sol5 - 6.851 Advanced Data Structures (Spring10) Prof. Erik...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
6.851 Advanced Data Structures (Spring’10) Prof. Erik Demaine Dr. Andr´ e Schulz TA: Aleksandar Zlateski Problem 5 Sample Solutions Cartesian trees in linear time. We will add the elements according to their order in A . If the current element x is greater than the previously added one, we just add it as its right child. Otherwise, we walk up the three until we find an element that is smaller then the current one. We then attach x as its right child, and attach it’s previous right child as x ’s left child. It is clear that with every step we make towards the root we reduce the path from the last element to the root by one. Having total of
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.
Ask a homework question - tutors are online