lookup
Basic concepts
definition

lookup: the process of finding data elements that meet certain conditions in data combination.

Lookup table(lookup structure): the data set used for lookup is called lookup table, which is composed of data elements (or records) of the same type. （table/graph/）
 Static lookup tables: finding
 Dynamic lookup table: find, add or delete data

keyword: the value of a data item that uniquely identifies a data element. Using keyword based search, the search result should be unique. （key）

Find length: in the lookup operation, you need toNumber of keyword comparisonsThis is called the lookup length.

Average lookup length(ASL): the average number of keyword comparisons in all search processes.
\(ASL= \displaystyle \sum^{n}_{i=1}{P_iC_i}\)
n: Number of data elements
\(P_i\): probability of finding the ith element
\(C_i\): find the find length of the ith element
The probability of finding any element is the same
The order of magnitude of ASL reflects the time complexity of the search algorithm.
Sequential search
Linear lookup: linear table (sequential table, linked list)
Algorithm implementation
int Search_Seq(SSTable ST,ElemType key){
int i;
for(i=0;i
Half search
Binary lookup, used for ordered sequential tables.
typedef struct{
ElemType *elem;
int TableLen;
}SSTable;
//Half search
int Binary_Search(SSTable L,ElemType key){
int low=0,high=L.TableLen1，mid;
while(low<=high){
mid=(low+high)/2; // Take the middle position
if(L.elem[mid]==key)
return mid; // If the search is successful, the location will be returned
else if(L.elem[mid]>key)
high = mid1; // The first half continues to find
else
low=mid+1; // The second half continues to find
}
return 1; // Search failed, return  1
}
B tree
//5fork lookup tree
struct Node{
Elem Type keys[4]; // Up to 4 keywords
struct Node*child[5]; // Up to 5 children
int num; // Keywords in nodes
}
//In the Mary search tree, except the root node, any node has at least [M / 2] forks, that is, it contains at least [M / 2]  1 keywords
Morder Btree  Morder B + tree  

analogy  Binary lookup tree – > Mary lookup tree  Block search – > multi level block search 
keyword  N keywords correspond to n forks  
Node containing information  All nodes  Lowest leaf node 
Search method  If the search is successful, it may stop at any layer node  Sequential search. If the search succeeds or fails, it will reach the lowest node 
Find speed  instable  stable 
Same point  Except the root node, at least\([m/2]\)The subtree of any node should be the same height 
Hash table
Hash table(hash table) hash table: it is a data structure. The keywords of data elements are directly related to their storage addresses.
Keyword establishes the connection with the storage address through the hash function (hash function) addr = H (key). chy
Construction method
synonym: different keywords are mapped to the same value through hash function
conflict: the position determined by the hash function already holds other elements
Zipper method(link method) (link address method): store all “synonyms” in a linked list to deal with conflicts
Division method : the hash table length is m, and the hash table length is not greater than m but closest to or equal to MPrime numberp
direct addressing : H (key) = key or H (key) = a * key + B
Where a and B are constants. This method is the simplest and will not cause conflict. It is suitable for the situation that the distribution of keywords is basically continuous, otherwise more empty spaces will waste storage space.
Digital analysis: select several bits with uniform digital distribution as the hash address.
Methods of handling conflicts
Open addressing method: