solutionHW#1 - CMPSC 465 SOLUTIONS TO ASSIGNMENT 1 This...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
CMPSC 465 SOLUTIONS TO ASSIGNMENT 1 Spring 2008 This assignment is worth a total of 50 points. 1. [5 points: 1 point for each number in answer] Exercise 2.1.4 on page 51. a. The best case is 2 (you pick two gloves that match). The worst case is 12 (you pick 5 red gloves of the same handedness, 4 yellow, and 2 green, and you still have to pick one more glove to have a matching pair). Note that the hint for 2.1.4.a on page 500 of the text is particularly helpful. b. There are ( 10 2 ) = 45 equally-likely choices for the two missing socks. In 5 of these, they form a matched pair (the best case); in the remaining 40 they don’t (the worst case). So the probability of the best case is 5/45 = 1/9 and the probability of the worst case is 8/9 . The average number of pairs is 4 × 1 9 + 3 × 8 9 = 3 1 9 . 2. [5 points] Exercise 2.1.6 on page 51. Begin by making n - 1 comparisons to see if the data is already in order. If it is, stop; otherwise, run the original algorithm. [4 points] This is not a desirable addition to a sorting method since it only pays oF in the unlikely event that the data is already completely sorted, while it results in wasted eFort in every other case. [1 point]
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 03/17/2008 for the course CMPSC 465 taught by Professor Burchardcharles during the Spring '08 term at Pennsylvania State University, University Park.

Page1 / 2

solutionHW#1 - CMPSC 465 SOLUTIONS TO ASSIGNMENT 1 This...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online