Go to linear table search-multipart search

Source: Internet
Author: User

From: http://student.zjzk.cn/course_ware/data_structure/web/chazhao/chazhao9.2.3.htm

Multipart search

Blocking search is also called index sequential search. It is a search method with performance between sequential search and binary search.

1. Binary Search table Storage Structure
A binary search table consists of a linear table and an index table with "Segmented Order.
(1) linear table of "Segmented Order"
Table R [1 .. n] are divided into B blocks, the number of nodes in the first B-1 block is, the number of nodes in the B block is less than or equal to s; the keywords in each block are not necessarily ordered, however, the maximum keyword in the previous section must be smaller than the minimum keyword in the next section, that is, the table is "segmented and ordered.

(2) index table
Extract the largest keyword in each block and its starting position to form an index table ID [L .. B], that is:
Id [I] (1 ≤ I ≤ B) stores the maximum keyword of block I and the starting position of the block in Table R. Since table R is segmented and ordered, the index table is an incremental and ordered table.
[Example] is a storage structure that meets the preceding requirements. R has only 18 nodes and is divided into three nodes, each of which has 6 nodes, the maximum keyword 22 in the first block is less than the minimum keyword 24 in the second block, and the maximum keyword 48 in the second block is less than the minimum keyword 49 in the third block.

2. Basic Idea of segmented search
The basic idea of multipart search is:
(1) first, search for the index table
An index table is an ordered table. You can use binary search or sequential search to determine the node to be queried.

(2) search the blocks in sequence.
The block is unordered and can only be searched in sequence.

3. Example of multipart search
[Example] storage structure of the previous example:
(1) Find the node whose keyword is equal to the given value K = 24
Because the index table is small, you can use the sequential search method to find the index table. That is to say, we first compare K with the keywords in the index table until we find 1st nodes with the same key value as K. Because k <48, if a node with the key value of 24 exists, it must be in the second part; then, by ID [2]. ADDR finds the starting address 7 of the second block, starting from this address in R [7 .. 12] Until R [11]. key = K.
(2) Search for nodes whose keywords are equal to the given value K = 30
Determine the second part, and then search for it. Because the search in this block is unsuccessful, it indicates that there is no node with the keyword of 30 in the table.
Specific process [see animation demonstration]

4. Algorithm Analysis
(1) average search length ASL
Multipart search is a two-step search process. The average length of the entire search process is the sum of the average length of the two searches.
① Determine the block by binary search and the average search length when the block search is successful
Aslblk = aslbn + aslsq ≈ lg (B + 1)-1 + (S + 1)/2 ≈ lg (N/S + 1) + S/2

② Locate and determine the block in order, and the average length of the block search when the block search is successful
Asl 'blk = (B + 1)/2 + (S + 1)/2 = (s2 + 2 S + N)/(2 S)
Note:
When S =, asl' BLK takes the minimum value + 1. That is, when the block is determined by sequential search, the number of knots in each block should be selected.
[Example] If the table contains 10000 nodes, it should be divided into 100 blocks, each containing 100 nodes. Use sequential search to determine the block. The block search average requires 100 comparisons, while the sequential search average requires 5000 comparisons, and the binary search requires a maximum of 14 comparisons.
Note:
The efficiency of the segmented search algorithm is between sequential search and binary search.

(2) block size
In practice, block lookup does not have to divide a linear table into several blocks of the same size. You can partition the table based on its features.
[Example] the student registration form of a school can be divided by the Department number or class number.

(3) storage structure of nodes
Each block can be placed in different vectors, or each block can be stored in a single-chain table.

(4) Advantages of multipart search
The advantages of multipart search are:
① When you insert or delete a record in a table, you only need to find the block to which the record belongs, and then perform the insert and delete operations in the block.
② Because the stored records in the block are arbitrary, it is easier to insert or delete records without moving a large number of records.
The primary cost of multipart search is to increase the storage space of an auxiliary array and calculate the sorting of the initial table.

Go to linear table search-multipart search

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.