IT 179, Fall 2015 Assignment 8, 45 points
Due: Nov. 30 (Monday) Note: This assignment is optional. If you decide to do it, your total score for programming assignments before normalization is 280, otherwise 235.
In this assignment, you will build Binary Search Trees according to the numbers read from a text file. You don’t have to use or create any external classes but build your own binary search trees inside your Asg8.java
for the required operations. Thus, you can ignore BinarySearchTree described in the Java document. You are completely free to construct your own binary trees using linked lists inside your program, Asg8.java
. Since the only data type needed in the binary tree is int , you don’t have to make your tree generic.
1. Make directory ∼ /IT179/Asg8/ and copy /home/cli2/public/IT179/numbers.txt
to it.
You will code Asg8.java
and run as: java Asg8 numbers.txt
where numbers.txt
is the input file in the current working directory. I may provide another input file with a full path to test your program.
2. Each line in numbers.txt
is a sequence of integers, n
0
, n
1
, n
2
, . . .
. For each such line, we will build up a binary search tree according to the following strategy.
(1) Start with an empty tree and try to insert numbers to it according to the order in the sequence, n
0
, n
1
, n
2
, . . .
.
(2) Let n i be the current number we try to insert. If n i is not in the binary search tree already, we insert n i
. On the other hand, if n i is already in the tree, instead of inserting n i again, we remove n i from the tree. Therefore, if a number appears even number of times in the sequence, it will not be in the tree at the end of the process, since it will be added, removed, . . .
, added, removed.
(3) After all numbers in the sequence are inserted/removed, print out all numbers in the binary search tree using preorder , inoder , and postorder traversal.
(4) Print out the size (the number of nodes) and the height of the tree. Also, print out the maximum and minimum numbers in the tree.
(5) Consider the first line in numbers.txt
, 5 4 3 7 8 4 3 1 3 . Your program should print out the results in the following format:
Prefix: 5 1 3 7 8
Infix: 1 3 5 7 8
Postfix: 3 1 8 7 5
Total: 5
Height: 3
Max: 8
Min: 1
As before, prepare your work in your secret directory according to the requirement (simply run the unix script copyasg.sh
. Check the description from the previous assignments.)
Due: Nov. 30 (Monday) c Chung-Chih Li P-1/1