QuestionQuestion

Consider the following recursive algorithm:

Unknown(A,i,j);
{
    if A[i] > A[j] then exchange A[i] and A[j];
    if i+1 >= j then return;
    k = (j-i+1) / 3; //integer division
    Unknown(A,i,j-k);
    Unknown(A,i+k,j);
    Unknown (A,i,j-k);
}

a) What does Unknown(A,1,n) do?

b) Prove that it indeed does what you have said in (a).

c) Give a recurrence for the worst-case time of Unknown(A,1,n) and solve it in big Theta.

Solution PreviewSolution Preview

This material may consist of step-by-step explanations on how to solve a problem or examples of proper writing, including the use of citations, references, bibliographies, and formatting. This material is made available for the sole purpose of studying and learning - misuse is strictly forbidden.

a) The given algorithm sorts the array 1..n, by taking first 2/3 of array, then last two 2/3 of the array and in the end first 2/3 again (this because of the value of k, which is about 1/3 of the array length)....
$10.00 for this solution

PayPal, G Pay, ApplePay, Amazon Pay, and all major credit cards accepted.

Find A Tutor

View available Data Structures and Algorithms Tutors

Get College Homework Help.

Are you sure you don't want to upload any files?

Fast tutor response requires as much info as possible.

Decision:
Upload a file
Continue without uploading

SUBMIT YOUR HOMEWORK
We couldn't find that subject.
Please select the best match from the list below.

We'll send you an email right away. If it's not in your inbox, check your spam folder.

  • 1
  • 2
  • 3
Live Chats