Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

4. Consider the following program Program1(A, n) A is an array of n elements 1 P.Initialize(); 2for i 1 to n do 3 | 4

image text in transcribed

4. Consider the following program Program1(A, n) A is an array of n elements 1 P.Initialize(); 2for i 1 to n do 3 | 4 5 6 7 end 8 end 9 while P.Size() 0 do for j 1 to n do for k 1 to n do P.Insert (AAljAlk]); end 10 | x P.ExtractMax(); 11Print x; 12 end P.Initialize () initializes the data structures P.Insert (x) inserts elements x in P. P.ExtractMax) 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.ExtractMax () operations. Note that the time foir 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.SizeO) take constant time. Show your worlk

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Excel As Your Database

Authors: Paul Cornell

1st Edition

1590597516, 978-1590597514

More Books

Students also viewed these Databases questions