Bifalgorithm post

Find one number in a sorted list of a billion in about 30 steps. That is binary search. The trick is that the array is sorted. So start by looking at the middle element. Target too big, throw away the left half. Too small, throw away the right. Either way, half the array is gone. Look at the new middle and have again and again. Closing in every step. A billion items collapses to just 30 checks because each step doubles your reach. That is log N. Halve. Compare, repeat. That is binary search.

Find one number in a sorted list of a billion in about 30 steps. That is binary search. The trick is that the array is sorted. So start by looking at the middl…

Ideas in this flowchart

  • Binary Search
  • Initial Setup
  • Sorted List
  • Search Process
  • Start at Middle Element
  • Compare Target
  • Target Too Big
  • Discard Left Half
  • Target Too Small
  • Discard Right Half
  • Repeat Process
  • Logarithmic Efficiency
  • Halve Each Step
  • 30 Steps for a Billion
Feed/

Find one number in a sorted list of a billion in about 30 steps. That is binary search. The trick is that the array is sorted. So start by looking at the middle element. Target too big, throw away the left half. Too small, throw away the right. Either way, half the array is gone. Look at the new middle and have again and again. Closing in every step. A billion items collapses to just 30 checks because each step doubles your reach. That is log N. Halve. Compare, repeat. That is binary search.

"Find one number in a sorted list of a billion in about 30 steps."

👍
0
0 comments0 shares

Sign in to view and post comments.