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

Material Type: Assignment; Professor: Kruskal; Class: Algorithms; Subject: Computer Science; University: University of Maryland; Term: Summer I 2009;

Typology: Assignments

Pre 2010

Uploaded on 07/30/2009

koofers-user-atz-1
koofers-user-atz-1 🇺🇸

10 documents

1 / 1

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

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] (psr), using exactly rpcomparisons and rp+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.