Open
Graph Drawing
Framework

 v. 2023.09 (Elderberry)
 

Loading...
Searching...
No Matches
LCA.h
Go to the documentation of this file.
1
34#pragma once
35
36#include <ogdf/basic/Array.h>
37#include <ogdf/basic/Graph.h>
38#include <ogdf/basic/basic.h>
39
40namespace ogdf {
41
55public:
65 explicit LCA(const Graph& G, node root = nullptr);
66
73 node call(node u, node v) const;
74
76 int level(node v) const { return m_n == 1 ? 0 : m_level[m_representative[v]]; }
77
78private:
79 const node m_root;
80 const int m_n;
81 const int m_len;
82 const int m_rangeJ;
87
92 void dfs(const Graph& G, node root);
93
98 void buildTable();
99
106 const int& sparseTable(int i, int j) const { return m_table[i * m_rangeJ + j - 1]; }
107
108 int& sparseTable(int i, int j) { return m_table[i * m_rangeJ + j - 1]; }
109
111
116 int rmq(int u, int v) const;
117};
118
119}
Declaration and implementation of Array class and Array algorithms.
Includes declaration of graph class.
Basic declarations, included by all source files.
The parameterized class Array implements dynamic arrays of type E.
Definition Array.h:219
Data type for general directed graphs (adjacency list representation).
Definition Graph_d.h:866
Implements the <O(n log n), O(1)>-time "sparse table" algorithm by Bender and Farach-Colton to comput...
Definition LCA.h:54
int level(node v) const
Returns the level of a node. The level of the root is 0.
Definition LCA.h:76
int & sparseTable(int i, int j)
Definition LCA.h:108
LCA(const Graph &G, node root=nullptr)
Builds the LCA data structure for an arborescence.
Array< int > m_level
L[i] is distance of node E[i] from root.
Definition LCA.h:85
void dfs(const Graph &G, node root)
Performs an Euler tour (actually a DFS with virtual back-edges) through the underlying tree and fills...
int rmq(int u, int v) const
Returns the internal index pointing to the LCA between two nodes u and v.
node call(node u, node v) const
Returns the LCA of two nodes u and v.
Array< node > m_euler
Euler[i] is i-th node visited in Euler Tour.
Definition LCA.h:83
NodeArray< int > m_representative
Euler[Representative[v]] = v.
Definition LCA.h:84
const int m_rangeJ
always floor(log(m_len)) (size of a row in the table)
Definition LCA.h:82
Array< int > m_table
preprocessed M[i,j] array
Definition LCA.h:86
const int m_n
number of nodes in graph
Definition LCA.h:80
const int m_len
length of the RMQ array (always 2 m_n - 1)
Definition LCA.h:81
const int & sparseTable(int i, int j) const
Access the sparse table at [i, j].
Definition LCA.h:106
const node m_root
the root of the tree
Definition LCA.h:79
void buildTable()
Fills the O(n log n)-space matrix with auxiliary data the LCA values can be computed from.
Class for the representation of nodes.
Definition Graph_d.h:241
RegisteredArray for nodes, edges and adjEntries of a graph.
Definition Graph_d.h:659
#define OGDF_EXPORT
Specifies that a function or class is exported by the OGDF dynamic library (shared object / DLL),...
Definition config.h:117
The namespace for all OGDF objects.