-
Notifications
You must be signed in to change notification settings - Fork 441
/
Copy pathquick.js
23 lines (14 loc) · 953 Bytes
/
quick.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
/*
QUICK SORT
*** Description
Like merge sort, quick sort employs a divide and conquer strategy.
It has a partitioning step, in which you pick an element (called a pivot) and partition the array so that all smaller elements come before pivot and all larger elements come after. The pivot will be in its final position. Recursively apply this to the subarray of smaller elements and the subarray of larger elements.
*** Exercises
- Write a partition helper function. For choice of pivot, for a basic implementation, we recommend choosing either the first or last element in the subarray. If you need hints, look up the Lumoto partiton scheme. Test this out before moving forward!
- Implement quicksort
- Identify time complexity
- Consider implications for choice of pivot (https://en.wikipedia.org/wiki/Quicksort#Choice_of_pivot)
*** Extra Credit
Variants:
- Implement a multi-pivot quicksort (ex: partition into 3 subarrays using 2 pivots)
*/