retagged by
2,229 views
1 votes
1 votes

What is worst case time complexity to delete middle element from the min heap of n distinct elements?

  1. O(logn)
  1. O(n)
  1. O(nlogn)
  1. O($n^{2}$)
retagged by

2 Answers

1 votes
1 votes
The leaves of the heap forms the mojority of elements , it can be the case that middle element is present at the leaf and there are n/2 leaves .so finding an element from n/2 takes O(n). Now delete the element whitakes constant time O(1). We have to Reheapify now to arrange the heap which will take O(logn). So total O(n)+O(logn)= O(n) should be the answer
1 votes
1 votes
Find Middle element (i.e mid index) of the array at n/2 -----> O(1)

Delete Mid and replace it with last element -------> O(1)

Build heap ----> O(n) or you can use heapify bottom-up approach O(logn)

Dominant term- > O(logn)

Related questions

0 votes
0 votes
2 answers
3