Questions tagged [cartesian-tree]

In computer science, a Cartesian tree is a binary tree derived from a sequence of numbers; it can be uniquely defined from the properties that it is heap-ordered and that a symmetric (in-order) traversal of the tree returns the original sequence.

Cartesian trees have also been used in randomized binary search tree data structures for binary search problems. The Cartesian tree for a sequence may be constructed in linear time using a stack-based algorithm for finding all nearest smaller values in a sequence.

Read More

7 questions
25
votes
4 answers

When to use a treap

Can anyone provide real examples of when is the best way to store your data is treap? I want to understand in which situations treap will be better than heaps and tree structures. If it's possible, please provide some examples from real…
user2281439
  • 603
  • 1
  • 11
  • 18
10
votes
1 answer

Range Minimum Query approach (from tree to restricted RMQ)

So, I read this TopCoder tutorial on RMQ (Range Minimum Query), and I got a big question. On the section where he introduced the approach, what I can understand until now is this: (The whole approach actually uses methodology introduced in Sparse…
Shane Hsu
  • 6,377
  • 6
  • 32
  • 60
2
votes
1 answer

tree recursive with cartesian implementation

I need help to find all combined possibilities from a tree I readed a lot of documentation about cartesian product, tried a lot of things but none of them seems to work properly... This is my tree var data = [ { "id": 5, "name": "Support…
2
votes
3 answers

Efficiently convert array to cartesian tree

I know how to convert an array to a cartesian tree in O(n) time http://en.wikipedia.org/wiki/Cartesian_tree#Efficient_construction and http://community.topcoder.com/tc?module=Static&d1=tutorials&d2=lowestCommonAncestor#From RMQ to LCA However, the…
dhruvbird
  • 5,396
  • 5
  • 31
  • 37
1
vote
2 answers

RMQ on static 2D array in constant time

The input is an array (n*m 1
Rajarshi basu
  • 322
  • 1
  • 10
1
vote
1 answer

How to reverse an array from index i to index j multiple times using cartesian tree?

Suppose I have a given array A. Now there are multiple operations of the form reverse i,j // means reverse the array Ai..j inclusive and print i,j Print the array Ai..j. Example , A = 6 9 1 10 4 15 9 reverse 2,3 A = 6 1 9 10 4 15 9 reverse 3,6 A…
Unbound
  • 233
  • 1
  • 11
1
vote
2 answers

complexity of single change in array that is maintained with a static Range Minimum Query

I had a test in the data structures course and one of the questions was: lets say you have an n-size array that is maintained with a Range Minimum Query that gives the minimum between two numbers in the array in o(1) complexity. of course the array…
user76508
  • 267
  • 2
  • 7