Explanation of average search length

Source: Internet
Author: User

1. Sequential search:

From the end of the table, scan the linear table sequentially and compare the node keywords scanned with the given value K.

Under equi probability conditions, the average length of... search is ASL = (n +... + 2 + 1)/n = (n + 1)/2;

2. Binary Search:

The premise is that a linear table is an ordered table. Assume that the data is sorted in ascending order. For the given value X, the comparison starts from the intermediate position of the sequence. If the current position value is equal to X, the query is successful. If X is less than the current position value, search in the first half of the series; if X is greater than the current position value, continue searching in the second half of the series until it is found.

Under the equi probability condition... average search length: ASL = log2 (n + 1)-1 = log2 (n + 1)

Reason: the binary tree is used to describe the relationship between the height D of the tree and the node tree: d ^ 2-1 = N; so d = log2 (n + 1 ), each layer only needs to be compared once. Therefore, log2 (n + 1) can be compared at most.

3. multipart search:

It is also called index ordered search, which is ordered by blocks (the keywords in each block are not necessarily ordered, but the maximum keywords in the previous block must be smaller than the minimum keywords in the next one, that is, the Segmented Order .) Linear table and index table. For example, the R [1... n] is divided into B blocks, then the number of B-1 block nodes is S = [N/B], the last part is allowed to be less than or equal to S. An index is an incremental ordered table.

The average search length is divided into two parts: Index Table search + intra-block search. (The index table can be searched by binary method and sequence. The block is unordered, so it can only be searched by sequence)

If the block is determined by binary search, ASL = log2 (B + 1)-1 + (S + 1)/2 = log2 (N/S + 1) + S/2;

If the block is determined by searching in order, ASL = (B + 1)/2 + (S + 1)/2 = (s ^ 2 + 2 S + n) /(2 S ).

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.