CS4311 Design and Analysis of Algorithms
Homework 3
Due: 11:10 am, May 8, 2008 (before class)
1. (20%) There is a staircase with
n
steps. Your friend, Jack, wants to count how many
diﬀerent ways he can walk up this staircase. Because John is quite tall, in one move, he
can choose either to walk up 1 step, 2 steps, or 3 steps.
Let
F
k
denote the number of ways John can walk up a staircase with
k
steps. So,
F
1
= 1,
F
2
= 2,
F
3
= 4, and
F
4
= 7.
Derive a recurrence for
F
k
, and show that
F
n
can be computed in
O
(
n
) time.
2. Consider the following coin-taking game between Tom and Jerry. We start with two piles
of coins, with
x
coins in the ﬁrst pile and
y
coins in the second pile. They will take turn to
remove coins from the pile. In each turn, they have three options: (i) remove any number
of coins from the ﬁrst pile, (ii) remove any number of coins from the second pile, or (iii)
remove the
same
number of coins from both piles.
In this game, the person loses if he cannot get any coin during his turn. For instance,
suppose it is Tom’s turn, and the coins in the current piles are (
x,y
) = (5
,
5). In this case,
if Tom now removes coins using the third option, he can make the piles (0
,
0) so that Jerry
loses by not getting any coin in his next turn.
If both Tom and Jerry plays cleverly, some combinations of (
x,y
) are always losing. For
instance, (0
,
0) is a losing combination, and we can also show that (1
,
2) is a losing combi-
nation as follows:
•
Firstly, there are only 4 ways of removing the coins: (1) take 1 coin from pile 1; (2)