Randomized Algorithms, Exercises Solution- Discrete Mathematics 1, Exercises of Discrete Structures and Graph Theory

Discrete Structures, Randomized Algorithm, Exercises, Exam Paper

Typology: Exercises

2010/2011

Uploaded on 10/12/2011

lovefool
lovefool 🇬🇧

4.5

(21)

292 documents

1 / 4

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
6.856 Randomized Algorithms
Handout #6, March 6, 2011 Homework 1 Solutions
1a.
Let 0.b1b2. . . be the binary fraction representation of p1. We can treat the random bit
stream r1, r2, . . . also as a binary fraction and return the first item if r= 0.r1r2. . . < p1
and the second item otherwise. Since the random bit stream is unbiased, we will return the
first item with probability p1. We will make the comparison of the two binary fractions by
comparing biand ristarting from i= 1. If the two bits differ (with probability 0.5), we can
immediately conclude if r < p and return the appropriate item from S. If they are the same
(with probability 0.5), we need to compare additional bits to determine the direction of the
inequality. Thus, for any arbitrary p1, the probability that it will take exactly ncomparisons
to choose one of the two items is 1
2n. Thus, the expected number of bits to examine is
B=P
n=1 1
2nn=P
n=1 1
2n+P
n=2 1
2n+· · ·+P
n=i1
2n+· · · = 1 + 1
2+· · ·+1
2i1+· · · =
2O(1).
1b.
When there are more than 2 items in S, we associate Swith the root node of a binary tree
that at each node divides the associated set into 2 roughly even partitions. For each node i,
we can compute the probability piof drawing an element from the left subtree by summing
up the probabilities associated with the elements associated with the subtrees and normalize
such that probability of descending into the two subtrees sum up to 1. To draw a sample
from the set, we recursively compare the current random bit stream against piat the node
starting at the root, and descend down the appropriate subtree based on the result of the
comparison. The recursion ends when we reach a subtree with only a single element and
return that element. Since the height of the tree is O(log n) and each comparison uses O(1)
random bits in expectation, the overall algorithm uses O(log n) random bits in expectation
per sample. 1
1By computing cumulative probabilities ci=p1+· · · +piand reusing the random bit stream when
performing binary comparison over ci, we can further reduce the constant factor of the O(log n) algorithm.
1
pf3
pf4

Partial preview of the text

Download Randomized Algorithms, Exercises Solution- Discrete Mathematics 1 and more Exercises Discrete Structures and Graph Theory in PDF only on Docsity!

6.856 — Randomized Algorithms

Handout #6, March 6, 2011 — Homework 1 Solutions

1a.

Let 0.b 1 b 2... be the binary fraction representation of p 1. We can treat the random bit stream r 1 , r 2 ,... also as a binary fraction and return the first item if r = 0.r 1 r 2... < p 1 and the second item otherwise. Since the random bit stream is unbiased, we will return the first item with probability p 1. We will make the comparison of the two binary fractions by comparing bi and ri starting from i = 1. If the two bits differ (with probability 0.5), we can immediately conclude if r < p and return the appropriate item from S. If they are the same (with probability 0.5), we need to compare additional bits to determine the direction of the inequality. Thus, for any arbitrary p 1 , the probability that it will take exactly n comparisons to choose one of the two items is

2

)n

. Thus, the expected number of bits to examine is B =

n=

2

)n n =

n=

2

)n

n=

2

)n +· · ·+

n=i

2

)n +· · · = 1+ 12 +· · ·+ (^2) i^1 − 1 +· · · = 2 ∈ O(1).

1b.

When there are more than 2 items in S, we associate S with the root node of a binary tree that at each node divides the associated set into 2 roughly even partitions. For each node i, we can compute the probability pi of drawing an element from the left subtree by summing up the probabilities associated with the elements associated with the subtrees and normalize such that probability of descending into the two subtrees sum up to 1. To draw a sample from the set, we recursively compare the current random bit stream against pi at the node starting at the root, and descend down the appropriate subtree based on the result of the comparison. The recursion ends when we reach a subtree with only a single element and return that element. Since the height of the tree is O(log n) and each comparison uses O(1) random bits in expectation, the overall algorithm uses O(log n) random bits in expectation per sample. 1

(^1) By computing cumulative probabilities ci = p 1 + · · · + pi and reusing the random bit stream when

performing binary comparison over ci, we can further reduce the constant factor of the O(log n) algorithm.

1c.

Assume that a finite number of bits n suffices for the uniform distribution on 1, 2, 3. This means that at the highest resolution, we are able to divide the [0,1] interval into 2n^ equally sized subintervals. But we need to apportion intervals so that equal numbers of intervals are assigned to elements 1, 2, and 3. This is impossible since 3 does not divide 2n. More generally, we have 2n^ equi-probable states, which must be evenly divided among three elements. ⇒⇐. Therefore, finite bits will not suffice in the worst case.

2a.

Since x is randomly selected, s ∈ { 0 , 1 ,... , n − 1 } with equal probability (^) n^1. When s ≥ k, the size of the recursive set is s. Otherwise, it is n − s − 1 2. Thus, the expected size of the recursive set is

∑^ n−^1

s=k

s n

∑^ k−^2

s=

n − s − 1 n

(n + k − 1)(n − k) 2 n

2(k − 1)(n − 1) − (k − 2)(k − 1) 2 n

n^2 − 2 k^2 + 2nk − 3 n + 2k 2 n

= n

k n

k n

k n

k n

k n

n

Defining b = −

( (^) k n

  • (^) nk + 12 , it obtains its maximum of 34 at (^) nk = 12. Thus, the expected size of the recursive set of is at most 34 n.

2b.

Let T (n) be the expected runtime of F IN D on an n-element set. In the base case, T (1) = 1 since we can simply return the single element in the set. When n > 1, the algorithm picks a random pivot and divides the set into two in n steps. The recursion continues on a subset S′^ whose expected size is bounded by 34 n. Thus, assuming T (·) is linear in n, T (n) = n + E[T (sizeof (S′))] = n + T (E[sizeof (S′)]) ≤ n + T (^34 n). This recurrence yields

T (n) ≤ n

4

= 4n. Thus, the expected running time of F IN D on an

n-element set is at most 4n. (^2) We assume that if s = k − 1, the algorithm terminates and returns x.

Problem 5.

(a)

Consider the following graph G = (V, E): there are vertices s and t, and there are k inde- pendent and similar components. The component i is as follows: there are nodes Ai and Bi, and edges {(s, Ai); (s, Bi); (Ai, Bi), (Bi, t)}. Clearly the size of the min cut is equal to k and the cut is: T = {t} and S = E \ T (i.e., all vertices except t). There is exactly one s-t cut. Therefore, let’s call the edges {(Bi, t) | i = 1... k} the cut edges, and the rest of the edges as non-cut edges. Let’s prove that the algorithm has an exponentially small probability of not contracting a cut edges. Suppose the algorithm performed t steps and did not contract a cut edge yet. Then there are k cut edges and at most 3k non-cut edges. Therefore, the probability that the algorithm chooses a non-cut edge is ≤ 34 kk = 3/4. Thus, there is at most (3/4)n−^2 probability that in each of the n − 2 contractions the algorithm did not choose a cut edge. Thus, the probability that the algorithm finds a min-cut is at most (3/4)n−^2 = e−Ω(n), which is exponentially small.

(b)

The construction of the graph is similar: there are k independent similar components. The component i looks like: there is a vertex Ai and edges {(s, Ai); (Ai, t)}. Clearly any cut has value exactly k; and therefore every cut is a min-cut. There are in total 2k^ = 2n−^2 cuts in total (each Ai can be either in S or in T ). Thus, there can be an exponential (2Ω(n)) number of min s-t cuts.