Skip to content

Commit 3301037

Browse files
committed
QS simple Background
Added complexity.
1 parent e94e335 commit 3301037

File tree

1 file changed

+23
-3
lines changed

1 file changed

+23
-3
lines changed

src/algorithms/explanations/QSExp.md

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@
55
Quicksort is a divide and conquer algorithm. It first rearranges the input
66
array into two smaller sub-arrays: the (relatively) low elements and the
77
(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:
912

1013
* Pick the rightmost element of the array, called a pivot.
1114

@@ -15,12 +18,29 @@ The steps for Quicksort are:
1518

1619
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.
1720

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+
1839
The first version of quicksort was published by Tony Hoare in 1961 and
1940
quicksort remains the *fastest* sorting algorithm on average (subject to
2041
various caveats). The pivot selection and partitioning steps can be
2142
done in *many* different ways and the choice of specific implementation
2243
details and computer hardware can significantly affect the algorithm's
2344
performance. In 1975, Robert Sedgewick completed a Ph.D. thesis on this
2445
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

Comments
 (0)