JavaAlgorithms
Elementary and no so elementary Java algorithms
treeAlgorithms.LeastCommonAncestor< T extends Comparable< T > > Class Reference

List of all members.

Public Member Functions

TreeNode< T > findLCA (TreeNode< T > root, T valLess, T valGT)

Detailed Description

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

Author:
Ian Kaplan, iank@bearcave.com
Parameters:
<T>The type for the TreeNode. This type must implement the Comparable interface.

Definition at line 32 of file LeastCommonAncestor.java.


Member Function Documentation

TreeNode<T> treeAlgorithms.LeastCommonAncestor< T extends Comparable< T > >.findLCA ( TreeNode< T >  root,
valLess,
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.

Parameters:
rootthe tree root
valLess
valGT
Returns:
the node that is the least common ancestor

Definition at line 45 of file LeastCommonAncestor.java.


The documentation for this class was generated from the following file:
 All Classes Namespaces Files Functions Variables