1. Definition
Block Lookup (Blocking search) is also called index order lookup . It is a way to find performance between sequential lookups and binary lookups.
2. Basic Ideas
The basic idea of block lookup is:
(1) First look up the index table
The index table is an ordered table, which can be found in binary or sequential order to determine which piece of the unknown Origin node.
(2) Then order-finding in the identified blocks
Because the blocks are unordered, they can only be searched in order .
3. Storage structure
A binary lookup table consists of a linear table and an index table with a "block order".
(1) Linear table with "block order"
Table R[1..N] are divided into B block, the number of nodes in the front b-1 block is, the node of the B block is less than or equal to s; the key word in each piece is not necessarily ordered, but the largest keyword in the previous piece must be less than the smallest keyword in the latter piece, i.e. the table is "block ordered".
(2) Index Table
Extracting the largest keyword in each block and its starting position constitute an index table id[l. b], which is: Id[i] (1≤i≤b) holds the maximum keyword of block I and the starting position of the block in table R. Because table R is block-ordered, the index table is an ascending ordered table.
"Example" is to meet the requirements of the storage structure, where r only 18 nodes, is divided into 3 blocks, each block has 6 nodes, the first block of the maximum keyword 22 is less than the second block of the minimum keyword 24, the second block of the largest keyword 48 is less than the third block of the smallest keyword 49.
4. Block Lookup Example
"Example" for the storage structure of the example above:
(1) Find the node where the keyword equals the given value k=24
Because the index table is small, you may want to find the index table using the sequential lookup method. That is, the K and the index table in the first comparison of the key, until the 1th key is found to be equal to the K node, because of k<48, so the keyword is 24 if the node exists, it must be in the second block; then, Id[2].addr finds the start address 7 of the second block, starting at r[ 7..12] in order to be searched until r[11].key=k.
(2) Find the node where the keyword equals the given value k=30
Determine the second block first, and then look in the block. Because the lookup in this block is unsuccessful, there is no node with the keyword 30 in the table.
5. Algorithm Analysis
(1) Average search length ASL
Block Lookup is a two-time lookup process. The average lookup length for the entire lookup process is the sum of the average lookup lengths of two lookups.
① The average lookup length in binary lookup to determine block, block lookup success
ASLBLK=ASLBN+ASLSQ≈LG (b+1) -1+ (s+1)/2≈lg (n/s+1) +S/2
② The average lookup length in order to find the block when the block lookup succeeds
ASL ' blk= (b+1)/2+ (s+1)/2= (s2+2s+n)/(2s)
Note:
When s= the ASL ' BLK takes a minimum of +1, that is, when using sequential lookups to determine the block, the nodes in each block should be selected as.
"Example" if there are 10,000 nodes in the table, it should be divided into 100 blocks, each containing 100 nodes. The order lookup determines the block, and the block lookup averages 100 comparisons, while the sequential lookup averages 5,000 comparisons, and the binary lookup requires a maximum of 14 comparisons.
Note:
The efficiency of the block lookup algorithm is between the sequential lookup and the binary lookup.
(2) The size of the block
In practice, block lookups do not necessarily divide a linear table into blocks of equal size, which can be partitioned according to the characteristics of the table.
"Example" a student registration form in a school can be divided by a department number or class number.
(3) Storage structure of nodes
Each block can be placed in a different vector, or each piece can be stored in a single linked list .
(4) Advantages of block lookup
① when a record is inserted or deleted in a table, the insert and delete operations are performed within the block whenever the block to which the record belongs is found.
② because the storage of the block record is arbitrary, so it is easier to insert or delete, no need to move a large number of records .
(5) Disadvantages of block lookup
The primary cost of block lookups is to increase the storage space of an auxiliary array and to sort the initial table tiles .
Block Lookup (Blocking search)