
Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Material Type: Assignment; Professor: Kruskal; Class: Algorithms; Subject: Computer Science; University: University of Maryland; Term: Summer I 2009;
Typology: Assignments
1 / 1
This page cannot be seen from the preview
Don't miss anything!

Summer 2009 CMSC 351: Homework 6 Clyde Kruskal
Due at the start of class Wednesday, June 24, 2009.
Problem 1. Consider an array of size eight with the numbers 50, 70 , 10 , 20 , 60 , 40 , 80 , 30. Assume you execute quicksort using the version of partition from CLRS.
(a) What is the array after the first partition. How many comparisons did you use? How many exchanges? (b) Show the left side after the next partition. How many comparisons did you use? How many exchanges? (c) Show the right side after the next partition on that side. How many comparisons did you use? How many exchanges? (d) What is the total number of comparisons in the entire algorithm? What is the total number of exchanges in the entire algorithm?
Problem 2. Assume you execute quicksort using the version of partition from CLRS.
(a) What is the fewest exchanges that the algorithm will execute for an input of size n. (b) Give an example with n = 8.
Problem 3. Write an algorithm Partition(A,p,r,s) to partition array A from p to r based on element A[s] (p ≤ s ≤ r), using exactly r − p comparisons and r − p + O(1) moves. The element A[s] should end up in its proper sorted location after partitioning.
Problem 4. Challenge problem. Consider the following recurrence that basically occurs from one of the recursive integer multiplication algorithms:
T (n) =
{ 4 T (⌈n/ 2 ⌉) + n if n > 1 0 if n = 1
Find at constant a such that T (n) = an^2 + O(n). Justify your answer.