Skip to content

Commit e53f5f9

Browse files
mj-z-alitrekhleb
authored andcommitted
Added Complexity of Each Algorithm in Sorting/ directory. (trekhleb#76)
* Added Complexity to Bubble Sort README.md * Added Complexity to Counting-Sort README.md * Italicized n in Bubble Sort README.md * Added Complexity to Heap Sort README.md * Added Complexity to Insertion Sort README.md * Added Complexity to Merge Sort README.md * Added Complexity to Quick Sort README.md * Added Complexity to Radix Sort README.md * Added Complexity to Selection Sort README.md * Added Complexity to SHell Sort README.md
1 parent 831ce89 commit e53f5f9

File tree

9 files changed

+56
-0
lines changed

9 files changed

+56
-0
lines changed

src/algorithms/sorting/bubble-sort/README.md

+7
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,13 @@ are needed, which indicates that the list is sorted.
99

1010
![Algorithm Visualization](https://upload.wikimedia.org/wikipedia/commons/c/c8/Bubble-sort-example-300px.gif)
1111

12+
## Complexity
13+
14+
###### time: worst _O_(_n_<sup>2</sup>), best _O_(_n_), average _O_(_n_<sup>2</sup>)
15+
16+
###### space: worst _O_(1) auxiliary
17+
18+
1219
## References
1320

1421
- [Wikipedia](https://en.wikipedia.org/wiki/Bubble_sort)

src/algorithms/sorting/counting-sort/README.md

+6
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,12 @@ zero.
5454

5555
![Counting Sort](https://1.bp.blogspot.com/-xPqylngqASY/WLGq3p9n9vI/AAAAAAAAAHM/JHdtXAkJY8wYzDMBXxqarjmhpPhM0u8MACLcB/s1600/ResultArrayCS.gif)
5656

57+
## Complexity
58+
59+
###### time: worst _O_(_n_ + _k_), best _O_(_n_), average _O_(_n_ + _k_) where _n_ is the number of elements in the input array and _k_ is the range of the output.
60+
61+
###### space: worst _O_(_n_ + _k_)
62+
5763
## References
5864

5965
- [Wikipedia](https://en.wikipedia.org/wiki/Counting_sort)

src/algorithms/sorting/heap-sort/README.md

+6
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@ rather than a linear-time search to find the maximum.
1313

1414
![Algorithm Visualization](https://upload.wikimedia.org/wikipedia/commons/4/4d/Heapsort-example.gif)
1515

16+
## Complexity
17+
18+
###### time: worst _O_(_n log n_), best _O_(_n log n_), average _O_(_n log n_)
19+
20+
###### space: worst _O_(1) auxiliary
21+
1622
## References
1723

1824
[Wikipedia](https://en.wikipedia.org/wiki/Heapsort)

src/algorithms/sorting/insertion-sort/README.md

+7
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,13 @@ sort.
1010

1111
![Algorithm Visualization](https://upload.wikimedia.org/wikipedia/commons/0/0f/Insertion-sort-example-300px.gif)
1212

13+
## Complexity
14+
15+
###### time: worst _O_(_n_<sup>2</sup>), best _O_(_n_), average _O_(_n_<sup>2</sup>)
16+
17+
###### space: worst _O_(1) auxiliary
18+
19+
1320
## References
1421

1522
[Wikipedia](https://en.wikipedia.org/wiki/Insertion_sort)

src/algorithms/sorting/merge-sort/README.md

+6
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@ emulate merge sort (top-down).
2222

2323
![Merge Sort](https://upload.wikimedia.org/wikipedia/commons/e/e6/Merge_sort_algorithm_diagram.svg)
2424

25+
## Complexity
26+
27+
###### time: average _O_(_n log n_)
28+
29+
###### space: worst _O_(_n_)
30+
2531
## References
2632

2733
- [Wikipedia](https://en.wikipedia.org/wiki/Merge_sort)

src/algorithms/sorting/quick-sort/README.md

+6
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,12 @@ The horizontal lines are pivot values.
2323

2424
![Quicksort](https://upload.wikimedia.org/wikipedia/commons/6/6a/Sorting_quicksort_anim.gif)
2525

26+
## Complexity
27+
28+
###### time: worst _O_(_n_<sup>2</sup>), best _O_(_n log n_), average _O_(_n log n_)
29+
30+
###### space: worst _O_(_n_) auxiliary
31+
2632
## References
2733

2834
- [Wikipedia](https://en.wikipedia.org/wiki/Quicksort)

src/algorithms/sorting/radix-sort/README.md

+6
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,12 @@ comparison-based sorts (and worse if keys are much longer than `log n`).
2525

2626
![Radix Sort](https://www.researchgate.net/publication/291086231/figure/fig1/AS:614214452404240@1523451545568/Simplistic-illustration-of-the-steps-performed-in-a-radix-sort-In-this-example-the.png)
2727

28+
## Complexity
29+
30+
###### time: worst _O_(_n_), best _O_(_n_), average _O_(_n_)
31+
32+
###### space: always _O_(_n_)
33+
2834
## References
2935

3036
- [Wikipedia](https://en.wikipedia.org/wiki/Radix_sort)

src/algorithms/sorting/selection-sort/README.md

+6
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@ memory is limited.
1313

1414
![Algorithm Visualization](https://upload.wikimedia.org/wikipedia/commons/9/94/Selection-Sort-Animation.gif)
1515

16+
## Complexity
17+
18+
###### time: worst _O_(_n_<sup>2</sup>), best _O_(_n_<sup>2</sup>), average _O_(_n_<sup>2</sup>)
19+
20+
###### space: _O_(1) auxiliary
21+
1622
## References
1723

1824
[Wikipedia](https://en.wikipedia.org/wiki/Selection_sort)

src/algorithms/sorting/shell-sort/README.md

+6
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,12 @@ Shell sort uses insertion sort to sort the array.
4242

4343
![Shellsort](https://www.tutorialspoint.com/data_structures_algorithms/images/shell_sort.jpg)
4444

45+
## Complexity
46+
47+
###### time: best _O_(_n log n_), average - depends on 'gap sequence'.
48+
49+
###### space: worst _O_(_n_) total, _O_(1) auxiliary
50+
4551
## References
4652

4753
* [Tutorials Point](https://www.tutorialspoint.com/data_structures_algorithms/shell_sort_algorithm.htm)

0 commit comments

Comments
 (0)