Quicksort

Learn Algorithms · 3:29

Listen on 93

Lyrics

[Verse 1]
Started with an array, unsorted and wild
Tony Hoare had a vision, algorithmic styled
Pick a pivot element, that's your starting key
Partition left and right, divide and you'll see
Elements smaller go left of the line
Bigger ones to the right, that's the design
Recursive by nature, it calls itself back
Conquering chaos with mathematical track

[Chorus]
Quick-sort, quick-sort, divide and conquer strong
Pivot, partition, can't go wrong
Left side smaller, right side bigger
O of n log n, that's the figure
Quick-sort, quick-sort, in-place we go
Average case fast, worst case slow
Pick your pivot wisely, watch it flow

[Verse 2]
Lomuto scheme or Hoare partition style
Two pointer methods that make it worthwhile
Left pointer scanning for elements greater
Right pointer hunting for values that cater
When they cross paths, the partition's complete
Pivot finds home where the sections meet
Randomized pivot keeps worst case at bay
Median of three, that's another way

[Chorus]
Quick-sort, quick-sort, divide and conquer strong
Pivot, partition, can't go wrong
Left side smaller, right side bigger
O of n log n, that's the figure
Quick-sort, quick-sort, in-place we go
Average case fast, worst case slow
Pick your pivot wisely, watch it flow

[Bridge]
When the pivot's always smallest or largest each round
O of n squared complexity will bring you down
But randomization saves the day
Expected performance leads the way
Cache friendly, memory tight
Tail recursion optimization, that's right

[Verse 3]
Base case reached when subarray's small
One or zero elements, no need to call
Stack depth matters in recursion's game
Iterative versions achieve the same
Industry standard for sorting large data
Introsort hybrid when performance matters
From lomuto to three-way partitioning schemes
Quicksort's the foundation of algorithmic dreams

[Chorus]
Quick-sort, quick-sort, divide and conquer strong
Pivot, partition, can't go wrong
Left side smaller, right side bigger
O of n log n, that's the figure
Quick-sort, quick-sort, in-place we go
Average case fast, worst case slow
Pick your pivot wisely, watch it flow

[Outro]
Tony Hoare's legacy living on strong
Quicksort's efficiency can't go wrong
Divide and conquer, that's the way
Sorting arrays every single day

← Longest common subsequence | Quicksort Fundamentals: Divide and Conquer Strategy →