Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

1. (10 pts) A grad student comes up with the following algorithm to sort an array A[1.n] that works by first sorting the first 2/3rds

image text in transcribed

1. (10 pts) A grad student comes up with the following algorithm to sort an array A[1.n] that works by first sorting the first 2/3rds of the array, then sorting the last 2/3rds of the (resulting) array, and finally sorting the first 2/3rds of the new array. 1: function G-SORT(A, n) takes as input an array of n numbers, Al..n G-sort-recurse(A, 1, n) 3: end function function G-SORT-RECURSE(A, I, u) 4: 5: ifu_K0then D1 or fewer elements already sorted 2 elements D swap values return 7: else if uL 1 then temp Alu All temp end if 12: 13: 14: 15: 16: 17: 18: 19: 20: end functiorn else D 3 or more elements size u-1+1 twothirds- [(2 * size)/3] G-sort-recurse(A,L, l + twothirds - 1) G-sort-recurse(A, u twothirds +1,u) G-sort-recurse(A,e,e + twothirds - 1) end if First (5 pts), prove that the algorithm correctly sorts the numbers in the array (in increasing order) After showing that it correctly sorts 1 and 2 element intervals, you may make the (incorrect) assump- tion that the number of elements being passed to G-sort-recurse is always a multiple of 3 to simplify the notation (and drop the floors/ceilings). Next (1 pts), Derive a recurrence for the algorithm's running time (or number of comparisons made). Finally (4 pts), obtain a good asymptotic upper bound (big-O) for your recurrence. 1. (10 pts) A grad student comes up with the following algorithm to sort an array A[1.n] that works by first sorting the first 2/3rds of the array, then sorting the last 2/3rds of the (resulting) array, and finally sorting the first 2/3rds of the new array. 1: function G-SORT(A, n) takes as input an array of n numbers, Al..n G-sort-recurse(A, 1, n) 3: end function function G-SORT-RECURSE(A, I, u) 4: 5: ifu_K0then D1 or fewer elements already sorted 2 elements D swap values return 7: else if uL 1 then temp Alu All temp end if 12: 13: 14: 15: 16: 17: 18: 19: 20: end functiorn else D 3 or more elements size u-1+1 twothirds- [(2 * size)/3] G-sort-recurse(A,L, l + twothirds - 1) G-sort-recurse(A, u twothirds +1,u) G-sort-recurse(A,e,e + twothirds - 1) end if First (5 pts), prove that the algorithm correctly sorts the numbers in the array (in increasing order) After showing that it correctly sorts 1 and 2 element intervals, you may make the (incorrect) assump- tion that the number of elements being passed to G-sort-recurse is always a multiple of 3 to simplify the notation (and drop the floors/ceilings). Next (1 pts), Derive a recurrence for the algorithm's running time (or number of comparisons made). Finally (4 pts), obtain a good asymptotic upper bound (big-O) for your recurrence

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

Students also viewed these Databases questions

Question

If 3,000 = 1,500 1.1n, what is the value of n?

Answered: 1 week ago

Question

6. Does your speech have a clear and logical structure?

Answered: 1 week ago