276 views
0 votes
0 votes
Suppose i delete the root element from the heap then i will apply the heapify() procedure on root,and suppose if i delete a random element form heap which will take O(n) time in total then the procedure is:-

1. Locate the element.

2.Swap with the last element

3.Delete the last element and perform Heapify() again.But this  heapify() we need to apply on root or the swapped location ?

And During insertion of particular element we need to do:-

1. Insert and element in the last node according to level order traversal then:-

                for(i = n/2 downto 1){ Maxheapify(A[i]) }

Am i right?

And following this strategy we will find the minimum number of swaps or comparison required isnt it?

1 Answer

0 votes
0 votes
IN worst case deletion from heap will take O (logn)..if u want to delete random element from heap...so to find that element it will take O (n) time...and just delete that element...replace with last element to maintain the property of heap ACBT (almost complete binary tree)...now after replaceming u cant perform either minheapify Top or Minheapify Bottom....beacuse u dont know which side to Go to arrange the tree(Up Or Down)....so just apply Min heapify Top from root to maintain heap property.

Related questions

0 votes
0 votes
0 answers
1
ishitasinha asked Jan 10, 2019
281 views
for directed weighted graph with edge weight non negative whether dijakstra will give correct result in every case ???
0 votes
0 votes
1 answer
4
Akash Kumar Roy asked May 2, 2018
391 views
E= V2If we apply log both side. What will be the result with respect to V. V=?