CS112_47_StanfordFinal - Handout#52 CS106B Practice Final...

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

View Full Document Right Arrow Icon
Handout #52 Spring 2002 May 22, 2002 Robert Plummer Practice Final Note: this practice exam is the actual exam from last quarter. A second practice exam will be available in electronic form from the class website some time later. We have removed some of the blank space for answers in order to save some trees. Solutions to both practice exams will be posted on Friday May 31 st . General instructions Answer each of the questions given on the following pages. Write all of your answers directly on the examination paper, including any work that you wish to be considered for partial credit. Each question is marked with the number of points assigned to that question. You should budget your time carefully. In all questions, you may use functions or definitions that have been used in the course, and any standard C functions. You do NOT have to provide #include statements or citations for the functions you use, but it is your responsibility to use them correctly. Comments are not required on the exam. Uncommented code that gets the job done will be sufficient for full credit on the problem. On the other hand, comments may help you to get partial credit on a problem if they help us determine what you were trying to do. The examination is open-book, and you may make use of any texts, handouts, or course notes. You may not, however, use a computer of any kind. I accept the letter and spirit of the honor code— I have not given or received aid on this exam. Name (signed) __________________________________________________________ Score Grader 1. Recursion (25) ______ ______ 2. Function pointers, mapping, iteration (25) ______ ______ 3. Trees (30) ______ ______ 4. Graphs (20) ______ ______ Total (100) ______ CS106B
Background image of page 1

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

View Full Document Right Arrow Icon
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:
Background image of page 2
Image of page 3
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 Right Arrow Icon
Ask a homework question - tutors are online