This preview shows page 1. Sign up to view the full content.
Binary search trees, Greedy algorithms
October 31, 2010
Homework 4
Due Date: Tuesday, 9 November 2010, 2:05pm
Problem 41.
20pts
Suppose that a search for key
k
in a binary search tree ends up in a leaf. Consider three sets:
A
, the keys to
the left of the search path;
B
, the keys on the search path; and
C
, the keys to the right of the search path.
Provide a small counterexample that disproves the following claim:
Any three keys
a
∈
A, b
∈
B, c
∈
C
must
satisfy
a
≤
b
≤
c
.
Problem 42.
20pts
An alternative method of performing an inorder tree walk of an
n
node binary search tree ﬁnds the minimum
element in the tree and then ﬁnding its
n

1 successors, one at a time. In other words, if minimum is
a
,
then ﬁrst ﬁnd
a
, then ﬁnd
b
=successor of
a
, then
c
=successor of
b
, etc. Prove that this algorithm runs
in Θ(
n
) time. [Note that one cannot claim that ”successor” operation always takes
O
(1) time, even for an
approximately balanced binary search tree.]
Problem 43.
25pts
This is the end of the preview. Sign up
to
access the rest of the document.
This note was uploaded on 02/01/2011 for the course MATH 171 taught by Professor R during the Spring '09 term at Stanford.
 Spring '09
 R
 Sets

Click to edit the document details