Linear search of ten algorithms

Source: Internet
Author: User

Introduced:

The problem solved by the bfprt algorithm is classical, that is, to select the elements of K-Large (K-small) from the sequence of some n elements, and through ingenious analysis, the BFPRT can be guaranteed to remain linear time complexity in the worst case. The idea of the algorithm is similar to the idea of fast sequencing, of course, in order to make the algorithm in the worst case, still can achieve O (n) time complexity, five-bit algorithm authors have done a subtle processing.

Complexity of Time

O (N)

algorithm steps:

1. Divide n elements into groups of N/5 (upper bound) for each of the 5 groups.

2. Take out the median of each group, any sort method, such as insert sort.

3. Recursive invocation of the selection algorithm to find the median of all the median in the previous step, set to X, the case of an even number of median is set to select the middle of the small one .

4. Use x to divide the array, set the number of less than equals X is K, the number of greater than X is n-k.

5. If i==k, return x; if i<k, find The small element of I recursively in the element less than X, and if i>k, recursively find the i-k small element in the element greater than X.

Termination condition: When n=1, it is the I small element that is returned.


For specific details, please click here: A linear search algorithm of ten algorithms


Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Linear search of ten algorithms

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.