Lab 9: Trees
CS 241: Data Structures, Fall 2007


Due Date: class on Monday Nov 19

Goals for this assignment are to:

Reading

Read Chapter 10 and Chapter section 11.3.

Directions

  1. Do 10.3 (p. 265). We will go over the solution in class.

  2. In class, we began the implementation of a binary search tree for storing integers. This code will be placed on the \\home\classes drive in the folder gorr\cs241Fa07. The skeleton code (before in-class modifications) can be found here (zip).

    Your job is to complete the Node class so that it can do all the different traversals as well as print the tree structure. Use recursion wherever possible. You should be able to do each of the items below.

    1. Clear to begin a new tree (this is done in the frame class).
    2. Insert a random value into the tree.
    3. Insert a specific value that the user enters in the textfield.
    4. Print the node items in sorted order (in-order traversal) using recursion.
    5. Print the node items in pre-order order using recursion.
    6. Print the node items in level-order (i.e. breadth first search) - use iteration not recursion. You will also need a queue of some sort. An ArrayList actually works well.
    7. Print the node items using parenthesis as described in class using recursion.
    8. Print the node items as a tree structure on it's side as discussed in class using recursion.
    9. Print out the height of the tree using recursion.
    10. Search to see if a node item, entered by the user, is in the tree.
    11. Extra credit (2 pts) - remove a node specified by user. This is tricky and is best done using iteration rather than recursion.
    12. Extra credit (2 pts)- do a graphical picture of your binary tree where each node is in its own column.

    Note: extra credit will only be given if the regular part of the lab is complete.

  3. The code for the TicTacToe game is available here (zip).

    1. Note that the player can put an O in a location that is not empty. Fix this.
    2. Add code so that the player can quit playing instead of entering a row number.
    3. Do problem 10.23 (p. 282).

Evaluation

By no later than class on Monday Nov 19, you should zip together both projects, including a jar files, and email the code as an attachment to gorr@willamette.edu. Place CS241 Lab 9 in the subject line.

Demonstrate your binary tree program and tic-tac-toe program by Thursday Nov 22.


[top]  [Schedule]  [Home]