@@ -7,12 +7,12 @@ Though under some conditions (discussed later), the best case could be done in O
7
7
8
8
### Implementation Invariant
9
9
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 ** .
12
12
13
13
### Comparison to Selection Sort
14
14
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.
16
16
The algorithm for cyclic sort does a bit more than selection sort's.
17
17
In the process of trying to find the correct element for the ith position, any element that was
18
18
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
29
29
2 . The [ ** generalised** ] ( ./generalised ) case discusses cyclic sort for general inputs. This is comparison-based and is
30
30
usually implemented in O(n^2).
31
31
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
+
32
39
0 commit comments