solu2 - This le contains the exercises, hints, and...

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

View Full Document Right Arrow Icon
This fle contains the exercises, hints, and solutions For Chapter 2 oF the book ”Introduction to the Design and Analysis oF Algorithms,” 2nd edition, by A. Levitin. The problems that might be challenging For at least some students are marked by ± ; those that might be difficult For a majority oF students are marked by ² . Exercises 2.1 1. ±or each oF the Following algorithms, indicate (i) a natural size metric For its inputs; (ii) its basic operation; (iii) whether the basic operation count can be di²erent For inputs oF the same size: a. computing the sum oF n numbers b. computing n ! c. fnding the largest element in a list oF n numbers d. Euclid’s algorithm e. sieve oF Eratosthenes F. pen-and-pencil algorithm For multiplying two n -digit decimal integers 2. a. Consider the defnition-based algorithm For adding two n -by- n matri- ces. What is its basic operation? How many times is it perFormed as a Function oF the matrix order n ? As a Function oF the total number oF elements in the input matrices? b. Answer the same questions For the defnition-based algorithm For matrix multiplication. 3. Consider a variation oF sequential search that scans a list to return the number oF occurrences oF a given search key in the list. Will its efficiency di²er From the efficiency oF classic sequential search? 4. a. Glove selection There are 22 gloves in a drawer: 5 pairs oF red gloves, 4 pairs oF yellow, and 2 pairs oF green. You select the gloves in the dark and can check them only aFter a selection has been made. What is the smallest number oF gloves you need to select to have at least one matching pair in the best case? in the worst case? (aFter [Mos01], #18) b. Missing socks Imagine that aFter washing 5 distinct pairs oF socks, you discover that two socks are missing. OF course, you would like to have the largest number oF complete pairs remaining. Thus, you are leFt with 4 complete pairs in the best-case scenario and with 3 complete pairs in the worst case. Assuming that the probability oF disappearance For each 1
Background image of page 1

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

View Full DocumentRight Arrow Icon
of the 10 socks is the same, Fnd the probability of the best-case scenario; the probability of the worst-case scenario; the number of pairs you should expect in the average case. (after [Mos01], #48) 5. a. ± Prove formula (2.1) for the number of bits in the binary representation of a positive integer. b. What would be the analogous formula for the number of decimal digits? c. Explain why, within the accepted analysis framework, it does not mat- ter whether we use binary or decimal digits in measuring n ’s size. 6. Suggest how any sorting algorithm can be augmented in a way to make the best-case count of its key comparisons equal to just n 1 ( n is a list’s size, of course). Do you think it would be a worthwhile addition to any sorting algorithm?
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 04/28/2010 for the course CS CSE taught by Professor Drt during the Spring '10 term at Kaplan University.

Page1 / 51

solu2 - This le contains the exercises, hints, and...

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

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