solutionHW#1

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

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

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 o ff in the unlikely event that the data

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

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### What students are saying

• As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

Kiran Temple University Fox School of Business ‘17, Course Hero Intern

• I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

Dana University of Pennsylvania ‘17, Course Hero Intern

• The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

Jill Tulane University ‘16, Course Hero Intern