You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This module provides a function to build a Cartesian tree from a given vector in O(n) time. A Cartesian tree is a binary tree where each node's value is greater than the values of its children, and it is constructed based on the order of elements in the input vector.
9
+
10
+
## Usage Example
11
+
12
+
```cpp
13
+
#include"cartesian.hpp"
14
+
std::vector<int> a = {3, 1, 2};
15
+
auto res = cartesian(a); // returns a vector of pairs representing ls and rs of each node.
16
+
```
17
+
18
+
## Main Features
19
+
- Supports custom comparison functions for building Cartesian trees based on different criteria.
20
+
- Uses monostack algorithm, time complexity $O(n)$
21
+
- Does not modify the original data (pass by value)
0 commit comments