This question considers binary trees using the following node class. You may not assume that the tree has any method or additional fields. class Node { } String key; Node left, right; Node root%; // the root of the tree Recall that the height of a node x is the maximum of the number nodes between x and a null link. By definition, the height of a leaf is 0, and therefore the height of the empty tree is -1. (a) Implement a method height which returns the height of the tree, starting from the root. public int height () {
This question considers binary trees using the following node class. You may not assume that the tree has any method or additional fields. class Node { } String key; Node left, right; Node root%; // the root of the tree Recall that the height of a node x is the maximum of the number nodes between x and a null link. By definition, the height of a leaf is 0, and therefore the height of the empty tree is -1. (a) Implement a method height which returns the height of the tree, starting from the root. public int height () {
Related questions
Question

Transcribed Image Text:This question considers binary trees using the following node class. You may not assume that the tree has
any method or additional fields.
class Node {
}
String key;
Node left, right;
Node root%; // the root of the tree
Recall that the height of a node x is the maximum of the number nodes between x and a null link. By
definition, the height of a leaf is 0, and therefore the height of the empty tree is -1.
(a) Implement a method height which returns the height of the tree, starting from the root.
public int height () {
Expert Solution

This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
Step by step
Solved in 2 steps
