The previous articles introduced basic sorting algorithms, and sorting is usually a prelude to finding. Starting from this article, the basic lookup algorithm is introduced.
In the introduction of the search algorithm, first of all need to understand the symbolic table of the abstract data structure, this article first introduced what is a symbol table, and this abstract data structure of the API, and then introduced two simple symbol table implementation.
A symbol table
Before we begin to introduce the lookup algorithm, we need to define an abstract data structure called the symbol table, which is similar to the dictionary we use in C #, which is an abstraction for elements with key values, each with a key and value. We can add Key,value key value pairs to the inside, or we can find value based on key. In real life, we often encounter a variety of needs based on key to find value, such as DNS based on domain name lookup IP address, library based on index number to find books and so on:
To achieve this, we define an abstract data structure and then choose the right data structure to implement:
public class St<key, value>
Two implementation
1 using unordered list to implement lookup table
The key to the implementation of look-up table is the selection of data structure, the simplest one is to use unordered list to achieve, each node record key value, value and the object pointing to the next record.
For example, when we insert an element into a linked list, we start with the table header and, if found, update value, otherwise insert a new node element in the table header.