Kth Largest Element - QuickSelect

QuickSelect is a selection algorithm based on QuickSort's partition. Instead of sorting both halves, you only recurse into the half containing the kkth element.

1.1. Pick a pivot and partition the array.

2.2. If the pivot lands at position k1k-1, you found the answer.

3.3. If pivot position >k1> k-1, recurse left.

4.4. If pivot position <k1< k-1, recurse right.

Average case is O(n)O(n) because you halve the problem each time: n+n/2+n/4+...=2nn + n/2 + n/4 + ... = 2n.