
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
Five problems from a computer science course, including analyzing the quicksort algorithm, determining the expected gain, variance, and standard deviation of a carnival game, and finding a constant for a recursive integer multiplication algorithm.
Typology: Assignments
1 / 1
This page cannot be seen from the preview
Don't miss anything!

Summer 2008 CMSC 351: Homework 6 Clyde Kruskal
Due at the start of class Wednesday, June 25, 2008.
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], 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. A carnival game consists of three dice in a cage. A player can bet a dollar on any of the numbers 1 through 6. The cage is shaken, and the payoff is as follows. If the player’s number doesn’t appear on any of the dice, he loses his dollar. Otherwise if his number appears on exactly k of the three dice, for k = 1, 2 , 3, he keeps his dollar and wins k more dollars.
(a) What is his expected gain from playing the carnival game once? (b) What is the variance from playing the carnival game once? (c) What is the standard deviation from playing the carnival game once? (d) What are his expected gain, variance, and standard deviation from playing the carnival game n times?
Problem 5. 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.