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)
Background image of page 1

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

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

This note was uploaded on 02/10/2012 for the course CSE 5211 taught by Professor Dmitra during the Spring '12 term at FIT.

Page1 / 2

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

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online