Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

image text in transcribed

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

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

101 Database Exercises Text Workbook

Authors: McGraw-Hill

2nd Edition

0028007484, 978-0028007489

More Books

Students also viewed these Databases questions

Question

1. Define and explain culture and its impact on your communication

Answered: 1 week ago