Try it on paper first. A hint, the key idea and the worked solution are here when you need them.
Which search would you use? (a) A list of names in no particular order. (b) A sorted list of numbers. (c) A list of numbers that is not sorted, searched only once. How many checks does the binary search need at most for , , and items?
Binary search needs a sorted list. Sorting costs time, so it pays off when you search many times.
Have you tried it?
Work it out on paper first. It is fine to get stuck or make a mistake: that is how we learn. When you are ready, compare your working with the solution.
The most checks for binary search: , , and .
Log in to join the discussion.
Loading…