Sorting, Selection & Divide-and-Conquer
- Quicksort = partition + recurse
- Quickselect = partition + one side
- Merge sort = split + merge
- Combine step is where counting happens
1 / 5
Partition
- Choose pivot (random is safest)
- < pivot on left, > pivot on right
- Pivot ends in its final index
2 / 5
Quickselect
- If pivot index == k-1, done
- Else recurse only into the side that contains k
- Average O(n)
3 / 5
Merge + Inversions
- When left[i] > right[j], add (len(left)-i)
- Works for many pair-counting tasks
4 / 5
Divide-and-conquer pattern
- Base case
- Split
- Recurse
- Combine (the real work)
5 / 5
Use arrow keys or click edges to navigate. Press H to toggle help, F for fullscreen.