mirror of
https://github.com/krahets/hello-algo.git
synced 2026-04-23 18:11:45 +08:00
Add "reference" for EN version. Bug fixes. (#1326)
This commit is contained in:
@@ -73,9 +73,7 @@ The implementation code of counting sort is shown below:
|
||||
|
||||
- **Time complexity is $O(n + m)$, non-adaptive sort**: Involves traversing `nums` and `counter`, both using linear time. Generally, $n \gg m$, and the time complexity tends towards $O(n)$.
|
||||
- **Space complexity is $O(n + m)$, non-in-place sort**: Utilizes arrays `res` and `counter` of lengths $n$ and $m$ respectively.
|
||||
- **Stable sort**: Since elements are filled into `res` in a "right-to-left" order, reversing the traversal of $nums$ can prevent changing the relative position between equal elements, thereby achieving a stable sort. Actually, traversing `nums$ in
|
||||
|
||||
order can also produce the correct sorting result, but the outcome is unstable.
|
||||
- **Stable sort**: Since elements are filled into `res` in a "right-to-left" order, reversing the traversal of `nums` can prevent changing the relative position between equal elements, thereby achieving a stable sort. Actually, traversing `nums` in order can also produce the correct sorting result, but the outcome is unstable.
|
||||
|
||||
## Limitations
|
||||
|
||||
|
||||
@@ -60,7 +60,7 @@ The implementation of merge sort is shown in the following code. Note that the i
|
||||
## Algorithm characteristics
|
||||
|
||||
- **Time complexity of $O(n \log n)$, non-adaptive sort**: The division creates a recursion tree of height $\log n$, with each layer merging a total of $n$ operations, resulting in an overall time complexity of $O(n \log n)$.
|
||||
- **Space complexity of $O(n)$, non-in-place sort**: The recursion depth is $\log n`, using $O(\log n)` stack frame space. The merging operation requires auxiliary arrays, using an additional space of $O(n)$.
|
||||
- **Space complexity of $O(n)$, non-in-place sort**: The recursion depth is $\log n$, using $O(\log n)$ stack frame space. The merging operation requires auxiliary arrays, using an additional space of $O(n)$.
|
||||
- **Stable sort**: During the merging process, the order of equal elements remains unchanged.
|
||||
|
||||
## Linked List sorting
|
||||
|
||||
Reference in New Issue
Block a user