Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

image text in transcribed
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

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

Practical Oracle8I Building Efficient Databases

Authors: Jonathan Lewis

1st Edition

0201715848, 978-0201715842

More Books

Students also viewed these Databases questions