{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

Quiz1 - Analysis of Algorithms CSE 5211 Fall 2010 Quiz 1...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
Analysis of Algorithms CSE 5211 Fall 2010 Quiz 1 Points 45 Intro to Analysis of Algorithms CSE 4081 Fall 2010 Quiz 1 Points 40 Time: 45 min Q1. The following recursive algorithm finds k -th largest element in an unsorted array A . Set up a recurrence equation for the algorithm’s asymptotic time complexity and solve it. You may presume that the pivot always gets in the middle. Algorithm QuickSelect (array A , i, j, k ) (1) Say, n = j-i+1; //length of A (2) If k > n then return “no answer”; (3) if n = = 1 then return A[i] as the answer; (4) pick a pivot from the array and QuickPartition the array; // as is done in QuickSort ) (5) L := A[i, n/2] and L includes the pivot; //left half (6) R := A[n/2 +1, j] ; //right half (7) if length (L) k then QuickSelect (L, i, n/2, k) (8) else QuickSelect (R, n/2 +1, j, k - size(L) -1); // previous call’s k-th element is k-|L|-1 in R End algorithm. T(n) = T(n/2)+O(n), or T(i)+T(n-i+1)+O(n) Soln from Master’s thm: T(n) is O(n) Q2. A chain of matrices have the following dimensions: A1 (2x3), A2 (3x1), A3 (1x4), A4 (4x6).
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}