Skip to content

Commit 5e7127f

Browse files
committed
docs: improve phrasing for some sorts
1 parent b00cf3a commit 5e7127f

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

src/main/java/algorithms/sorting/cyclicSort/README.md

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ Though under some conditions (discussed later), the best case could be done in O
77

88
### Implementation Invariant
99

10-
**At the end of the ith iteration, the ith element
11-
(of the original array, from either the back or front depending on implementation), is correctly positioned**.
10+
**At the end of the kth iteration, the smallest (largest) i items are correctly sorted
11+
in the first (last) i positions of the array**.
1212

1313
### Comparison to Selection Sort
1414

15-
Its invariant is quite similar as selection sort's. But they differ slightly in maintaining this invariant.
15+
Its invariant is quite similar as selection sort's. But they differ in maintaining this invariant.
1616
The algorithm for cyclic sort does a bit more than selection sort's.
1717
In the process of trying to find the correct element for the ith position, any element that was
1818
encountered will be correctly placed in their positions as well.
@@ -29,4 +29,11 @@ We discuss more implementation-specific details and complexity analysis in the r
2929
2. The [**generalised**](./generalised) case discusses cyclic sort for general inputs. This is comparison-based and is
3030
usually implemented in O(n^2).
3131

32+
Note that, in practice, the generalised case is hardly used. There are more efficient algorithms to use for sorting,
33+
e.g. merge and quick sort. If the concern is the number of swaps, generalized cyclic sort does indeed require fewer
34+
swaps, but likely won't lower than selection sort's.
35+
36+
In other words, cyclic sort is specially designed for situations where the elements to be sorted are
37+
known to fall within a specific, continuous range, such as integers from 1 to n, without any gaps or duplicates.
38+
3239

src/main/java/algorithms/sorting/selectionSort/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,6 @@ time complexity of selectionSort is n + (n-1) + (n-2) + ... + 2 = O(n^2)
3434
**Space**: O(1) since sorting is done in-place
3535

3636
Image Source: https://www.hackerearth.com/practice/algorithms/sorting/selection-sort/tutorial/
37+
38+
## Notes
39+
The number of swaps made is always O(n) (careful not to confuse this with the number of comparisons).

0 commit comments

Comments
 (0)