You are on page 1of 3

Homework # 5

Randomized/ Graph/ Approximation


Algorithms

CS 510 Design and Analysis of Algorithms
Lahore University of Management Sciences

Release Date April 27, 2012
Due Date May 10, 2012 (Before Class)
Points 100

Notes:

9 Work within your group.
9 Start early (there will be no extensions)
9 Give clear and clean proofs/algorithms/arguments.

PART I: Randomized Algorithms: Problems 1 and 2 and 3 are taken from Jeff Ericksons notes on
treaps and skip-lists, here (also on LMS):
http://www.cs.uiuc.edu/~jeffe/teaching/algorithms/notes/10-treaps.pdf

1. 15 pts Review the lecture and notes on treaps and solve the following problems:

(a) The left spine of a binary tree is a path starting at the root and following only left-child
pointers down to a leaf. What is the expected number of nodes in the left spine of an n-node
treap?

(b) What is the expected number of leaves in an n-node treap? [Hint: What is the probability that
in an n-node treap, the node with kth smallest search key is a leaf?]

(c) Prove that the expected number of proper descendants of any node in a treap is exactly equal
to the expected depth of that node.

2. 18 pts Review the lecture and notes on treaps and solve the following problems:

Recall that a priority search tree is a binary tree in which every node has both a search key and a
priority, arranged so that the tree is simultaneously a binary search tree for the keys and a min
heap for the priorities. A heater is a priority search tree in which the priorities are given by the
user, and the search keys are distributed uniformly and independently at random in the real
interval [0, 1]. Intuitively, a heater is a sort of dual treap. The following problems consider an n-
node heater T whose node priorities are the integers from 1 to n. We identify nodes in T by their
priorities; thus, node 5 means the node in T with priority 5. The min-heap property implies that
node 1 is the root of T. Finally, let i and j be integers with 1 i < ] n.

(a) Prove that in a random permutation of the (i + 1)-element set, {1,2,S, , i, ]], elements i and
] are adjacent with probability
2
+1
.
(b) Prove that node i is an ancestor of node ] with probability
2
+1
. [Hint: Use part (a)!]
(c) What is the probability that node i is a descendant of node ]? [Hint: Dont use part (a)!]
(d) What is the exact expected depth of node ]?
(e) Describe and analyze an algorithm to insert a new item into a heater. Express the expected
running time of the algorithm, in terms of the rank of the newly inserted item.
(f) Describe an algorithm to delete the minimum-priority item

3. 7 pts Any skip list I can be transformed into a binary search tree I(I) as follows: The root of
I(I) is the leftmost node on the highest non-empty level of I; the left and right sub-trees are
constructed recursively from the nodes to the left and to the right of the root. Lets call the
resulting tree I(I), a skip list tree. Show that any search in T(L) is no more expensive than the
corresponding search in L. (Searching in I(I) could be considerably cheaperwhy?)

PART II: Basic Graph Algorithms: Problems 4, 5 and 6 are taken from the exercise problems in
DPV chapter 3 and 4. Reading these chapters will help you solve these problems.


4. 10 pts You are given a directed graph with (possibly negative) weighted edges, in which the
shortest path between any two vertices is guaranteed to have at most k edges. Give an algorithm
that finds the shortest path between two vertices u and : in 0(k|E|) time.

5. 10 pts Give an 0(|I|
2
) algorithm for the following task.
Input: An undirected graph 0 = (I, E); edge lengthsl
c
> u; an edge c E.
Output: The length of the shortest cycle containing edge c.

6. 20 pts Problem 3.28, pg 111 DPV: An algorithm for 2SAT, using directed graphs and strongly
connected components.

PART III: Approximation Algorithms: Chapter 9 of DPV; chapter 35 of CLRS are
recommended readings.

7. 10 pts Consider the problem of partitioning the nodes of a weighted undirected graph 0 =
(I, E, w), where w is the set of positive edge weights, into two sets I
1
and I
2
, such that following
quantity (D) is maximized:

w(I
1
) = w({u, :])
u,v
1
{u,]L

w(I
2
) = w({w, x])
w,xv
2
{w,x]L


= |w(I
1
) - w(I
2
)|

(a) Show that the brute-force algorithm takes exponential time.

Following is a proposed approximation algorithm:

Let u I, be an arbitrary subset of I
WHILE (
0

v
( ||u| - |u

|| = 1 AND w(u

) > w(u) )
u u



(b) Show that this is a valid approximation algorithm with
A
= 2.
(c) Does the algorithm run in polynomial time?

8. 10 pts In problem 6 you found an algorithm for the 2SAT problem. The 3SAT problem is just an
extension of the 2SAT problem, in which a clause can have no more than 3 literals. For example,
following is an instance of the 3SAT problem:

(x
1
x
2
) (x
1
x
3
x
4
) (x
2
) (x
2
x
3
x
4
)

Just as before the goal is to find an assignment of truth values to the variables such that, the who
expression becomes true. However, unlike 2SAT, 3SAT is NP-hard, which means that, no
efficient algorithm is known to solve it.

As you can see from the struct of the CNF form, for the entire expression to be true, every clause
has to be true. Give an approximation heuristic which will satisfy (turn true) at least half the
clauses of the formula.

9. 0 pts Read Chapter 8 of DPV, on NP-Complete problems from pg 247 to 262. Nothing to
submit for this problem.

You might also like