Preview

Solu2

Good Essays
Open Document
Open Document
11506 Words
Grammar
Grammar
Plagiarism
Plagiarism
Writing
Writing
Score
Score
Solu2
This file 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. For 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 different for inputs of the same size:
a. computing the sum of n numbers
b. computing n!
c. finding 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 definition-based algorithm for adding two n-by-n matrices. 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 definition-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 differ 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

You May Also Find These Documents Helpful