A Cartesian Tree is a binary tree that is uniquely defined by a sequence of numbers and has two key properties: it is a binary search tree (BST) with respect to the values of the nodes, and it is a min-heap with respect to the indices of the elements in the original sequence. This means that for any node in the tree, all values in the left subtree are less than , and all values in the right subtree are greater than . Additionally, if you were to traverse the tree in a pre-order manner, the sequence of values would match the original sequence's order of appearance.
To construct a Cartesian Tree from an array, one can use the following steps:
This structure is particularly useful for applications in data structures and algorithms, such as for efficient range queries or maintaining dynamic sets.
Start your personalized study experience with acemate today. Sign up for free and find summaries and mock exams for your university.