Bfprt (linear search algorithm)

Source: Internet
Author: User

The problem solved by the bfprt algorithm is very classic, that is, the element of the K (k) is selected from the sequence of n elements, through clever analysis, bfprt ensures linear time complexity in the worst case. The idea of this algorithm is similar to that of fast sorting. Of course, in order to make the algorithm in the worst case, it can still reach the time complexity of O (N, the five algorithm authors have done some subtle work.

Algorithm steps:

1. Divide n elements into N/5 (Upper Bound) groups.

2. Obtain the median of each group and any sorting method, such as insert sorting.

3. recursively call the selection algorithm to find the medians of all medians in the previous step. If it is set to X and the even medians, it is set to select a small median.

4. Use X to split the array and set the number of less than or equal to X to K. N-k is the number of more than X.

5. if I = K, return X. If I <K, Recursively search for elements smaller than X; if I> K, recursively search for elements smaller than I-K in the element greater than X.

Termination condition: If n = 1, the return value is the small I element.

Bfprt (linear search algorithm)

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.