Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

  1. Open the book in the middle  mid = (max-+min)/2 (min, max and mid are the page numbers here)
  2. If the name you want is on that page, you're done.
  3. If the name is before the names where you opened the book, re-open the book halfway on the smaller side and repeat the process.
  4. If the name is after the names where you opened the book, re-open the book halfway on the larger side and repeat the process.

...

  1. min = 0, max = 13, so mid = 6 ==>  so look at the #12 (min, max and mid are indices into the array here)
  2. min= 0, max = 6, and 11 < 12, so look at mid = (6+0)/2 = 3, i.e. the #7.
  3. min= 3, max = 6, and 11 > 7, so look at the mid = (6+3)/2 = 4, i.e. the #10
  4. min = 4, max = 6 and 11>10 so look at the mid=(4+6)/2 = 5, i.e. the #11
  5. min = 5, max = 6,  there's only one element left and since 11 = 11, we found it! 

...