{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

# final(4) - CS 373 U Final Exam Questions Spring 2004 Write...

This preview shows pages 1–2. Sign up to view the full content.

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 .... You’ve probably known how to solve this problem since CS 125, so make it more interesting, let’s 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

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

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### What students are saying

• As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

Kiran Temple University Fox School of Business ‘17, Course Hero Intern

• I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

Dana University of Pennsylvania ‘17, Course Hero Intern

• The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

Jill Tulane University ‘16, Course Hero Intern