Docsity

Assignment for Algorithms - Summer 2009 | CMSC 351, Assignments of Algorithms and Programming

Toggle sidebar
bg1
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 Afrom pto r
based on element A[s] (pโ‰คsโ‰คr), using exactly rโˆ’pcomparisons 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) = (4T(โŒˆn/2โŒ‰) + nif n > 1
0 if n= 1
Find at constant asuch that T(n) = an2+O(n). Justify your answer.

Partial preview of the text

Download Assignment for Algorithms - Summer 2009 | CMSC 351 and more Assignments Algorithms and Programming in PDF only on Docsity!

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.