Class 17: Binary Search
Held Monday, February 22
- Exam 1
- I've corrected some typos on the exam. There's no guarantee of
extra credit for identifying typos, but you certainly get some
- There have been some questions on how to test your inventory
class from problem 5. We'll spend some time discussing that
- Are there other questions.
- As you may have noted, a new whiteboard has arrived. Later this
week, I'll show you how cool it is.
- Today at noon, there is a meeting in 2413 to discuss summer research
opportunities in computer science at Grinnell. There are also
web pages describing
- On Tuesday at 12:15 in 2413, there is an informational meeting
on an MBA Program with specialization in information and software
systems. It seems that students will receive a $20,000 fellowship
- On Tuesday at 4:??, there is a meeting to discuss summer research
opportunities in mathematics at Grinnell.
- A slight change in the schedule: today we'll work on lab A2, after
a short discussion of searching.
- Sorry if today's notes are therefore more abbreviated. You should
have read about binary search in the lab manual, and you'll get to
read about it again in the next reading from the book.
- A technique for searching through sorted arrays.
- One of the classic algorithms.
- Takes advantage of the strategy of divide and conquer:
you break the list in half, and only work on one half.
- Elegantly expressed recursively.
- (Can also be expressed iteratively.)
- To search for element e in sorted array A,
search for e in the subrange of A from 0 to
(last index in A).
- To search for element e in subrange l to u
- Identify a midpoint, m
- If e is at the midpoint, return the appropriate information.
- If e is smaller than the value at the midpoint, throw away
the upper half of the array (reduce the subrange).
- If e is greater than the value at the midpoint, throw away
the lower half of the array (reduce the subrange).
- We'll do an example that has to do with phone books.
- What's the running time?
- How might we code it in Java?
Do A2.5. We'll discuss step 1 aloud.
- Created Monday, January 11, 1999.
- Added short summary on Friday, January 22, 1999.
- Filled in details on Monday, February 22, 1999.