To insert an element, we put it at the beginning or end of the array, vector or list. To look up an element, we step through the pairs one by one, comparing the key we are searching for to the key in each pair. To insert an element, we put it at the appropriate place, shifting as necessary. To look up an element, we do binary search on the sorted array. Another strategy for building dictionaries is to use search trees .
Search trees use the basic idea of binary search, but encapsulate it in a particular way.
As in the case of heaps, search trees apply the divide and conquer approach to the design of data structures. For example, we might build the following structure for the first six letters of the alphabet. They look somewhat like upside-down trees . The same way we use binary search. To find an element in a search tree, you compare the object you're looking for to the current node.