Question: 1a) Define what this algorithm is doing: 1b) Give an example of a best-case array of size 10 1c) Give an example of a worst-case

1a) Define what this algorithm is doing:

1b) Give an example of a best-case array of size 10

1c) Give an example of a worst-case array of size 10

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

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

foo(A, i)

end for

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]

swap A[i] and A[l]

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

swap A[i] and A[r]

foo(A, r)

if A[l] > A[i]:

swap A[i] and A[l]

foo(A, l)

end foo

Better representation of the function foo---------------------------------------------------------------

1a) Define what this algorithm is doing: 1b) Give an example of

procedure foo(int[] A, int i) int i = 2*i+1 intr = 2*i+2 if | >= A.length && r >= A.length: return if r >= A.length if A[i] A[i] && A[r] > A[i]: swap A[i] and A[r] foo(A, r) return; if A[U] > A[i]: swap A[i] and A[U] foo(A, 1) end foo procedure foo(int[] A, int i) int i = 2*i+1 intr = 2*i+2 if | >= A.length && r >= A.length: return if r >= A.length if A[i] A[i] && A[r] > A[i]: swap A[i] and A[r] foo(A, r) return; if A[U] > A[i]: swap A[i] and A[U] foo(A, 1) end foo

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!