retagged by
292 views
1 votes
1 votes
time complexity to find the n/2 largest element in max heap ?\

it must be nlogn
retagged by

2 Answers

1 votes
1 votes
Use Extract Max n/2 times to get n/2th maximum element from the Max Heap... Time  --  O(nlogn)
1 votes
1 votes
To find an element in max heap takes O(n) time.

To fing n/2 largest element it also takes O(n) time because it will compare with n/2 elements of the max heap which will take O(n) time only not O(nlogn) as we are not asked to delete the elements from the heap

Related questions

0 votes
0 votes
3 answers
2
Nisha Bharti asked Sep 26, 2022
730 views
What is the time & space complexity of this algorithm?Main(){ for(i=n; i>10; i=i^1/4) { for(j=201; j<n^3; j=j+400) ...
0 votes
0 votes
1 answer
3
tusharb asked Feb 18, 2022
692 views
As we know the time complexity of solving the greedy knapsack algorithm depends mainly on the sorting algorithm used, Can we use counting sort as the sorting algorithm to...
1 votes
1 votes
0 answers
4
srestha asked May 19, 2019
633 views
Let $A(n)$ denotes the number of $n$ bit binary strings which have no pair of consecutive $1’s.$ what will be recurrence relation for it and what will be it’s Time Co...