Building a Cartesian Tree. A Cartesian Tree is a heap-like structure such that the root element of every sub-tree is not greater than any of the elements in the sub-tree below it. Like the heap, a Cartesian Tree is also a recursive structure. We show a linear time algorithm to build a cartesian tree from an input array. The difference between a cartesian tree and heap is that the former preserves the relative order of elements in the input array while the latter does not.