The lowest common ancestor (LCA) is a concept in graph theory and computer science. Let T be a rooted tree with n nodes. The lowest common ancestor is defined between two nodes v and w as the lowest node in T that has both v and w as descendants (where we allow a node to be a descendant of itself).
The LCA of v and w in T is the shared ancestor of v and w that is located farthest from the root. Computation of lowest common ancestors may be useful, for instance, as part of a procedure for determining the distance between pairs of nodes in a tree: the distance from v to w can be computed as the distance from the root to v, plus the distance from the root to w, minus twice the distance from the root to their lowest common ancestor.
In a tree data structure where each node points to its parent, the lowest common ancestor can be easily determined by finding the first intersection of the paths from v and w to the root. In general, the computational time required for this algorithm is O(h) where h is the height of the tree (length of longest path from a leaf to the root). However, there exist several algorithms for processing trees so that lowest common ancestors may be found more quickly, in constant time per query after a linear time preprocessing stage.
Read more about Lowest Common Ancestor: History
Famous quotes containing the words lowest, common and/or ancestor:
“When you are invited by someone to a wedding banquet, do not sit down at the place of honor, in case someone more distinguished than you has been invited by your host...But when you are invited, go and sit down at the lowest place, so that when your host comes, he may say to you, Friend, move up higher; then you will be honored in the presence of all who sit at the table with you.”
—Bible: New Testament, Luke 14:8,10.
“In the progress of politics, as in the common occurrences of life, we are not only apt to forget the ground we have travelled over, but frequently neglect to gather up experiences as we go.”
—Thomas Paine (17371809)
“In the core of Gods abysm,
Was a weed of self and schism;
And ever the Daemonic Love
Is the ancestor of wars,
And the parent of remorse.”
—Ralph Waldo Emerson (18031882)