Episode 3
Three Drawers Before the Bell
Duck has a ticket for his missing parade whistle. There are 7 drawers in the robot's workshop. Robot can only open 3 drawers before the bell goes off.

















Episode transcript
Ticket 23
Robot spots a red-booted duck on the monitor. Duck's claim ticket number is 23.
Duck: My parade whistle! Gotta have it before that bell goes off!
He sees a row of 7 identical drawer fronts. They have no numbers.
Duck: Drawer 23?
Robot: I put tags inside the drawers. Left to right, the numbers increase.
All seven drawers are closed.
Robot: 3 tries before the bell. First, the middle drawer.
The first two checks
The robot draws open the drawer in the 4th position from the left. Inside it is a tag with the number 19 on it.
Everything to the left of that is smaller.
23 > 19
Duck: Keep the three on the right.
Robot: Try the one in the middle of the three.
Starting from the left side of the rack, this is drawer number six.
In the sixth drawer you can find tag 35. If you look at the drawer further to the right you will find an even greater number.
Duck: 35 is way too big. Look to the left.
The last check
One side is the drawer with 19 in it. The other side is the drawer with 35. There's also one closed drawer in between.
That's the 5th drawer from the left.
The robot opens the drawer for him. There's the brass whistle.
Duck: 23!
The robot whistles into the workshop. A few seconds later the workshop bell chimes.
Duck: Did the bell just respond to your whistle?
Ticket 31
The tags are in the same order.
For ticket 31 it's back to the middle.
31 > 19 (right)
31 < 35 (left)
Check 3 (drawer 5)
The robot opens the drawer for him. It sees a claim tag inside which says 23.
31 > 23
23 eliminates drawer 5 and all the drawers left of it for ticket 31. The robot also knows drawer 6 has 35 from the last try, so it's already eliminated 6 and 7. There's no fourth drawer to pull open in the duck's search for ticket 31.
Duck: The next tag after 23 is 35. No space for 31.
Robot: If you mix your tags then you may miss the drawer you want.
Binary search
Binary search tests the middle value in the range of a sorted list where a match may exist. If the middle value is a match, then stop searching. If the middle value is smaller, then that value and everything on the left of it can't be a match. If the middle value is larger, then that value and everything on the right of it can't be a match. Test the remaining part using the same process.
If the part of the list that is still in the search area is empty, then the search ends. Every element in this sorted list has been eliminated.
3, 8, 14, 19, 23, 35, 52
If you start from the extreme left, it will take you 5 drawers to get to the whistle. If you do binary search, you'd get the same whistle in 3 drawer openings: 4th, 6th, and 5th.
What if tags were jumbled?
23, 8, 14, 19, 3, 35, 52
But the tag in the middle drawer is still 19. The robot will still turn right and look for 23. We could miss a matching tag by performing the same search.
If you check the middle drawer first, you can only eliminate one side if the tags are ordered.