Maximum number of sorted I items

Source: Internet
Author: User

9-1 Maximum number of sorted I

Given a set of n elements, we hope to use a comparison-basedAlgorithmTo find the largest I elements in order. Find an algorithm that implements the following methods and has the best progressive and worst running time, and analyze the running time of each method (represented by N and I ).

A) sort the input numbers and list the maximum I numbers.

B) Create a priority queue for the input number and call the EXTRACT-MAX process I times.

C) A sequence statistic algorithm is used to locate the largest element I, divide the input array, and sort the maximum number I.

 

Analysis and answer:

A)The idea of first sorting the input number and then listing the maximum number of I is the simplest. the time complexity is O (nlgn ).

 

B)Create a maximum heap for the set containing n elements, the time complexity is round (N), then call I EXTRACT-MAX operation, the time complexity is O (I * lgn ), the total time complexity is O (I * lgn ).

 

C)Use the sequential statistics algorithm to find the largest element I. the time complexity is random (n), and then divide the input array. the time complexity is random (N). Finally, sort the maximum number I, the time complexity is always (I * LGI), and the total time complexity is always (n + I * LGI ).

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.