{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

# hw1(1) - CS 373 Combinatorial Algorithms Fall 2000 Homework...

This preview shows pages 1–3. Sign up to view the full content.

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

View Full Document
CS 373 Homework 1 (due 9/12/00) Fall 2000 2. Consider the following sorting algorithm: S TUPID S ORT ( A [0 .. n 1]) : if n = 2 and A [0] > A [1] swap A [0] A [1] else if n > 2 m ←⌈ 2 n/ 3 S TUPID S ORT ( A [0 .. m 1]) S TUPID S ORT ( A [ n m .. n 1]) S TUPID S ORT ( A [0 .. m 1]) (a) Prove that S TUPID S ORT actually sorts its input. (b) Would the algorithm still sort correctly if we replaced the line m ←⌈ 2 n/ 3 with m ←⌊ 2 n/ 3 ? Justify your answer. (c) State a recurrence (including the base case(s)) for the number of comparisons executed by S TUPID S ORT . (d) Solve the recurrence, and prove that your solution is correct. [Hint: Ignore the ceiling.] Does the algorithm deserve its name? (e) Show that the number of swaps executed by S TUPID S ORT is at most ( n 2 ) . 3. The following randomized algorithm selects the r th smallest element in an unsorted array A [1 .. n ] . For example, to find the smallest element, you would call R ANDOM S ELECT ( A, 1) ; to find the median element, you would call R ANDOM S ELECT ( A, n/ 2 ) . Recall from lecture that P ARTITION splits the array into three parts by comparing the pivot element A [ p ]
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### Page1 / 6

hw1(1) - CS 373 Combinatorial Algorithms Fall 2000 Homework...

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

View Full Document
Ask a homework question - tutors are online