Ass05 - 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 Dene the cartesian tree CA of A

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

View Full Document Right Arrow Icon
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
Background image of page 1

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

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

This document was uploaded on 12/18/2011.

Page1 / 2

Ass05 - 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 Dene the cartesian tree CA of A

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online