Find the seam first.
transcript
A sorted list was rotated. Now plain search fails. One comparison fixes it. Here is how it works. Let me show you.
It rises to twelve. Then it drops to two. That drop is the seam. The lowest value is right after it. Name the seam, and you name the answer. Remember that for later.
Compare the middle with the right end. Above it means the seam is right. Below it means the seam is here or left. Why the right end? It sits in the last piece. So every middle has a fixed reference.
The middle is twelve. Above five. Go right. The next middle is four. Four is below five. Go left. The answer is two. Four steps for seven readings.
One hundred thousand readings. Seventeen steps, not a hundred thousand. For a million readings, twenty steps.
Name the seam first. Compare with the right end. Then search one piece. Full breakdown in the lecture.