Devise an algorithm to compute the height of a tree.
Write an implementation of your algorithm
as the getHeight method of the abstract Tree class
introduced in Program .
Devise an algorithm to count the number of internal nodes in a tree.
Write an implementation of your algorithm
as the getCount method of the AbstractTree class
introduced in Program .
Devise an algorithm to count the number of leaves in a tree.
Write an implementation of your algorithm
as a method of the AbstractTree class
introduced in Program .
Devise an abstract (generic) algorithm to compare trees.
(See Exercise ).
Write an implementation of your algorithm
as the _compareTo method of the abstract Tree class
introduced in Program .
The Iterator class introduced in Program
does a preorder traversal of a tree.
Write an iterator class that does
a postorder traversal.
Write an iterator class that does
a breadth-first traversal.
Write an iterator class that does
an inorder traversal.
(In this case,
assume that the tree is a BinaryTree).
Complete the GeneralTree class
introduced in Program
by providing suitable definitions for the following operations:
getIsEmpty, getIsLeaf, getDegree,
and _compareTo.
Write a test program and test your implementation.
Complete the NaryTree class
introduced in Program
by providing suitable definitions for the following operations:
getIsLeaf, getDegree, and _compareTo.
Write a test program and test your implementation.
Complete the BinaryTree class
introduced in Program
by providing suitable definitions for the following operations:
getIsEmpty, getIsLeaf, getDegree,
getKey, attachKey, detachKey,
attachLeft, detachLeft,
attachRight, detachRight,
and getSubtree.
Write a test program and test your implementation.
Write a visitor that draws a picture of a tree on the screen.
Design and implement an algorithm that constructs an expression tree
from an infix expression such as