{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

ass05

# ass05 - Fall 2011 CS 513#5 Farach-Colton Due by the...

This preview shows pages 1–2. Sign up to view the full content.

Fall 2011 CS 513: #5 Farach-Colton Due by the beginning of class, Oct. 11. 1. Let A [1 , n ] be an array of numbers. Define the cartesian tree , C A , of A recur- sively, as follows. If n = 1, then C A is a node with value A [1]. Otherwise, let A [ i ] be a minimal element of A . Then the C A is the tree with binary tree such that A [ i ] is the root, and the left and right children of A [ i ] are the cartesian trees of A [1 , i - 1] and A [ i + 1 , n ] respectively. If i = 0 then A [ i ] has no left child, and if i = n then A [ i ] has no right child. Give an algorithm for finding a cartesian tree of an array. Give an analysis of its running time. The faster the algorithm, the better your grade – an O ( n ) time algorithm is known. 2. Notice that A may have more than one cartesian tree if the elements of A are not unique. Show that the minimum value in the subarray A [ i, j ] is the value of the least common ancestor of A [ i ] and A [ j ] in T . In the future, we will refer to the least common ancestor of two nodes v , w in tree T as lca T ( v, w ), and

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}