Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Describe best case and worst case scenarios for run time of following pseudo code: Algorithm thisAlgo (int[] A : an array of N integers) for(int

Describe best case and worst case scenarios for run time of following pseudo code:

Algorithm thisAlgo (int[] A : an array of N integers)

for(int i = N /2; i >= 0; i --):

foo (A , i )

end for

end thisAlgo

procedure foo(int[] A, int i)

int l = 2*i+1

int r = 2*i+2

if l >= A.length && r >= A.length:

return

if r >= A.length

if A[i] < A[l]:

swap A[i] and A[l]

return;

if A[r] > A[l] && A[r] > A[i]:

swap A[i] and A[r]

foo(A, r)

return;

if A[l] > A[i]:

swap A[i] and A[l]

foo(A, l)

end foo

Describe the best/worst case in terms of what the array would need to be to get the best or worst case. For example, could best case be for array in descending order?

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

Step: 3

blur-text-image

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

SQL Database Programming

Authors: Chris Fehily

1st Edition

1937842312, 978-1937842314

More Books

Students also viewed these Databases questions

Question

What is { 0 1 } ^ - 1 in AES finite field GF ( 2 ^ 8 ) ?

Answered: 1 week ago