290 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

307
views
0 answers
0 votes
ishitasinha asked Jan 10, 2019
307 views
for directed weighted graph with edge weight non negative whether dijakstra will give correct result in every case ???
299
views
0 answers
1 votes
Prince Sindhiya asked Nov 21, 2018
299 views
divisibility: |w| i.e length of string is divisible by a,b.If a doesn't divide b and b doesn't divide a then Min. states = a*bCase 1 : Divisible by a and b - ... a then Min. states = GCD(a,b)Doubt -> is these all cases are true always ?
331
views
0 answers
0 votes
Na462 asked May 3, 2018
331 views
I statred my preparation for GATE 2019 very early and i finished almost everything i.e. all the subjects with there previous year gate questions from gateoverflow book ... i know i can.Is my above strategy right or what should i follow?
435
views
1 answers
0 votes
Akash Kumar Roy asked May 2, 2018
435 views
E= V2If we apply log both side. What will be the result with respect to V. V=?