edited by
415 views
2 votes
2 votes
consider a set of n distinct numbers by comparison find the 3 largest numbers,

which of the following is true

1.3 largest elements can be found by O(log^2 n) comparisons.
2.O(log^2 n) comparisons is not sufficient but 3 largest can be found in n comparisons.

3.n+O(1) comparisons are needed for 3 largest elements.

4.n+O(1) comparisons are not enough n+O(log n) comparisons are needed.
edited by

1 Answer

1 votes
1 votes
Is ans D correct?

If yes then I thought by this way!

Build Max heap in O(n) time and then extract 3 maximum elements.

To extract them 1 by 1 and again satisfy max heap property we need to execute MAX Heapify algorithm which is of 3 * log(n) = O(logn)

hence total is n + O(logn)

Related questions

1 votes
1 votes
2 answers
1
Nitesh_Yadav asked Apr 11, 2022
275 views
What is the time complexity of the below mentioned recursive function.int f(n){ if(n!=1){ return f(n/2)+f(n/2);}elsereturn 10;} O(n)O(n^2)O(log n)O(n logn)
0 votes
0 votes
1 answer
2
raja11sep asked Jan 15, 2022
871 views
Can anyone explain each option, for every option if it is true then why? If false then why? (Please don’t comment like answer is A,B etc) Please help
2 votes
2 votes
2 answers
3
LRU asked Oct 15, 2021
646 views
Consider an array contains n integers, each integer belongs to {0, 1, 2}. What is the best case time complexity to sort an array?
0 votes
0 votes
0 answers
4
Ajit J asked Dec 8, 2018
384 views
Will the complexity of the function be $\Theta n^{2} or \Theta n^{3}?$