Last updated
: November 19, 2009.
Test Cases
Tree Drawing
Tree Traversal
Heaps
This assignment consists of three programming problems.
1. Tree Drawing
We can draw a binary tree T with an algorithm that assigns x- and y-coordinates to a node v of T using the
following two rules:
•
x(v) is the number of nodes visited before v in the inorder traversal of T.
•
y(v) is the depth of v in T.
In this application, we take the convention common in computer graphics that x-coordinates increase left to
right and y-coordinates increase top to bottom. So the origin (0,0) is in the upper left corner of the computer
screen.
For example, given the following binary tree, the (x,y) coordinates of the nodes are A(0,2), B(1,1), C(2,3),
D(3,2), E(4,3), F(5,0), G(6,1), H(7,3), I(8,2).
In this problem, binary trees are implemented using linked structure. The tree nodes are extended to include
two new fields, x and y, which record the x- and y-coordinates of each node, respectively.
Your task is to write a public method computeXY( ) in file DrawableBinaryTree.java that computes and
records the x- and y-coordinates of every node in the tree.
Complete method computeXY( ) in file
DrawableBinaryTree.java
. You will need to submit only file
DrawableBinaryTree.java.
This is