A Binary Search
The list of names below is sorted into alphabetical order. When we search an ordered list, we can write a much more efficient search. For an ordered list, you can use a binary search.
index |
names |
years |
0 | Amy | 2010 |
1 |
Bill | 1985 |
2 |
Debbie | 1976 |
3 |
Ian | 1987 |
4 |
Jay | 1974 |
5 |
Josh | 2003 |
6 |
Lin | 2009 |
7 |
Mark | 1979 |
8 |
Paul | 2001 |
We will use the same program that read in the names from a file, but instead of a sequential search, we will use a binary search.