Question: Q 1 . Given the following algorithm Algorithm ( B ) for j 2 to length [ A ] do key A [ j ]

Q1. Given the following algorithm
Algorithm(B)
for j 2 to length[A]
do key A[j]
i j -1
while i >0 and A[i]> key
do A[i +1] A[i]
i i -1
A[i +1] key
(a) Describe the function of this algorithm
(b) Write a recursive version of this algorithm in pseudocode.
Q2.Given the following algorithm
Algorithm(A)
for i 1 to length[A]
for j length[A] down to i +1
if A[j]< A[j -1]
swap A[j] A[j -1]
(a) Describe the function of this algorithm
(b) Write a recursive version of this algorithm in pseudocode.

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!