Cartesian tree: Difference between revisions

Content deleted Content added
reflect updates to def in lead
top: tighter
Line 2:
[[File:Cartesian tree.svg|thumb|240px|A sequence of numbers and the Cartesian tree derived from them.]]
{{for|Descartes' metaphor of tree of knowledge|Tree of knowledge (philosophy)}}
In [[computer science]], a '''Cartesian tree''' is a [[binary tree]] derived from a sequence of distinct numbers. To construct the Cartesian tree, set its root to be the minimum number in the sequence, and recursively construct its left and right subtrees from the subsequences before and after this number. It is uniquely defined from theas properties that it isa [[Heap (data structure)|min-heap]]-ordered and that awhose [[Tree traversal|symmetric (in-order) traversal]] of the tree returns the original sequence.
 
Cartesian trees were introduced by {{harvtxt|Vuillemin|1980}} in the context of geometric [[range searching]] data structures. They have also been used in the definition of the [[treap]] and [[randomized binary search tree]] data structures for [[binary search]] problems, in [[comparison sort]] algorithms that perform efficiently on nearly-sorted inputs, and as the basis for [[pattern matching]] algorithms. A Cartesian tree for a sequence can be constructed in [[linear time]].