Skip to content

Added All Sorting README.md files #82

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 17 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
5 changes: 3 additions & 2 deletions code/code/sorting/src/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# cosmos
Your personal library of every algorithm and data structure code that you will ever encounter.
# Cosmos



A large scale collaboration of [OpenGenus](https://github.com/opengenus)
18 changes: 16 additions & 2 deletions code/code/sorting/src/bucket_sort/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,18 @@
# cosmos
Your personal library of every algorithm and data structure code that you will ever encounter.
# Bucket Sort


Bucket sort, or bin sort, is a sorting algorithm that works by distributing the elements of an array into a number of buckets. Each bucket is then sorted individually, either using a different sorting algorithm, or by recursively applying the bucket sorting algorithm. It is a distribution sort, a generalization of pigeonhole sort, and is a cousin of radix sort in the most-to-least significant digit flavor. Bucket sort can be implemented with comparisons and therefore can also be considered a comparison sort algorithm. The computational complexity estimates involve the number of buckets.

Bucket sort works as follows:

- Set up an array of initially empty "buckets".
- Scatter: Go over the original array, putting each object in its bucket.
- Sort each non-empty bucket.
- Gather: Visit the buckets in order and put all elements back into the original array.


## Further Reading
[Wikipedia - Bucket sort](https://en.wikipedia.org/wiki/Bucket_sort)


A large scale collaboration of [OpenGenus](https://github.com/opengenus)
14 changes: 14 additions & 0 deletions code/code/sorting/src/circle_sort/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Circle Sort

Circle sort algorithm can be visualized by drawing concentric circles on an array of integers. The elements of the array lying on the same circle diametrically opposite to each other are compared and if found in the wrong order they are swapped. This goes on in a recursive fashion in which the array is divided into sub-arrays on which the above process is repeated until we get pairs of sorted elements which when put together form a sorted array.

In short below two steps are repeated while there are swap operations involved in the steps.

-Compare the first element to the last element, then the second element to the second last element, etc.
-Then split the array in two and recurse until there is only one single element in the array.

## Further Reading
[GFG Cirlce sort](https://www.geeksforgeeks.org/circle-sort/)


A large scale collaboration of [OpenGenus](https://github.com/opengenus)
31 changes: 29 additions & 2 deletions code/code/sorting/src/counting_sort/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,31 @@
# cosmos
Your personal library of every algorithm and data structure code that you will ever encounter.
# Counting Sort

Counting sort is a sorting technique based on keys between a specific range. It works by counting the number of objects having distinct key values (kind of hashing). Then doing some arithmetic to calculate the position of each object in the output sequence.


For simplicity, consider the data in the range 0 to 9.
Input data: 1, 4, 1, 2, 7, 5, 2
1) Take a count array to store the count of each unique object.
Index: 0 1 2 3 4 5 6 7 8 9
Count: 0 2 2 0 1 1 0 1 0 0

2) Modify the count array such that each element at each index
stores the sum of previous counts.
Index: 0 1 2 3 4 5 6 7 8 9
Count: 0 2 4 4 5 6 6 7 7 7

The modified count array indicates the position of each object in
the output sequence.

3) Output each object from the input sequence followed by
decreasing its count by 1.
Process the input data: 1, 4, 1, 2, 7, 5, 2. Position of 1 is 2.
Put data 1 at index 2 in output. Decrease count by 1 to place
next data 1 at an index 1 smaller than this index.


## Further Reading
[GFG - Counting sort](https://www.geeksforgeeks.org/counting-sort/)


A large scale collaboration of [OpenGenus](https://github.com/opengenus)
10 changes: 8 additions & 2 deletions code/code/sorting/src/cycle_sort/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
# cosmos
Your personal library of every algorithm and data structure code that you will ever encounter.
# Cycle Sort

Cycle sort is an in-place, unstable sorting algorithm, a comparison sort that is theoretically optimal in terms of the total number of writes to the original array, unlike any other in-place sorting algorithm. It is based on the idea that the permutation to be sorted can be factored into cycles, which can individually be rotated to give a sorted result.


## Further Reading
[Wikipedia - Cycle sort](https://en.wikipedia.org/wiki/Cycle_sort)


A large scale collaboration of [OpenGenus](https://github.com/opengenus)
4 changes: 4 additions & 0 deletions code/code/sorting/src/flash_sort/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,7 @@
Flash sort is a distribution sorting algorithm. It has a usual performance of O(n) for uniformly distributed data sets. It has relatively less memory requirement.

The basic idea behind flashsort is that in a data set with a known distribution, it is easy to immediately estimate where an element should be placed after sorting when the range of the set is known.



A large scale collaboration of [OpenGenus](https://github.com/opengenus)
11 changes: 11 additions & 0 deletions code/code/sorting/src/gnome_sort/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#Gnome Sort

Gnome sort (or Stupid sort) is a sorting algorithm originally proposed by an Iranian computer engineer Dr. Hamid Sarbazi-Azad (Professor of Computer Engineering at Sharif University of Technology) in 2000 and called "stupid sort"[1] (not to be confused with bogosort), and then later on described by Dick Grune and named "gnome sort".[2] It is a sorting algorithm which is similar to insertion sort, except that moving an element to its proper place is accomplished by a series of swaps, as in bubble sort. It is conceptually simple, requiring no nested loops. The average, or expected, running time is O(n2), but tends towards O(n) if the list is initially almost sorted.[3]

The algorithm always finds the first place where two adjacent elements are in the wrong order, and swaps them. It takes advantage of the fact that performing a swap can introduce a new out-of-order adjacent pair only next to the two swapped elements. It does not assume that elements forward of the current position are sorted, so it only needs to check the position directly previous to the swapped elements.

## Further Reading
[Wikipedia - Gnome sort](https://en.wikipedia.org/wiki/Gnome_sort)


A large scale collaboration of [OpenGenus](https://github.com/opengenus)
9 changes: 9 additions & 0 deletions code/code/sorting/src/insertion_sort/README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# Insertion Sort

**Overview:** Algorithm will construct a sorted array/list of elements one item at a time. With each iteration, the algorithm takes one element from the input data, identifies the ordered location in the new sorted array/list, then inserts the element. This is repeated until all the input data has been orderly inserted into the array/list.


**Time Complexity:** O(n*n)



## Further Reading
[Wikipedia - Insertion sort](https://en.wikipedia.org/wiki/Insertion_sort)


A large scale collaboration of [OpenGenus](https://github.com/opengenus)
11 changes: 11 additions & 0 deletions code/code/sorting/src/intro_sort/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# IntroSort


ntrosort or introspective sort is a hybrid sorting algorithm that provides both fast average performance and (asymptotically) optimal worst-case performance. It begins with quicksort and switches to heapsort when the recursion depth exceeds a level based on (the logarithm of) the number of elements being sorted. This combines the good parts of both algorithms, with practical performance comparable to quicksort on typical data sets and worst-case O(n log n) runtime due to the heap sort. Since both algorithms it uses are comparison sorts, it too is a comparison sort.


## Further Reading
[Wikipedia - IntroSort](https://en.wikipedia.org/wiki/Introsort)


A large scale collaboration of [OpenGenus](https://github.com/opengenus)
12 changes: 12 additions & 0 deletions code/code/sorting/src/median_sort/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Median Sort

The median sort is an odd variation of Quicksort I have never seen or heard of until reading the O’Reilly Algorithms in a Nutshell book. It takes the median value as the pivot. Half of the list will be less than the median. The other half will be greater. So the median is an optimal pivot in the sense of splitting into equally sized sub-problems.

Finding the median in an unsorted list takes linear time. It can be done with another variation on Quicksort which partially sorts the list. The median pivots may be optimal but incur extra cost. However, a problem may have statistical properties that allow estimating the median more cheaply than linear time.


## Further Reading
[Median sort](https://equilibriumofnothing.wordpress.com/2013/10/16/algorithm-median-sort/)


A large scale collaboration of [OpenGenus](https://github.com/opengenus)
6 changes: 1 addition & 5 deletions code/code/sorting/src/quick_sort/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,6 @@ Quicksort is a comparison sort algorithm. It has an average performance of O(n\*

- https://en.wikipedia.org/wiki/Quicksort

---

<p align="center">
A massive collaborative effort by <a href="https://github.com/OpenGenus/cosmos">OpenGenus Foundation</a>
</p>
A large scale collaboration of [OpenGenus](https://github.com/opengenus)

---
2 changes: 2 additions & 0 deletions code/code/sorting/src/radix_sort/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,5 @@ At least one LSD radix sort implementation now counts the number of times that e
# Further Reading

https://en.wikipedia.org/wiki/Radix_sort

A large scale collaboration of [OpenGenus](https://github.com/opengenus)
9 changes: 1 addition & 8 deletions code/code/sorting/src/shaker_sort/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,5 @@ procedure cocktailShakerSort( A : list of sortable items ) defined as:
end for
while swapped // if no elements have been swapped, then the list is sorted
end procedure
```

---

<p align="center">
A massive collaborative effort by <a href="https://github.com/OpenGenus/cosmos">OpenGenus Foundation</a>
</p>

---
A large scale collaboration of [OpenGenus](https://github.com/opengenus)
3 changes: 3 additions & 0 deletions code/code/sorting/src/sleep_sort/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,6 @@ The **sleep sort** algorithm is closely related to the operating system. Each in
* Won’t work with negative values since the OS can’t sleep for a negative amount of time
* Huge amounts of elements will cause the algorithm to be slow
* Elements with large values will cause a slow algorithm.


A large scale collaboration of [OpenGenus](https://github.com/opengenus)
2 changes: 2 additions & 0 deletions code/code/sorting/src/stooge_sort/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,5 @@ Inspired by the three stooges smashing each other in the head with a wooden plan

## Further reading
[Wikipedia - Stoogesort](https://en.wikipedia.org/wiki/Stooge_sort)

A large scale collaboration of [OpenGenus](https://github.com/opengenus)
9 changes: 9 additions & 0 deletions code/code/sorting/src/topological_sort/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Topological Sort

In the field of computer science, a topological sort or topological ordering of a directed graph is a linear ordering of its vertices such that for every directed edge uv from vertex u to vertex v, u comes before v in the ordering. For instance, the vertices of the graph may represent tasks to be performed, and the edges may represent constraints that one task must be performed before another; in this application, a topological ordering is just a valid sequence for the tasks. A topological ordering is possible if and only if the graph has no directed cycles, that is, if it is a directed acyclic graph (DAG). Any DAG has at least one topological ordering, and algorithms are known for constructing a topological ordering of any DAG in linear time.

## Further Reading
[Wikipedia - Topological sort](https://en.wikipedia.org/wiki/Topological_sorting)


A large scale collaboration of [OpenGenus](https://github.com/opengenus)
14 changes: 14 additions & 0 deletions code/code/sorting/src/tree_sort/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Tree Sort

A tree sort is a sort algorithm that builds a binary search tree from the elements to be sorted, and then traverses the tree (in-order) so that the elements come out in sorted order. Its typical use is sorting elements online: after each insertion, the set of elements seen so far is available in sorted order.

Adding one item to a binary search tree is on average an O(log n) process (in big O notation). Adding n items is an O(n log n) process, making tree sorting a 'fast sort' process. Adding an item to an unbalanced binary tree requires O(n) time in the worst-case: When the tree resembles a linked list (degenerate tree). This results in a worst case of O(n²) time for this sorting algorithm. This worst case occurs when the algorithm operates on an already sorted set, or one that is nearly sorted, reversed or nearly reversed. Expected O(n log n) time can however be achieved by shuffling the array, but this does not help for equal items.

The worst-case behaviour can be improved by using a self-balancing binary search tree. Using such a tree, the algorithm has an O(n log n) worst-case performance, thus being degree-optimal for a comparison sort. However, trees require memory to be allocated on the heap, which is a significant performance hit when compared to quicksort and heapsort. When using a splay tree as the binary search tree, the resulting algorithm (called splaysort) has the additional property that it is an adaptive sort, meaning that its running time is faster than O(n log n) for inputs that are nearly sorted.


## Further Reading
[Wikipedia - Tree sort](https://en.wikipedia.org/wiki/Tree_sort)


A large scale collaboration of [OpenGenus](https://github.com/opengenus)