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.
More from Fun
- Vibecoded Stitches: a synth with built-in visuals and punch-in effects, built with Opus 5.5 — ssh4net · 2026-11-07
- Weekend Project: Halftone QR Codes That Still Scan Reliably — vincent_koc · 2026-11-07
- Two RSI jokes: GPT as an ICLR reviewer who only gives 1s and 2s — ShenRaphael · 2026-11-07
- Robot party in San Francisco features a bot actually giving a human a tattoo — Scobleizer · 2026-11-07
- OpenAI employees gaming while coding may finally fix Codex Mac memory issues — airkatakana · 2026-11-07
- AI-generated 'My Morning Routine' grotesque meme takes over Reddit — Old-Bake-420 · 2026-11-07