TheAlgorithms/C++ 1.0.0
All the algorithms implemented in C++
|
Heavy Light Decomposition implementation More...
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstring>
#include <iostream>
#include <list>
#include <numeric>
#include <string>
#include <vector>
Go to the source code of this file.
Classes | |
class | range_queries::heavy_light_decomposition::Tree< X > |
A Basic Tree, which supports binary lifting. More... | |
class | range_queries::heavy_light_decomposition::SG< X > |
Segment Tree, to store heavy chains. More... | |
class | range_queries::heavy_light_decomposition::HLD< X > |
The Heavy-Light Decomposition class. More... | |
Namespaces | |
namespace | range_queries |
for std::vector | |
namespace | heavy_light_decomposition |
Heavy light decomposition algorithm. | |
Functions | |
static void | test_1 () |
static void | test_2 () |
static void | test_3 () |
int | main () |
Heavy Light Decomposition implementation
Heavy-Light Decomposition is a technique on trees, that supports the following:
The update is done in O(log n) time, and the query is done in O(log^2 n) time with HLD where, n is the number of nodes
The template type is the data type of the value stored in the nodes. If a non-primitive data-type is used as a template, the coressponding operators must be overloaded.
An HLD object can only be created with a constant number of nodes, and it cannot be changed later. Creaty an empty instance is not supported.
To start answering updates and queries,
Sample I/O at the bottom.
Definition in file heavy_light_decomposition.cpp.
int main | ( | void | ) |
Main function
Definition at line 634 of file heavy_light_decomposition.cpp.
|
static |
Test implementations
Definition at line 505 of file heavy_light_decomposition.cpp.
|
static |
Second test implementations
Definition at line 549 of file heavy_light_decomposition.cpp.
|
static |
Third test implementations
Definition at line 592 of file heavy_light_decomposition.cpp.