Package edu.neu.khoury.cs6510.f24.wp161
Class BinaryTree
java.lang.Object
edu.neu.khoury.cs6510.f24.wp161.BinaryTree
The BinaryTree class represents a binary tree, where each node has a left and right child.
The tree supports operations like checking if it's a binary search tree (BST),
calculating its maximum depth, and finding the maximum value within the tree.
-
Constructor Summary
ConstructorsConstructorDescriptionConstructs an empty binary tree (i.e., a tree with no nodes).BinaryTree(Node root) Constructs a binary tree with the specified root node. -
Method Summary
-
Constructor Details
-
BinaryTree
Constructs a binary tree with the specified root node.- Parameters:
root- the root node of the binary tree
-
BinaryTree
public BinaryTree()Constructs an empty binary tree (i.e., a tree with no nodes).
-
-
Method Details
-
getRoot
Returns the root node of the binary tree.- Returns:
- the root node of the tree, or null if the tree is empty
-
isBst
public boolean isBst()Checks if the binary tree is a binary search tree (BST). A binary search tree is a binary tree in which, for every node n, all nodes in the left subtree have values less than n's value, and all nodes in the right subtree have values greater than n's value.- Returns:
- true if the tree is a BST, false otherwise
-
getMaxDepth
Returns the maximum depth of the binary tree. The maximum depth is the longest path from the root node to a leaf node.- Returns:
- the maximum depth of the tree
-
getMaxValue
Returns the maximum value held in the binary tree.- Returns:
- the maximum integer value in the tree
- Throws:
IllegalStateException- if the tree is empty
-
equals
-
hashCode
public int hashCode()
-