Home > other >  Static lookup knowledge learning summary
Static lookup knowledge learning summary

Time:09-18

Static search refers to the static on the lookup table lookup operation, find meet the conditions of data elements or location of the various properties, it has the following three find ways:
A, sequential search
1, in order to find, just as its name implies is the process in order to use the search terms in the given value and find the key data elements in the table value, if the value of a record with the given values are equal, then find the successful, returns the record the value of the storage location; If on the other hand, until the last record keyword value with the given values are not equal, and lookup fails, the return to find failure marks,
2, the lookup table storage structure is linear table table or list (order),
Table 3, order type definition:
100//# define MAX_NUM used to define table length
Typedef struct elemtype {
Keytype key;
.
} RecordType [MaxSize];
Number of data elements for n (n4, suppose that we have more than one keyword, we only select a we need to compare the value of the keyword r, put them in the array when the array with n elements, assuming that the records of keywords to find is k, the integrity of the sequential search algorithm, are given here we
Int SeqSearch (RecordType r, int n, Keytype k) {
/* return key value is equal to the position of data elements in the table r k, n is the number of elements in the table */
i=n;
R [0]. Key=k;/* lookout */
While (r [I]. The key! K)={
I -;
}
If (i> 0 {
Return (I);/* find success */
} else {
The return (1);/* * lookup failure/
}
}
Second, binary search
1, binary search is only applicable for orderly sequence table lookup,
2, each on a binary search, or to find success, end find; Will either find narrow half, repeat, until find success or search range is empty or lookup failure, so the binary search need time is relatively small, high efficiency,
3, binary search, also known as binary search, it is to the efficient and orderly sequence table lookup method, ordered lists the corresponding vector R in maximum input keywords, 12 nodes within each keyword for 1000 positive integer, and use half-width commas,
4, the description of the binary search algorithm is as follows:
Int BinSearch (RecordType r, int n, Keytype k) {
/* binary search key words in the order table r value is equal to the data elements of k */
Int low, high, mid;/* low, is refers to the starting point; High refers to the highest point; Mid is refers to the low and high and divided by 2 value; */
Low=1; High=n;/* set initial search range of low, high-end pointer */
While (low & lt;=high) {
Mid=+ high (low)/2;/* take a table in the middle of the position */
If (k==r (mid). Key) {
Return (mid);/* find success */
} else {
If (kHigh=mid - 1;/* in the left child table lookup */
} else {
Low=mid + 1; The right child table lookup *//*
}
}
}
The return (1);/* * lookup failure/
}
5, the average search length log2n binary search algorithm, relatively less, lookup speed, it applies to that once the build is little changed, and often need to the order of the table lookup,
Three, chunked retrieval
1, block Search (Blocking Search) is also called the indexed sequential Search, it is a kind of performance between sequential Search and binary Search to find methods,
2, the lookup table storage structure: linear table lookup table by "chunking orderly" and "orderly" index table,
(1) "block orderly" linear table: linear table R are divided into several blocks, each block in the key not orderly, but before a keyword must be smaller than the maximum after a minimum of keywords, it indicates that the "block order",
(2) the "orderly" index table: extraction of each piece of the largest keyword and its starting position and length of an index table ID,
3, block when first search index table lookup, the index table is ordered table, binary search can be used or sequential search, to identify the node where a pending investigation, and then identified block sequential search,
4, index data element in a table consists of two fields, the key domain for indexed the maximum number of keyword in the number of data elements, link the domain to be indexed several data elements in the position of the first data element number,
Four, static lookup methods compare
1, ASL (business Search Length), the Average Search Length: sequential Search, binary Search, block Search is in between two (sequential Search and binary Search),
2, it is suitable for table structure: sequential search is ordered list, unordered list can be no requirements (i.e., on the table), binary search is ordered table, block is partitioned order table lookup,
3, storage structure: sequential search is sequential storage structure and linear list, binary search is a sequential storage structure, block search is sequential storage structure and linear list,
  • Related