previous | index | next

Searching the Sorted Database

Q: If you start at the beginning of the list, how many titles must you look at to determine that Batman is not in the database?

A: 5 titles

Q: How many titles must you look at to determine that Unbearable Lightness of Being is not in the database?

A: All of them

The problem is that we are sequentially searching the list.

"Sequentially" means "Starting at the beginning of the alphabet and searching in order from there."

Q: If there are n titles on the list, what is the efficiency of a sequential search?

A: linear — θ(n)

Sequential search does not take full advantage of the fact that the list is sorted.

Needed: a search method that is better than linear.


previous | index | next