

0 / 2 embers
0 / 3000 xp
click for more info
Complete a lesson to start your streak
click for more info
Difficulty: 5
click for more info
Not enough gems
Cost: 6 gems
1: Sorting Algorithms
incomplete
2: Bubble Sort
incomplete
3: Bubble Sort Big O
incomplete
4: Why Bubble Sort?
incomplete
5: Merge Sort
incomplete
6: Merge Sort Big O
incomplete
7: Why Merge Sort?
incomplete
8: Insertion Sort
incomplete
9: Insertion Sort Big O
incomplete
10: Why Use Insertion Sort?
incomplete
11: Quicksort
incomplete
12: Quicksort Big O
incomplete
13: Fixing Quicksort
incomplete
14: Why Use Quicksort?
incomplete
15: Selection Sort
incomplete
Back
ctrl+,
Next
ctrl+.
This lesson's interactive features are locked, please to keep using them
Quicksort is an efficient sorting algorithm that's widely used in production sorting implementations. Like merge sort, quicksort is a recursive divide and conquer algorithm.
Divide:
Select a pivot element that will preferably end up close to the center of the sorted pack
Move everything onto the "greater than" or "less than" side of the pivot
The pivot is now in its final position
Recursively repeat the operation on both sides of the pivot
Conquer:
The array is sorted after all elements have been through the pivot operation
Select a "pivot" element - We'll arbitrarily choose the last element in the list
Move through all the elements in the list and swap them around until all the numbers less than the pivot are on the left, and the numbers greater than the pivot are on the right
Move the pivot between the two sections where it belongs
Recursively repeat for both sections
i marks the end of the section smaller than the pivot. It starts at low - 1 because that section is empty. After scanning, i + 1 is where the pivot belongs.
We now have two sorting algorithms on our LockedIn backend! It is a bit annoying to maintain both in the codebase. Quicksort is fast on large datasets just like merge sort, but is also lighter on memory usage. Let's use quicksort for both follower count and influencer revenue sorting!
Complete the quick_sort and partition functions according to the given algorithms.
The process is started with quick_sort(A, 0, len(A)-1).