CS 373: Combinatorial Algorithms, Spring 2001
Homework 2 (due Thu. Feb. 15, 2001 at 11:59 PM)
Name:
Net ID:
Alias:
U
3
/
4
1
Name:
Net ID:
Alias:
U
3
/
4
1
Name:
Net ID:
Alias:
U
3
/
4
1
Starting with Homework 1, homeworks may be done in teams of up to three people. Each team
turns in just one solution, and every member of a team gets the same grade. Since 1unit graduate
students are required to solve problems that are worth extra credit for other students,
1unit grad
students may not be on the same team as 3/4unit grad students or undergraduates.
Neatly print your name(s), NetID(s), and the alias(es) you used for Homework 0 in the boxes above.
Please also tell us whether you are an undergraduate, 3/4unit grad student, or 1unit grad student
by circling U,
3
/
4
, or 1, respectively. Staple this sheet to the top of your homework.
Required Problems
1. Suppose we are given two sorted arrays
A
[1
..n
] and
B
[1
..n
] and an integer
k
. Describe an
algorithm to Fnd the
k
th smallest element in the union of
A
and
B
. (±or example, if
k
= 1,
your algorithm should return the smallest element of
A
∪
B
; if
k
=
n
, our algorithm should
return the median of
A
∪
B
.) You can assume that the arrays contain no duplicates. ±or full
credit, your algorithm should run in Θ(log
n
) time.
[Hint: First try to solve the special case
k
=
n
.]
2. Say that a binary search tree is
augmented
if every node
v
also stores

v

, the size of its
subtree.
(a) Show that a rotation in an augmented binary tree can be performed in constant time.
(b) Describe an algorithm
ScapegoatSelect
(
k
) that selects the
k
th smallest item in an
augmented scapegoat tree in
O
(log
n
)
worstcase
time.
(c) Describe an algorithm
SplaySelect
(
k
) that selects the
k
th smallest item in an aug
mented splay tree in
O
(log
n
)
amortized
time.
This preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentCS 373
Homework 2 (due 2/15/2001)
Spring 2001
(d) Describe an algorithm
TreapSelect
(
k
) that selects the
k
th smallest item in an aug
mented treap in
O
(log
n
)
expected
time.
3. (a) Prove that only one subtree gets rebalanced in a scapegoat tree insertion.
(b) Prove that
This is the end of the preview.
Sign up
to
access the rest of the document.
 Spring '09
 A
 Analysis of algorithms, Selfbalancing binary search tree, Amortized analysis, kth smallest item

Click to edit the document details