Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
98 changes: 70 additions & 28 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,36 @@
# The Algorithms - Dart

[![Build Status](https://travis-ci.com/TheAlgorithms/Dart.svg?branch=master)](https://travis-ci.com/TheAlgorithms/Dart)
[![Donate](https://img.shields.io/badge/Donate-PayPal-green.svg)](https://www.paypal.me/TheAlgorithms/100)  
[![Discord chat](https://img.shields.io/discord/808045925556682782.svg?logo=discord&colorB=5865F2)](https://the-algorithms.com/discord/)  
[![Gitter chat](https://badges.gitter.im/gitterHQ/gitter.png)](https://gitter.im/#TheAlgorithms_community:gitter.im)
[![Build Status](#)](#)
[![Dart](https://img.shields.io/badge/Dart-2.19-blue.svg)](https://dart.dev/)
[![MIT License](https://img.shields.io/badge/license-MIT-green.svg)](LICENSE)
[![GitHub stars](https://img.shields.io/github/stars/TheAlgorithms/Dart?style=social)](#)
[![Join us on Gitter](https://badges.gitter.im/TheAlgorithms/community.svg)](https://gitter.im/TheAlgorithms/community)

### All algorithms implemented in Dart (for education)
> All algorithms implemented in Dart, for learning purposes.

These implementations are for learning purposes. They may be less efficient than the implementations in the Dart standard library.
This repository contains **clean and well-documented implementations** of many fundamental algorithms in the Dart programming language. These are designed to help learners understand algorithmic concepts in a simple, readable format.

> ⚠️ Note: These implementations may not be optimized for production. They are created for **educational use**.

---

## Table of Contents

- [Search Algorithms](#search-algorithms)
- [Linear Search](#-linear-search)
- [Binary Search](#-binary-search)
- [Sorting Algorithms](#sorting-algorithms)
- [Bubble Sort](#-bubble-sort)
- [Insertion Sort](#-insertion-sort)
- [Quick Sort](#-quick-sort)
- [Selection Sort](#-selection-sort)
- [Merge Sort](#-merge-sort)
- [Shell Sort](#-shell-sort)
- [Time Complexity Comparisons](#time-complexity-comparisons)
- [Contributing](#contributing)
- [License](#license)

---

## List of Algorithms

Expand All @@ -16,9 +39,10 @@ See our [directory](https://github.com/TheAlgorithms/Dart/blob/master/DIRECTORY.
## Search Algorithms

### Linear
![alt text][linear-image]
![alt text][linear-image]
From [Wikipedia][linear-wiki]:

From [Wikipedia][linear-wiki]: linear search or sequential search is a method for finding a target value within a list. It sequentially checks each element of the list for the target value until a match is found or until all the elements have been searched.
>Linear search or sequential search is a method for finding a target value within a list. It sequentially checks each element of the list for the target value until a match is found or until all the elements have been searched.
Linear search runs in at the worst linear time and makes at most n comparisons, where n is the length of the list.

__Properties__
Expand All @@ -29,25 +53,25 @@ __Properties__


### Binary
![alt text][binary-image]
![alt text][binary-image]</br>
From [Wikipedia][binary-wiki]:

From [Wikipedia][binary-wiki]: Binary search, also known as half-interval search or logarithmic search, is a search algorithm that finds the position of a target value within a sorted array. It compares the target value to the middle element of the array; if they are unequal, the half in which the target cannot lie is eliminated and the search continues on the remaining half until it is successful.
>Binary search, also known as half-interval search or logarithmic search, is a search algorithm that finds the position of a target value within a sorted array. It compares the target value to the middle element of the array; if they are unequal, the half in which the target cannot lie is eliminated and the search continues on the remaining half until it is successful.

__Properties__
* Worst case performance O(log n)
* Best case performance O(1)
* Average case performance O(log n)
* Worst case space complexity O(1)

----------------------------------------------------------------------------------------------------------------------

*
---
## Sort Algorithms


### Bubble
![alt text][bubble-image]
![alt text][bubble-image]</br>
From [Wikipedia][bubble-wiki]:

From [Wikipedia][bubble-wiki]: Bubble sort, sometimes referred to as sinking sort, is a simple sorting algorithm that repeatedly steps through the list to be sorted, compares each pair of adjacent items and swaps them if they are in the wrong order. The pass through the list is repeated until no swaps are needed, which indicates that the list is sorted.
>Bubble sort, sometimes referred to as sinking sort, is a simple sorting algorithm that repeatedly steps through the list to be sorted, compares each pair of adjacent items and swaps them if they are in the wrong order. The pass through the list is repeated until no swaps are needed, which indicates that the list is sorted.

__Properties__
* Worst case performance O(n^2)
Expand All @@ -56,12 +80,11 @@ __Properties__

###### View the algorithm in [action][bubble-toptal]



### Insertion
![alt text][insertion-image]
![alt text][insertion-image]</br>
From [Wikipedia][insertion-wiki]:

From [Wikipedia][insertion-wiki]: Insertion sort is a simple sorting algorithm that builds the final sorted array (or list) one item at a time. It is much less efficient on large lists than more advanced algorithms such as quicksort, heapsort, or merge sort.
>Insertion sort is a simple sorting algorithm that builds the final sorted array (or list) one item at a time. It is much less efficient on large lists than more advanced algorithms such as quicksort, heapsort, or merge sort.

__Properties__
* Worst case performance O(n^2)
Expand All @@ -72,9 +95,10 @@ __Properties__


### Quick
![alt text][quick-image]
![alt text][quick-image]</br>
From [Wikipedia][quick-wiki]:

From [Wikipedia][quick-wiki]: Quicksort (sometimes called partition-exchange sort) is an efficient sorting algorithm, serving as a systematic method for placing the elements of an array in order.
>Quicksort (sometimes called partition-exchange sort) is an efficient sorting algorithm, serving as a systematic method for placing the elements of an array in order.

__Properties__
* Worst case performance O(n^2)
Expand All @@ -84,9 +108,10 @@ __Properties__
###### View the algorithm in [action][quick-toptal]

### Selection
![alt text][selection-image]
![alt text][selection-image]</br>
From [Wikipedia][selection-wiki]:

From [Wikipedia][selection-wiki]: The algorithm divides the input list into two parts: the sublist of items already sorted, which is built up from left to right at the front (left) of the list, and the sublist of items remaining to be sorted that occupy the rest of the list. Initially, the sorted sublist is empty and the unsorted sublist is the entire input list. The algorithm proceeds by finding the smallest (or largest, depending on sorting order) element in the unsorted sublist, exchanging (swapping) it with the leftmost unsorted element (putting it in sorted order), and moving the sublist boundaries one element to the right.
>The algorithm divides the input list into two parts: the sublist of items already sorted, which is built up from left to right at the front (left) of the list, and the sublist of items remaining to be sorted that occupy the rest of the list. Initially, the sorted sublist is empty and the unsorted sublist is the entire input list. The algorithm proceeds by finding the smallest (or largest, depending on sorting order) element in the unsorted sublist, exchanging (swapping) it with the leftmost unsorted element (putting it in sorted order), and moving the sublist boundaries one element to the right.

__Properties__
* Worst case performance O(n^2)
Expand All @@ -97,9 +122,10 @@ __Properties__


### Merge
![alt text][merge-image]
![alt text][merge-image]</br>
From [Wikipedia][merge-wiki]:

From [Wikipedia][merge-wiki]: Merge sort (also commonly spelled mergesort) is a divide and conquer algorithm that was invented by John von Neumann in 1945. The algorithm dirst divides the list into the smallest unit (1 element), then compares each element with the adjacent list to sort and merge the two adjacent lists. Finally all the elements are sorted and merged. It is an efficient, general-purpose, comparison-based sorting algorithm.
>erge sort (also commonly spelled mergesort) is a divide and conquer algorithm that was invented by John von Neumann in 1945. The algorithm dirst divides the list into the smallest unit (1 element), then compares each element with the adjacent list to sort and merge the two adjacent lists. Finally all the elements are sorted and merged. It is an efficient, general-purpose, comparison-based sorting algorithm.

__Properties__
* Worst case performance O(n log n)
Expand All @@ -110,9 +136,10 @@ __Properties__


### Shell
![alt text][shell-image]
![alt text][shell-image]</br>
From [Wikipedia][shell-wiki]:

From [Wikipedia][shell-wiki]: Shellsort is a generalization of insertion sort that allows the exchange of items that are far apart. The idea is to arrange the list of elements so that, starting anywhere, considering every nth element gives a sorted list. Such a list is said to be h-sorted. Equivalently, it can be thought of as h interleaved lists, each individually sorted.
>Shellsort is a generalization of insertion sort that allows the exchange of items that are far apart. The idea is to arrange the list of elements so that, starting anywhere, considering every nth element gives a sorted list. Such a list is said to be h-sorted. Equivalently, it can be thought of as h interleaved lists, each individually sorted.

__Properties__
* Worst case performance O(nlog2 2n)
Expand Down Expand Up @@ -157,6 +184,15 @@ Comparing the complexity of sorting algorithms (Bubble Sort, Insertion Sort, Sel
[binary-wiki]: https://en.wikipedia.org/wiki/Binary_search_algorithm
[binary-image]: https://upload.wikimedia.org/wikipedia/commons/f/f7/Binary_search_into_array.png

| Algorithm | Best Case | Average Case | Worst Case |
|----------------|-----------|--------------|-------------|
| Bubble Sort | O(n) | O(n²) | O(n²) |
| Insertion Sort | O(n) | O(n²) | O(n²) |
| Selection Sort | O(n²) | O(n²) | O(n²) |
| Merge Sort | O(n log n) | O(n log n) | O(n log n) |
| Quick Sort | O(n log n) | O(n log n) | O(n²) |
| Shell Sort | O(n log n) | Varies | O(n log² n) |

----------------------------------------------------------------------------------

## Community Channel
Expand All @@ -170,3 +206,9 @@ Please read our [CONTRIBUTING.md](https://github.com/TheAlgorithms/Dart/blob/mas
## License

[MIT](https://github.com/TheAlgorithms/Dart/blob/master/LICENSE)

## Resources

- [Dart Language Docs](https://dart.dev/guides)
- [Big-O Cheat Sheet](https://www.bigocheatsheet.com/)
- [Sorting Algorithm Visualizations](https://visualgo.net/en/sorting)