Cartesian trees solve range minimum query problem in constant time.

Category: QuestionsCartesian trees solve range minimum query problem in constant time.
Editor">Editor Staff asked 1 month ago

Cartesian trees solve range minimum query problem in constant time.
 
(a) true
 
(b) false
 
The above asked question is from Cartesian Tree topic in section Binary Trees of Data Structures & Algorithms I
 
This question was addressed to me during an internship interview.

1 Answers
Editor">Editor Staff answered 1 month ago

The correct answer is (a) true
 
The explanation is: Range minmum query is finding the minimum element in a given subarray of an array. Constant time is achieved by storing the Cartesian trees for all the blocks in the array. Rmq’s are used in string matchings, computing lowest common ancestor and longest common prefix of a sring.