Finding the max of 1M items takes 999,999 comparisons; second max just 19 more

abhishekcode42 · x · 2026-11-07

A classic algorithm trivia: finding the maximum of 1,000,000 elements takes 999,999 comparisons, but the second-largest takes only 19 more (log₂(1,000,000) ≈ 20). The post hints at it via tennis grand slam seeding brackets — this is the tournament method: the maximum "wins" a knockout tournament, and the second-largest must have lost only to the maximum, so you just find the max among those 20 losers.

Original post →

More from Fun

Fun channel →