Review sheet for test 3

advertisement
EECS 210
Review for Test 3
Fall 2011
Here’s a review sheet for test 3. As usual it’s not necessarily designed to be all inclusive. I
did not include any big-O or big- proofs since they appear in the notes on the web. Go back
through your discussion worksheets and homework while preparing for the test. Also, look at
the discussion notes for examples done during the discussions. The test is Wednesday,
November 30 at 5:45 p.m. in 1131 Learned.
Some of the counting questions in this review sheet may cover material beyond that covered
in class. Use those questions in preparing for the final.
1. Program A uses one second on 30 data items and has complexity c•n 2 for n items. How
many seconds would the program take for 50 data items? Leave your answer as a
fraction in lowest terms.
2. How many times is the assignment statement in the while loop executed?
in
while i  1 do
i  i/2
3. Solve each of the following recurrence relations. Be sure to show the entire solution,
including summations, if appropriate, before computing the sum. Use backward
substitution.
a. f(n) = 3f(n/3) + n and f(1) = 1 Assume n = 3k
b. an = 3an-1 + 3 and a0 = 1. Use backward substitution.
4. An ice cream parlor offers 6 toppings for its sundaes. A customer can choose as many or
as few of the toppings as desired. If you eat one sundae each Sunday, how many
Sundays will it take to try each topping combination. (At least one topping must be used.)
5. Using the standard alphabet and allowing repetition of letters, find the number of words
of length 8 that are palindromes.
6. If C(n, 8) = C(n, 5) then n = _____________
7. Matching exactly three white balls in the powerball lottery wins a prize. How many
powerball tickets are there for which exactly three white balls (and not the powerball) are
matched?
8. Consider the set of bit strings of length 10. How many
a. contain exactly three 0's?
b. begin or end with 0
c. contain at least two 0's?
9. How many three-digit numbers are there in which the sum of the digits is even?
10. A group of n men and n women are arranged in a row. The number of arrangements with
a. the men and women in any order is _______
b. the men and women in alternate places is
c. The men occupying n consecutive seats
11. A test has two parts. Part 1 has 6 questions and part 2 has 4. A student must answer a
total of 6 questions with at least two from each part. In how many ways can the questions
that are answered be selected?
12. A coin is tossed eight times. An outcome is string of 8 made up of H’s and T’s.
a. How many outcomes have a head (H) on the fifth toss?
b. How many outcomes have equal numbers of heads and tails?
13. A class contains 30 students--10 freshmen, 12 sophomores and 8 juniors.
a. The number of committees with exactly one person from each class is
b. The number of ways to arrange the students in a line so that all the freshmen are
together at the front of the line is
14. Consider 5-card hands selected from a deck of 52 cards. How many hands
a. have no face cards (Aces are not face cards)?
b. have only face cards?
c. have three cards of one suit and one each of two other suits?
15. Write a pseudocode algorithm that returns the index of the first item that is greater than its
predecessor in the array[a1, a2, ..an]. Output 0 if the numbers are in nonincreasing order.
Give the number of comparisons made in the best and worst cases.
16. Write a nonrecursive pseudocode algorithm to compute the following sum:
1 + 1•2 + 1•2•3 + … + 1•2•…•n. How many multiplications does your algorithm perform?
What is its big-O complexity? Explain how you got your answers.
Download