Quickselect

Seven runners finish a race. Which time takes fourth place? Equal times each occupy a place.

Compare each number with the pivot. Smaller numbers go left, equal ones in the middle and larger ones right. A question mark covers unchecked cells.

Find the group containing the requested position. Continue searching inside that group.

Random input order takes O(n) comparisons on average, O(n²) in the worst case. Swaps use the original array.