@abreen/tada 1.15.7 → 1.15.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -25,12 +25,10 @@ Selection sort is a well-known comparison-based sorting algorithm.
|
|
|
25
25
|
|
|
26
26
|
Selection sort's strength is its simplicity.
|
|
27
27
|
|
|
28
|
+
- The helper method, `index_smallest()` is easy to understand
|
|
28
29
|
- `index_smallest()` always scans from `start` to the end
|
|
29
30
|
- It requires no additional memory (other than local variables)
|
|
30
31
|
|
|
31
|
-
However, it has no `break` statements and therefore can't return early if
|
|
32
|
-
the array is already sorted.
|
|
33
|
-
|
|
34
32
|
---
|
|
35
33
|
|
|
36
34
|
## Performance
|
|
@@ -51,12 +49,16 @@ The innermost statement compares `nums[i]` and `nums[curr]`.
|
|
|
51
49
|
- when `i` is $n - 3$, the comparison is executed two times
|
|
52
50
|
- when `i` is $n - 2$, the comparison is executed one time
|
|
53
51
|
|
|
54
|
-
Therefore the total number of comparisons is
|
|
52
|
+
Therefore the total number of comparisons $C(n)$ is
|
|
55
53
|
|
|
56
54
|
$$
|
|
57
|
-
(n-1) + (n-2) + \dots + 1 = \sum_{i=1}^{n-1}i
|
|
55
|
+
(n-1) + (n-2) + \dots + 1 = \sum_{i=1}^{n-1}i = \frac{n(n-1)}{2}
|
|
58
56
|
$$
|
|
59
57
|
|
|
58
|
+
??? question What complexity class does $C(n)$ belong to?
|
|
59
|
+
It's a quadratic function. The class is $O(n^2)$.
|
|
60
|
+
???
|
|
61
|
+
|
|
60
62
|
---
|
|
61
63
|
|
|
62
64
|
## Review
|
package/package.json
CHANGED