You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/algorithms/explanations/QSExp.md
+23-3Lines changed: 23 additions & 3 deletions
Original file line number
Diff line number
Diff line change
@@ -5,7 +5,10 @@
5
5
Quicksort is a divide and conquer algorithm. It first rearranges the input
6
6
array into two smaller sub-arrays: the (relatively) low elements and the
7
7
(relatively) high elements. It then recursively sorts each of the sub-arrays.
8
-
The steps for Quicksort are:
8
+
9
+
### Sorting using Basic Quicksort
10
+
11
+
The steps for basic Quicksort, used in this animation are:
9
12
10
13
* Pick the rightmost element of the array, called a pivot.
11
14
@@ -15,12 +18,29 @@ The steps for Quicksort are:
15
18
16
19
The base case of the recursion is arrays of size one or zero, which are in order by definition, so they never need to be sorted.
17
20
21
+
22
+
### Complexity
23
+
24
+
Time complexity:
25
+
<code>
26
+
Average case <i>O(nlogn)</i>
27
+
Worst case <i>O(n<sup>2</sup>)</i>
28
+
Best case <i>O(nlogn)</i>
29
+
30
+
Note: Worst case in simple quicksort occurs when a file is already sorted, since the partition is highly asymmetrical. Improvements such as median-of-three quicksort make a significant improvement, although worst case behaviour is still possible.
31
+
</code>
32
+
33
+
Space complexity is O(1), that is, no extra space is required.
34
+
35
+
36
+
37
+
### Development of Quicksort
38
+
18
39
The first version of quicksort was published by Tony Hoare in 1961 and
19
40
quicksort remains the *fastest* sorting algorithm on average (subject to
20
41
various caveats). The pivot selection and partitioning steps can be
21
42
done in *many* different ways and the choice of specific implementation
22
43
details and computer hardware can significantly affect the algorithm's
23
44
performance. In 1975, Robert Sedgewick completed a Ph.D. thesis on this
24
45
single algorithm. Our presentation here is influenced by the original
25
-
Hoare version and some of Sedgewick's adaptations.
26
-
46
+
Hoare version and some of Sedgewick's adaptations.
0 commit comments