Lab 9: Trees
CS 241: Data Structures,
Fall 2007
Due Date: class on Monday Nov 19
Goals for this assignment are to:
- Learn basic binary tree operations.
- Learn about simple game trees.
Reading
Read Chapter 10 and Chapter section 11.3.
Directions
Do 10.3 (p. 265). We will go over the solution in class.
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.
- Clear to begin a new tree (this is done in the frame class).
- Insert a random value into the tree.
- Insert a specific value that the user enters in the textfield.
- Print the node items in sorted order (in-order traversal) using recursion.
- Print the node items in pre-order order using recursion.
- 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.
- Print the node items using parenthesis as described in class using recursion.
- Print the node items as a tree structure on it's side as discussed in class using recursion.
- Print out the height of the tree using recursion.
- Search to see if a node item, entered by the user, is in the tree.
- Extra credit (2 pts) - remove a node specified by user. This is tricky and is best done using
iteration rather than recursion.
- 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.
The code for the TicTacToe game is available here (zip).
- Note that the player can put an O in a location that is not empty. Fix this.
- Add code so that the player can quit playing instead of entering a row number.
- 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]