mirror of
https://github.com/trekhleb/javascript-algorithms.git
synced 2025-07-07 18:10:24 +08:00
Update READMEs.
This commit is contained in:
@ -11,16 +11,9 @@ are needed, which indicates that the list is sorted.
|
||||
|
||||
## Complexity
|
||||
|
||||
Time
|
||||
|
||||
- worst _O_(_n_<sup>2</sup>),
|
||||
- best _O_(_n_),
|
||||
- average _O_(_n_<sup>2</sup>)
|
||||
|
||||
Space
|
||||
|
||||
worst _O_(1) auxiliary
|
||||
|
||||
| Name | Best | Average | Worst | Memory | Stable | Comments |
|
||||
| --------------------- | :-------------: | :-----------------: | :-----------------: | :-------: | :-------: | :-------- |
|
||||
| **Bubble sort** | n | n<sup>2</sup> | n<sup>2</sup> | 1 | Yes | |
|
||||
|
||||
## References
|
||||
|
||||
|
@ -56,9 +56,9 @@ zero.
|
||||
|
||||
## Complexity
|
||||
|
||||
###### 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.
|
||||
|
||||
###### space: worst _O_(_n_ + _k_)
|
||||
| Name | Best | Average | Worst | Memory | Stable | Comments |
|
||||
| --------------------- | :-------------: | :-----------------: | :-----------------: | :-------: | :-------: | :-------- |
|
||||
| **Counting sort** | n + r | n + r | n + r | n + r | Yes | r - biggest number in array |
|
||||
|
||||
## References
|
||||
|
||||
|
@ -15,9 +15,9 @@ rather than a linear-time search to find the maximum.
|
||||
|
||||
## Complexity
|
||||
|
||||
###### time: worst _O_(_n log n_), best _O_(_n log n_), average _O_(_n log n_)
|
||||
|
||||
###### space: worst _O_(1) auxiliary
|
||||
| Name | Best | Average | Worst | Memory | Stable | Comments |
|
||||
| --------------------- | :-------------: | :-----------------: | :-----------------: | :-------: | :-------: | :-------- |
|
||||
| **Heap sort** | n log(n) | n log(n) | n log(n) | 1 | No | |
|
||||
|
||||
## References
|
||||
|
||||
|
@ -12,10 +12,9 @@ sort.
|
||||
|
||||
## Complexity
|
||||
|
||||
###### time: worst _O_(_n_<sup>2</sup>), best _O_(_n_), average _O_(_n_<sup>2</sup>)
|
||||
|
||||
###### space: worst _O_(1) auxiliary
|
||||
|
||||
| Name | Best | Average | Worst | Memory | Stable | Comments |
|
||||
| --------------------- | :-------------: | :-----------------: | :-----------------: | :-------: | :-------: | :-------- |
|
||||
| **Insertion sort** | n | n<sup>2</sup> | n<sup>2</sup> | 1 | Yes | |
|
||||
|
||||
## References
|
||||
|
||||
|
@ -24,9 +24,9 @@ emulate merge sort (top-down).
|
||||
|
||||
## Complexity
|
||||
|
||||
###### time: average _O_(_n log n_)
|
||||
|
||||
###### space: worst _O_(_n_)
|
||||
| Name | Best | Average | Worst | Memory | Stable | Comments |
|
||||
| --------------------- | :-------------: | :-----------------: | :-----------------: | :-------: | :-------: | :-------- |
|
||||
| **Merge sort** | n log(n) | n log(n) | n log(n) | n | Yes | |
|
||||
|
||||
## References
|
||||
|
||||
|
@ -25,9 +25,9 @@ The horizontal lines are pivot values.
|
||||
|
||||
## Complexity
|
||||
|
||||
###### time: worst _O_(_n_<sup>2</sup>), best _O_(_n log n_), average _O_(_n log n_)
|
||||
|
||||
###### space: worst _O_(_n_) auxiliary
|
||||
| Name | Best | Average | Worst | Memory | Stable | Comments |
|
||||
| --------------------- | :-------------: | :-----------------: | :-----------------: | :-------: | :-------: | :-------- |
|
||||
| **Quick sort** | n log(n) | n log(n) | n<sup>2</sup> | log(n) | No | |
|
||||
|
||||
## References
|
||||
|
||||
|
@ -27,9 +27,9 @@ comparison-based sorts (and worse if keys are much longer than `log n`).
|
||||
|
||||
## Complexity
|
||||
|
||||
###### time: worst _O_(_n_), best _O_(_n_), average _O_(_n_)
|
||||
|
||||
###### space: always _O_(_n_)
|
||||
| Name | Best | Average | Worst | Memory | Stable | Comments |
|
||||
| --------------------- | :-------------: | :-----------------: | :-----------------: | :-------: | :-------: | :-------- |
|
||||
| **Radix sort** | n * k | n * k | n * k | n + k | Yes | k - length of longest key |
|
||||
|
||||
## References
|
||||
|
||||
|
@ -15,9 +15,9 @@ memory is limited.
|
||||
|
||||
## Complexity
|
||||
|
||||
###### time: worst _O_(_n_<sup>2</sup>), best _O_(_n_<sup>2</sup>), average _O_(_n_<sup>2</sup>)
|
||||
|
||||
###### space: _O_(1) auxiliary
|
||||
| Name | Best | Average | Worst | Memory | Stable | Comments |
|
||||
| --------------------- | :-------------: | :-----------------: | :-----------------: | :-------: | :-------: | :-------- |
|
||||
| **Selection sort** | n<sup>2</sup> | n<sup>2</sup> | n<sup>2</sup> | 1 | No | |
|
||||
|
||||
## References
|
||||
|
||||
|
@ -44,9 +44,9 @@ Shell sort uses insertion sort to sort the array.
|
||||
|
||||
## Complexity
|
||||
|
||||
###### time: best _O_(_n log n_), average - depends on 'gap sequence'.
|
||||
|
||||
###### space: worst _O_(_n_) total, _O_(1) auxiliary
|
||||
| Name | Best | Average | Worst | Memory | Stable | Comments |
|
||||
| --------------------- | :-------------: | :-----------------: | :-----------------: | :-------: | :-------: | :-------- |
|
||||
| **Shell sort** | n log(n) | depends on gap sequence | n (log(n))<sup>2</sup> | 1 | No | |
|
||||
|
||||
## References
|
||||
|
||||
|
Reference in New Issue
Block a user