JavaAlgorithms
Elementary and no so elementary Java algorithms
|
Public Member Functions | |
TreeNode< T > | findLCA (TreeNode< T > root, T valLess, T valGT) |
LeastCommonAncestor
Given a ordered binary tree and two values that exist in the tree, find their least common ancestor. The least common ancestor is the ancestor tree node with the least value.
In the tree we assume that the left node is less and the right node is greater.
Jun 15, 2013
<T> | The type for the TreeNode. This type must implement the Comparable interface. |
Definition at line 32 of file LeastCommonAncestor.java.
TreeNode<T> treeAlgorithms.LeastCommonAncestor< T extends Comparable< T > >.findLCA | ( | TreeNode< T > | root, |
T | valLess, | ||
T | valGT | ||
) |
Find the ancestor node in the tree such that valLess <= root.getValue() <= valGT, where valLess < valGT. If valLess and ValGT exist in the tree, then such a node must exist.
root | the tree root |
valLess | |
valGT |
Definition at line 45 of file LeastCommonAncestor.java.