Skip to content

Commit f34ccf2

Browse files
authored
English Edit
1 parent 717ba94 commit f34ccf2

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

Introsort/README.markdown

+4-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ IntroSort is the algorithm used by swift to sort a collection. Introsort is an h
66

77
The number 20 is an empiric number obtained observing the behaviour of InsertionSort with lists of this size.
88

9-
Here's an implementation in Pseudocode:
9+
Here's an implementation in pseudocode:
1010

1111
```
1212
procedure sort(A : array):
@@ -32,9 +32,9 @@ Let's walk through the example. The array is initially:
3232
[ 10, 0, 3, 9, 2, 14, 8, 27, 1, 5, 8, -1, 26 ]
3333

3434

35-
for this example let's assume that `maxDepth` is **2** and that the size of the partition for the insertionSort to kick in is **5**
35+
For this example let's assume that `maxDepth` is **2** and that the size of the partition for the insertionSort to kick in is **5**
3636

37-
At the first iteration we run introSort on the full collection that counts 13 elements. the maxDepth is 2, therefore we fall in the else case where quicksort acts.
37+
The first iteration of introsort begins by attempting to use insertionSort. The collection has 13 elements, so it tries to do heapsort instead. The condition for heapsort to occur is if `maxdepth == 0` evaluates true. Since `maxdepth` is currently **2** for the first iteration, introsort will default to quicksort.
3838

3939
The `partition` method picks the first element, the median and the last, it sorts them and uses the new median as pivot.
4040

@@ -106,5 +106,6 @@ The array is now successfully sorted
106106

107107
[Introsort on Wikipedia](https://en.wikipedia.org/wiki/Introsort)
108108
[Introsort comparison with other sorting algorithms](http://agostini.tech/2017/12/18/swift-sorting-algorithm/)
109+
[Introsort implementation from the Swift standard library](https://github.com/apple/swift/blob/09f77ff58d250f5d62855ea359fc304f40b531df/stdlib/public/core/Sort.swift.gyb)
109110

110111
*Written for Swift Algorithm Club by Giuseppe Lanza*

0 commit comments

Comments
 (0)