TheAlgorithms/C++ 1.0.0
All the algorithms implemented in C++
|
A balanced binary search tree (BST) on the basis of binary search tree and heap: the Treap algorithm implementation. More...
#include <array>
#include <cassert>
#include <cstdint>
#include <iostream>
Go to the source code of this file.
Classes | |
struct | data_structures::treap::Treap |
Struct representation of the treap. More... | |
Namespaces | |
namespace | data_structures |
for IO operations | |
namespace | data_structures::treap |
Functions for the Treap algorithm implementation. | |
Functions | |
static void | test () |
Self-test implementations. | |
int | main () |
Main function. | |
Variables | |
const int | data_structures::treap::maxNode = 1e5 + 5 |
maximum number of nodes | |
A balanced binary search tree (BST) on the basis of binary search tree and heap: the Treap algorithm implementation.
Implementation of the treap data structre
Support operations including insert, erase, and query (the rank of specified element or the element ranked x) as the same as BST
But these operations take O(log N) time, since treap keeps property of heap using rotate operation, and the desired depth of the tree is O(log N). There's very little chance that it will degenerate into a chain like BST
Definition in file treap.cpp.
int main | ( | void | ) |
|
static |
Self-test implementations.
< Treap object instance
Definition at line 229 of file treap.cpp.