1. Engineering
  2. Computer Science
  3. 1 10 pts a grad student comes up with the...

Question: 1 10 pts a grad student comes up with the...

Question details

1. (10 pts) A grad student comes up with the following algorithm to sort an array A1..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 Dtakes as input an array of n numbers, A1..n] 1: function G-SORT(A, n) 2: G-sort-recurse(A, 1, n) 3: end function 4: function G-SORT-RECURSE(A, L, u) 5: if u - l< 0then D 1 or fewer elements already sorted D 2 elements swap values return 7: else if u-1 then if Aluj < A[] then temp ← A[u] 9: 10: end if 12: 13: else 14 15: 16 17 18: 19 end if 20: end function D3 or more elements sizeu -+1 twothirds(2 size)/3] G-sort-recurse(A, u, u twothirds 1) G-sort-recurse(A,-twothirds, l) G-sort-recurse(A, u, u twothirds - 1) 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 algorithms running time (or number of comparisons made) Finally (4 pts), obtain a good asymptotic upper bound (big-O) for your recurrence

Solution by an expert tutor
Blurred Solution
This question has been solved
Subscribe to see this solution