Class ExtendedBST

java.lang.Object
  extended byintroExam.BinarySearchTree.BST
      extended byExtendedBST

public class ExtendedBST
extends BST

These methods are the candidates for the BST question


Nested Class Summary
 
Nested classes inherited from class introExam.BinarySearchTree.BST
BST.BSTNode
 
Field Summary
 
Fields inherited from class introExam.BinarySearchTree.BST
root
 
Constructor Summary
ExtendedBST()
           
 
Method Summary
 int balancedFactorOfNode(java.lang.Comparable value)
          This method returns balanced factor of a given node with value If the node does not exists, return -1 Balanced Factor is defined as the absolute value of the difference in heights between left and right subtrees of the node.
 ExtendedBST cloneTree()
          Creates and returns an exact copy of the tree.
 boolean isPerfect()
          Returns true if, and only if, all leaves of the tree are at the same level (are the same distance from the root) and the tree has the maximum number of nodes for its depth (each node has exactly 0 or two children), and false otherwise.
 int maxLeafLevel()
          Returns the level of the leaf that is farthest from the top (root) of the tree.
 int minLeafLevel()
          Returns the level of the leaf that is closest to the top (root) of the tree.
 void printLeavesAtLevel(int level)
          Prints to the console a list of all items organized at the specified level of the tree.
 void printPath(java.lang.Comparable keyValue)
          Prints the value at each node between and including the root and the supplied keyValue.
 
Methods inherited from class introExam.BinarySearchTree.BST
insert, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ExtendedBST

public ExtendedBST()
Method Detail

cloneTree

public ExtendedBST cloneTree()
Creates and returns an exact copy of the tree. This copy organizes the same items and has the same structure. It does not duplicate the reference data stored within each Node. Instead, it duplicate only the tree and the nodes it contains

This method does not change any of the items or the structure of the original tree.

In the event of an error, it returns null.

Returns:
an exact copy of the tree. This copy organizes the same items and has the same structure.

minLeafLevel

public int minLeafLevel()
Returns the level of the leaf that is closest to the top (root) of the tree.

The root is considered to be at level 0.

This method does not change any of the items or the structure of the original tree.

In the event of an error, it returns -1

Returns:
the level of the leaf that is closest to the top (root) of the tree.

maxLeafLevel

public int maxLeafLevel()
Returns the level of the leaf that is farthest from the top (root) of the tree.

The root is considered to be at level 0.

This method does not change any of the items or the structure of the original tree.

In the event of an error, it returns -1

Returns:
the level of the leaf that is farthest from the top (root) of the tree.

isPerfect

public boolean isPerfect()
Returns true if, and only if, all leaves of the tree are at the same level (are the same distance from the root) and the tree has the maximum number of nodes for its depth (each node has exactly 0 or two children), and false otherwise.

This method does not change any of the items or the structure of the original tree.

In the event of an error, it returns false

Returns:
true if, and only if, all leaves of the tree are at the same level (are the same distance from the root) and the tree has the maximum number of nodes for its depth (each node has exactly 0 or two children), and false otherwise.

printPath

public void printPath(java.lang.Comparable keyValue)
Prints the value at each node between and including the root and the supplied keyValue. If keyValue is not present in the tree, nothing is printed.

This method does not change any of the items or the structure of the original tree.

It can print the nodes in any order, but cannot use a collection class.


printLeavesAtLevel

public void printLeavesAtLevel(int level)
Prints to the console a list of all items organized at the specified level of the tree. If level greater than the height of the tree or no leaves at the given level, nothing is printed. For negative heights print nothing

This method does not change any of the items or the structure of the original tree.

It can print all the nodes at the specified level


balancedFactorOfNode

public int balancedFactorOfNode(java.lang.Comparable value)
This method returns balanced factor of a given node with value If the node does not exists, return -1 Balanced Factor is defined as the absolute value of the difference in heights between left and right subtrees of the node.

This method does not change any of the items or the structure of the original tree.

Print the absolute value of the differences between heights of left and right subtrees. If the node does not exists, return -1