CMSC 351 Homework 7: Problems on Sums, Carnival Games, and Bubble Sort - Prof. Clyde P. Kr, Assignments of Algorithms and Programming

Four problems from a university-level computer science course, cmsc 351, homework 7. The problems involve calculating the sum of a sequence using non-integral methods and integrals, analyzing the expected gain, variance, and standard deviation of a carnival game, and finding the expected number of exchanges and comparisons in the bubble sort algorithm for different input distributions.

Typology: Assignments

Pre 2010

Uploaded on 07/29/2009

koofers-user-c4f
koofers-user-c4f šŸ‡ŗšŸ‡ø

9 documents

1 / 1

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Summer 2009 CMSC 351: Homework 7 Clyde Kruskal
Due at the start of class, Friday, June 26.
Problem 1. For this problem you may use a calculator for a few calculations.
Consider P100
k=1 k3/2.
(a) Use a non-integral method to show that the sum is between 15,000 and 70,000.
(b) Approximate the sum using integrals. Make sure to get an upper and lower
bound.
Problem 2. 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 kof the three dice, for k= 1,2,3, he keeps his dollar
and wins kmore 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 ntimes?
Problem 3. Consider the bubble-sort algorithm, for an input (a b c) of the three integer
values 1, 2, and 3 in any order, where all input orders are equally likely (uniform
distribution).
(a) Let Mbe the number of exchanges. What are E(M), Var(M), and σ(M)?
(b) Let xbe the number of comparisons. What are E(M), Var(M), and σ(M)?
(c) What p ercentage of the sample space is within a standard deviation of average.
Problem 4. Again consider the bubble-sort algorithm, for an input (a b c) of the three
integer values 1, 2, and 3 in any order. But now suppose the input orders are not
equally likely; instead, there is a 1/5 chance of a= 1 being the first item in the input
(the 1/5 distributed equally among those inputs) and 4/5 of anot being 1 (again the
4/5 shared equally among all these inputs).
(a) Let Mbe the number of exchanges. What are E(M), Var(M), and σ(M)?
(b) Let xbe the number of data comparisons made. What are E(M), Var(M), and
σ(M)?
(c) What p ercentage of the sample space is within a standard deviation of average.

Partial preview of the text

Download CMSC 351 Homework 7: Problems on Sums, Carnival Games, and Bubble Sort - Prof. Clyde P. Kr and more Assignments Algorithms and Programming in PDF only on Docsity!

Summer 2009 CMSC 351: Homework 7 Clyde Kruskal

Due at the start of class, Friday, June 26.

Problem 1. For this problem you may use a calculator for a few calculations.

Consider

āˆ‘ 100 k=1 k

(a) Use a non-integral method to show that the sum is between 15,000 and 70,000. (b) Approximate the sum using integrals. Make sure to get an upper and lower bound.

Problem 2. 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 3. Consider the bubble-sort algorithm, for an input (a b c) of the three integer values 1, 2, and 3 in any order, where all input orders are equally likely (uniform distribution).

(a) Let M be the number of exchanges. What are E(M ), Var(M ), and σ(M )? (b) Let x be the number of comparisons. What are E(M ), Var(M ), and σ(M )? (c) What percentage of the sample space is within a standard deviation of average.

Problem 4. Again consider the bubble-sort algorithm, for an input (a b c) of the three integer values 1, 2, and 3 in any order. But now suppose the input orders are not equally likely; instead, there is a 1/5 chance of a = 1 being the first item in the input (the 1/5 distributed equally among those inputs) and 4/5 of a not being 1 (again the 4 /5 shared equally among all these inputs).

(a) Let M be the number of exchanges. What are E(M ), Var(M), and σ(M )? (b) Let x be the number of data comparisons made. What are E(M ), Var(M ), and σ(M )? (c) What percentage of the sample space is within a standard deviation of average.