This preview shows pages 1–2. Sign up to view the full content.
This preview has intentionally blurred sections. Sign up to view the full version.View Full Document
Unformatted text preview: CS 373 U Final Exam Questions (May 11, 2004) Spring 2004 Write your answers in the separate answer booklet. 1. In the well-known Tower of Hanoi problem, we have three spikes, one of which has a tower of n disks of different sizes, stacked with smaller disks on top of larger ones. In a single step, we are allowed to take the top disk on any spike and move it to the top of another spike. We are never allowed to place a larger disk on top of a smaller one. Our goal is to move all the disks from one spike to another. Hmmm.... Youve probably known how to solve this problem since CS 125, so make it more interesting, lets add another constraint: The three spikes are arranged in a row, and we are also forbidden to move a disk directly from the left spike to the right spike or vice versa. In other words, we must move a disk either to or from the middle spike at every step. 1 2 3 4 The first four steps required to move the disks from the left spike to the right spike. (a) [4 pts] Describe an algorithm that moves the stack of n disks from the left needle to the right needle in as few steps as possible. (b) [6 pts] Exactly how many steps does your algorithm take to move all n disks? A correct -bound is worth 3 points. [Hint: Set up and solve a recurrence.] 2. Consider a random walk on a path with vertices numbered 1 , 2 , . . . , n from left to right. At each step, we flip a coin to decide which direction to walk, moving one step left or one step right with equal probability. The random walk ends when we fall off one end of the path, either by moving left from vertex 1 or by moving right from vertex n . In Midterm 2, you were asked to prove that if we start at vertex 1, the probability that the walk ends by falling...
View Full Document
- Spring '11