CIS 110 Spring 2013 - Introduction to Computer Programming

upenn.edu | directories | van pelt library
seas.upenn.edu | CETS | engineering library
computer graphics & game dev (SIGGRAPH @ Penn) | dining philosophers (DP) | science & tech wing (STWING) | women in cs (WICS)
CETS Answers

Recitation 10 Exercises

Goals

The goals of this week's recitation assignments are to about Graph data structures and Depth First Search.

Exercises

  • Many things in life, the universe and the internet can be thought of as graph problems. Think of three systems that can be expressed as graphs. Write down what the nodes and edges would be, and what you would gain by expressing the system as a graph.
  • Remember the movie Pay it Forward? You do good things for three random people, and in return they each have to do good things for three different people. And so it keeps going. In our problem you're an even better person than Haley Joel Osment and help an arbitrary number of people. Assume you have a linked list of all the people you've helped. Assuming they each pay it forward (again, to an arbitrary number of people), write a function that returns the sum of all the people you have helped if only the people you've helped have helped other people. Use the Node class below to represent each person.
    public class Node
    ----------------
    public String name
    public Node people     // list of people this node has helped
    public Node next       // next person in list of people
    
  • What is the difference between a graph and a Linked List?