Lesson AB30 - Binary Search Trees |
|
|
TreeStats Background: The height of a binary tree is defined as the number of nodes in the longest path from the root to a leaf of the tree. The heights of the trees above are 5 for Tree 1, and 6 for Tree 2. The width of a binary tree is the number of nodes in the longest path in the tree. The width of an empty tree is 0, and the width of a single-node tree is 1. The width of Tree 1 is 8 (symbolized by the darkened nodes) and the width of Tree 2 is 9. The longest path may or may not include the root node. In general, the width of an empty tree is 0, and the width of a nonempty tree is the maximum of the following three quantities:
When writing these two methods (height and width), you may find it useful to use the
Assignment:
Instructions:
|
|