This preview shows pages 1–2. Sign up to view the full content.
Fall 2011
CS 513: #5
FarachColton
Due by the beginning of class, Oct. 11.
1. Let
A
[1
,n
] be an array of numbers. Deﬁne 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 ﬁnding 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
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.