Question: Give a worst-case analysis of the following algorithm: Problem: Create an ordered copy of an array Precondition: X is an unordered integer array X =

Give a worst-case analysis of the following algorithm:

Problem: Create an ordered copy of an array

Precondition: X is an unordered integer array X = [x0, x1, x2,.. ,xn] whose elements are of some ordered type

Postconditions: Array A contains the elements of X in ascending order, X is unmodfied

Give a worst-case analysis of the following algorithm: Problem: Create an ordered

07 A CON ORDEREDARRAY(X) 1 A[0] = X[0] 1 for i=1 to n - 1 2 k = BINARYSEARCH(A, i, X[i]) for j=i downto k + 1 4 A[j] = A[j 1] 5 A[k] = X[i] 6 return A For the purposes of this assignment, assume that BINARYSEARCH(A, k, 2) takes (lg k) steps, where the input array A has k elements. BINARY SEARCH returns the index in the array here x should be inserted to maintain ascending order. Your analysis should contain the following: (a) An expression of the runtime function of the algorithm (should involve a sum). (b) An asymptotic upper bound on the runtime of the algorithm. Here you must prove the upper bound. For example, to state that 2n +3 O(n) is not sufficient, you must prove this. An asymptotic lower bound on the runtime of the algorithm. Here again you must prove your result. (d) An asymptotic tight bound on the runtime of the algorithm. 07 A CON ORDEREDARRAY(X) 1 A[0] = X[0] 1 for i=1 to n - 1 2 k = BINARYSEARCH(A, i, X[i]) for j=i downto k + 1 4 A[j] = A[j 1] 5 A[k] = X[i] 6 return A For the purposes of this assignment, assume that BINARYSEARCH(A, k, 2) takes (lg k) steps, where the input array A has k elements. BINARY SEARCH returns the index in the array here x should be inserted to maintain ascending order. Your analysis should contain the following: (a) An expression of the runtime function of the algorithm (should involve a sum). (b) An asymptotic upper bound on the runtime of the algorithm. Here you must prove the upper bound. For example, to state that 2n +3 O(n) is not sufficient, you must prove this. An asymptotic lower bound on the runtime of the algorithm. Here again you must prove your result. (d) An asymptotic tight bound on the runtime of the algorithm

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!