Cartesian trees are most suitable for?

Category: QuestionsCartesian trees are most suitable for?
Editor">Editor Staff asked 1 month ago

Cartesian trees are most suitable for?
 
(a) searching
 
(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.

1 Answers
Editor">Editor Staff answered 1 month ago

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.