CS112_47_StanfordFinal

# CS112_47_StanfordFinal - Handout#52 CS106B Practice Final...

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

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

View Full Document
2 Problem 1: Recursion (25 points) Suppose you are having your classmates from a seminar over to dinner, and you want to decide how to seat them around your round dining room table. Luckily, the table seats exactly the right number of people, but you realize that not all of them are friends. You decide that the best approach is to try to position people so that everyone is a friend of both their neighbors. You quickly write a function that tells you whether any two people are friends, but you still wonder how to use that to come up with an arrangement that will work. Then it dawns on you—recursion will save the day! You can write a recursive function that will tell you if an acceptable arrangement is possible. Certainly the problem seems to have a recursive nature: each time you decide where to place someone at the table you are left with a problem that is similar to the original (find acceptable places for some guests), but simpler (there is one fewer guest to deal with). Your job in this problem is to write the function that determines whether an acceptable placement exists. Just to be sure you understand the problem, here is a possible seating of six people:
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### Page1 / 13

CS112_47_StanfordFinal - Handout#52 CS106B Practice Final...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online