Question: Program2(A, n) /* A is an array of n elements 1 P.Initialize(); 2 for i = 1 to n do for j = 1 to

 Program2(A, n) /* A is an array of n elements 1

Program2(A, n) /* A is an array of n elements 1 P.Initialize(); 2 for i = 1 to n do for j = 1 to n do for k = 1 to n do P.Insert (A[i] * A[j] * A[k]); end end C P.ExtractMax (); Print x; 10 end O 0 - 0 ou A con P.Initialize () initializes the data structures. P.Insert (x) inserts elements x in P. P.Extract Max () returns the maximum element of P and deletes it from P. P.Size () returns the number of elements in P. (a) Analyze carefully the running time of Program2 assuming that P is implemented as a Max-Heap. Analyze the total time for both the P.Insert () and P.ExtractMax () operations. Note that the time for P.Insert () and P.ExtractMax () is dependent on the number of elements in P which changes over the running time of the algorithm. Operations P.Initialize () and P.Size () take constant time. Show your work. (b) Analyze carefully the running time of Program2 assuming that P is implemented by some data structure which takes e(s) time for P.Insert () where s is the number of elements in P and O(1) time for P.ExtractMax (). Analyze the total time for both the P.Insert () and P.ExtractMax () operations. Note that the time for P.Insert() is dependent on the number of elements in P which changes over the running time of the algorithm. Operations P.Initialize () and P.Size () take constant time. Show your work. (c) Analyze carefully the running time of Program2 assuming that P is implemented by some data structure which takes O(1) time for P.Insert () and e(s) time for P.ExtractMax () where s is the number of elements in P. Analyze the total time for both the P.Insert () and P.ExtractMax () operations. Note that the time for P.ExtractMax () is dependent on the number of elements in P which changes over the running time of the algorithm. Operations P.Initialize () and P.Size() 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!