Cartesian trees are most suitable for?
(b) finding nth element
(c) minimum range query and lowest common ancestors
(d) self balancing a tree
I need to ask this question from Cartesian Tree in chapter Binary Trees of Data Structures & Algorithms I
The question was posed to me in quiz.
Correct option is (c) minimum range query and lowest common ancestors
Easiest explanation – In a cartesian tree minimum value can be found by finding lowest common ancestor for the extreme elements. consider 11,9,19,16 the lowest element is 9 and is a lowest common ancestor for 11 and 16. and by applying few techniques cartesian tree can be used to even find lowest common ancestors efficiently.
these can be done in constant time. tree can be constructed in linear time (this is the most efficient time for any tree construction) and takes space as many elements are there.