TheAlgorithms/C++ 1.0.0
All the algorithms implemented in C++
|
Public Member Functions | |
LowestCommonAncestor (const RootedTree &tree_) | |
Stores the tree and precomputs "up lifts". | |
int | lowest_common_ancestor (int u, int v) const |
Query the structure to find the lowest common ancestor. Assumes that the provided numbers are valid indices of vertices. Iterativelly modifies ("lifts") u an v until it finnds their lowest common ancestor. | |
Public Attributes | |
const RootedTree & | tree |
std::vector< std::vector< int > > | up |
for every vertex stores a list of its ancestors by powers of two For each vertex, the first element of the corresponding list contains the index of its parent. The i-th element of the list is an index of the (2^i)-th ancestor of the vertex. | |
Protected Member Functions | |
void | populate_up () |
A structure that holds a rooted tree and allow for effecient queries of the lowest common ancestor of two given vertices in the tree.
Definition at line 145 of file lowest_common_ancestor.cpp.
|
inlineexplicit |
Stores the tree and precomputs "up lifts".
tree_ | rooted tree. |
Definition at line 151 of file lowest_common_ancestor.cpp.
|
inline |
Query the structure to find the lowest common ancestor. Assumes that the provided numbers are valid indices of vertices. Iterativelly modifies ("lifts") u an v until it finnds their lowest common ancestor.
u | index of one of the queried vertex |
v | index of the other queried vertex |
Definition at line 164 of file lowest_common_ancestor.cpp.
|
inlineprotected |
Populate the "up" structure. See above.
Definition at line 212 of file lowest_common_ancestor.cpp.
const RootedTree& graph::LowestCommonAncestor::tree |
Definition at line 199 of file lowest_common_ancestor.cpp.
std::vector<std::vector<int> > graph::LowestCommonAncestor::up |
for every vertex stores a list of its ancestors by powers of two For each vertex, the first element of the corresponding list contains the index of its parent. The i-th element of the list is an index of the (2^i)-th ancestor of the vertex.
Definition at line 206 of file lowest_common_ancestor.cpp.