3/11/08

To Notes

CSC 212 -- 3/11/08

 

Review Questions

  1. Draw the recursion tree for Towers of Hanoi with three disks.

    Ans: Here is the solution.

  2. In what order does the FloodFill algorithm fill this region? The start point is x=5,y=5 and the fill order is left, down, right, up.

    Ans: If counting is in this order:

    and the fill order is this is the solution:

  3. Draw the family tree produced by this java code. What is the output?

    public static void main(String[ ] args)
    {
        Person p = new Person("R");
        p.addChild(new Person("M"));
        p.addChild(new Person("Q"));
        p.getChild(1).addChild(new Person("L"));
        p.getChild(1).getChild(0).addChild(new Person("Y"));
        p.addChild(new Person("A"));
        p.getChild(2).addChild(new Person("K"));
        p.getChild(1).addChild(new Person("X"));
        p.getChild(0).addChild(new Person("J"));
        p.getChild(0).addChild(new Person("W"));
        p.getChild(0).getChild(0).addChild(new Person("B"));
        p.getChild(0).getChild(1).addChild(new Person("U"));
        p.getChild(1).getChild(0).addChild(new Person("T"));
        System.out.println(p);
    }
    
    Ans: Indentation means child:
                           R
              ____________/|\_____________
             0|           1|            2|
              M            Q             A
            0/1\         0/1\           0| 
            /   \        /   \           |  
           J     W      L     X          K
           |     |     / \               
           B     U    Y   T
    
    Output: R M J B W U Q L Y T X A K, one letter per line.

 

The KnightsTour Example

 

Review for Final