| Algorithms_in_C++ 1.0.0
    Set of algorithms implemented in C++. | 
Data structure for finding the lowest common ancestor of two vertices in a rooted tree using binary lifting. More...
#include <cassert>#include <iostream>#include <queue>#include <utility>#include <vector>| Classes | |
| class | graph::Graph< T > | 
| class | graph::RootedTree | 
| class | graph::LowestCommonAncestor | 
| Namespaces | |
| namespace | graph | 
| Graph Algorithms. | |
| Functions | |
| static void | tests () | 
| int | main () | 
Data structure for finding the lowest common ancestor of two vertices in a rooted tree using binary lifting.
Algorithm: https://cp-algorithms.com/graph/lca_binary_lifting.html
Complexity:
Example: 
 Tree: 
            _  3  _
         /     |     \
       1       6       4
     / |     /   \       \
   7   5   2       8       0
           |
           9
 lowest_common_ancestor(7, 4) = 3 
 lowest_common_ancestor(9, 6) = 6 
 lowest_common_ancestor(0, 0) = 0 
 lowest_common_ancestor(8, 2) = 6
The query is symmetrical, therefore lowest_common_ancestor(x, y) = lowest_common_ancestor(y, x)
| int main | ( | void | ) | 
| 
 | static | 
Unit tests
_ 3 _ / | \ 1 6 4
/ | / \ \ 7 5 2 8 0 | 9