Question: Consider the following program: Program2(A, n) /* A is an array of n elements P.Initialize); 2 for i 1 to n do a for jI

 Consider the following program: Program2(A, n) /* A is an array

Consider the following program: Program2(A, n) /* A is an array of n elements P.Initialize); 2 for i 1 to n do a for jI to ln] do 4P.Insert (AAU) end 6 end 7 for i1 to n do sz P.ExtractMaxO Print r; 10 end P.Initialize() initializes the data structures P.Insert (r) inserts elements z in P P.ExtractMax) returns the maximum element of P and deletes it from P P.Size() returns the number of elements in P am2 assuming that P is implemented by some data ments in p and (1) the P.Insert ) and P.ExtractMax ) ents in P which ze) take (a) Analyze carefully the running time of Progr structure which takes (s) tirne for P insert() where s is the number of eler time for P.ExtractMax ). Analyze the total time for both operations. Note that the time for P.Insert) is dependent on the number of elem changes over the running time of the algorithm. Operations P.Initialize() and P.Si constant time. Show your work. (b) Analyze carefully the running time of Progran2 assuming that P is implemented by some duta is implemented by data structure which takes (1) tiine for P. Insert() and (s) time for P.ExtractMax() wher number of elements in P. Analyze the total time for both the P. Insert() and P.ExtractM operations. Note that the time for P.ExtractMax O is dependent on the number of elem ents in P which changes over the running time of the algorithm. Operations P.InitializeO and P.SizeO take constant time. Show your work

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!