recategorized by
438 views
0 votes
0 votes
time taken to delete a node from min heap if you know the value but not position

To find the position of the number  in min heap should not be log(n)

why is it so O(n)
recategorized by

1 Answer

Best answer
0 votes
0 votes
Since we don't know the position of the element to be deleted, we need to search that element and then delete it.

For searching in a heap (be it min or max), we need to go through all the elements of the heap. Because there is no total ordering of the heap elements. There is no relation between the siblings of a node. So, searching will take O(n).

Now for deletion, it will take O(logn).

This gives total complexity = O(n) + O(logn) = O(n)
selected by

Related questions

1 votes
1 votes
1 answer
1
Kaluti asked Nov 6, 2017
318 views
To find the kth smallest element in the heap , the time required is O(n), where k is less than the number of element in the heap. is this statement true should not it be ...
11 votes
11 votes
5 answers
2
Vikrant Singh asked Dec 28, 2014
3,690 views
What is the complexity of finding $50^{th}$ smallest element in an already constructed binary min-heap?$\Theta(1)$$\Theta (\log n)$$\Theta (n)$$\Theta (n \log n)$
1 votes
1 votes
1 answer
3
4 votes
4 votes
1 answer
4
Gaurab Ghosh asked Jan 18, 2017
1,525 views
If you are given a sorted list with n elements in ascending order. Then what will be the Time complexity to build a Min heap from the given array?