Question: 6. Consider the following program: Program1 (A, 1) /* A is an array of n elements 1 P.Initialize(); 2 for it 1 to lVnj do

6. Consider the following program: Program1 (A, 1) /* A is an array of n elements 1 P.Initialize(); 2 for it 1 to lVnj do 3 for j+1 to n do 4 | P.Insert (A[i] * A[j]); 5 end 6 end 7 while P.Size() +0 do 8 + P.Extract Max(); 9 Printe; 10 end P.Initialize() initializes the data structures. P.Insert (r) inserts elements r 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. Analyze carefully the running time of Program1 assuming that P is implemented as a Max-Heap. An- alyze the total time for both the P.Insert() and P.Extract Max) 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
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
