Docsity

Random Walks and Graph Connectivity in Computer Science, Study notes of Number Theory

Toggle sidebar
bg1
CS225: Pseudorandomness Prof. Salil Vadhan
Lecture 4: Random Walks
February 13, 2007
Based on scribe notes by Dave Troiano and Brian Greenberg.
1 Graph Connectivity
One of the most basic problems in computer science is that of deciding connectivity in graphs, i.e.
S-T Connectivity:Given a directed graph Gand two vertices sand t, is there a path from s
to tin G?
This problem can of course be solved in linear time using breadth-first or depth-first search. How-
ever, these algorithms also require linear space. It turns out that S-T Connectivity can in fact
be solved using much less workspace. (When measuring the space complexity of algorithms, we do
not count the space for the (read-only) input and (write-only) output.)
Theorem 1 There is an algorithm deciding S-T Connectivity using space O(log2n)(and time
nO(log n)).
Proof: The following recursive algorithm IsPath(G, u, v, k) decides whether there is a path of
length at most kfrom uto v.
IsPath(G, u, v, k):
1. If k= 0, accept if u=v.
2. If k= 1, accept if u=vor (u, v ) is an edge in G.
3. Otherwise, loop through all vertices win Gand accept if both IsPath(G, u, w, dk/2e) and
IsPath(G, w, v, bk/2c) accept for some w.
We can solve S-T Connectivity by running IsPath(G, s, t, n), where nis the number of vertices
in the graph. The algorithm has log nlevels of recursion and uses log nspace per level of recursion
(to store the vertex w), for a total space bound of log2n. Similarly, the algorithm uses polynomial
time per level of recursion, for a total time bound of poly(n)log n=nO(log n).
It is not known how to improve the space bound in Theorem 1 or to get the running time down to
polynomial while maintaining space no(1). For undirected graphs, however, we can do much better
using a randomized algorithm. Specifically, we can place it in the following class:
1
pf3
pf4
pf5

Partial preview of the text

Download Random Walks and Graph Connectivity in Computer Science and more Study notes Number Theory in PDF only on Docsity!

CS225: Pseudorandomness Prof. Salil Vadhan

Lecture 4: Random Walks

February 13, 2007

Based on scribe notes by Dave Troiano and Brian Greenberg.

1 Graph Connectivity

One of the most basic problems in computer science is that of deciding connectivity in graphs, i.e.

S-T Connectivity: Given a directed graph G and two vertices s and t, is there a path from s to t in G?

This problem can of course be solved in linear time using breadth-first or depth-first search. How- ever, these algorithms also require linear space. It turns out that S-T Connectivity can in fact be solved using much less workspace. (When measuring the space complexity of algorithms, we do not count the space for the (read-only) input and (write-only) output.)

Theorem 1 There is an algorithm deciding S-T Connectivity using space O(log^2 n) (and time nO(log^ n)).

Proof: The following recursive algorithm IsPath(G, u, v, k) decides whether there is a path of length at most k from u to v.

IsPath(G, u, v, k):

  1. If k = 0, accept if u = v.
  2. If k = 1, accept if u = v or (u, v) is an edge in G.
  3. Otherwise, loop through all vertices w in G and accept if both IsPath(G, u, w, dk/ 2 e) and IsPath(G, w, v, bk/ 2 c) accept for some w.

We can solve S-T Connectivity by running IsPath(G, s, t, n), where n is the number of vertices in the graph. The algorithm has log n levels of recursion and uses log n space per level of recursion (to store the vertex w), for a total space bound of log^2 n. Similarly, the algorithm uses polynomial time per level of recursion, for a total time bound of poly(n)log^ n^ = nO(log^ n).

It is not known how to improve the space bound in Theorem 1 or to get the running time down to polynomial while maintaining space no(1). For undirected graphs, however, we can do much better using a randomized algorithm. Specifically, we can place it in the following class:

Definition 2 A language L is in RL if there exists a randomized algorithm A that always halts, uses space at most O(log n) on inputs of length n, and satisfies:

  • x ∈ L ⇒ Pr[A(x) accepts] ≥ (^12)
  • x 6 ∈ L ⇒ Pr[A(x) accepts] = 0

Recall that our model of a randomized space-bounded machine is one that has access to a coin- tossing box (rather than an infinite tape of random bits), and thus must explicitly store in its workspace any random bits it needs to remember. The requirement that A always halts ensures that its running time is at most 2O(log^ n)^ = poly(n), because otherwise there would be a loop in its configuration space. Similarly to RL, we can define L (deterministic logspace), co-RL (one-sided error with errors only on no instances), and BPL (two-sided error).

Now, we can state the theorem regarding connectivity in undirected graphs.

Undirected S-T Connectivity: Given an undirected graph G and two vertices s and t, is there a path from s to t in G?

Theorem 3 Undirected S-T Connectivity is in RL.

Proof: The algorithm simply does a polynomial-length random walk starting at s.

Random-Walk Algorithm for Undirected S-T Connectivity. On input (G, s, t), where G = (V, E) has n vertices:

  1. Let v = s.
  2. Repeat up to n^4 times:

(a) If v = t, halt and accept. (b) Else let v ← {R w : (v, w) ∈ E}.

  1. Reject (if we haven’t visited t yet).

Notice that this algorithm only requires space O(log n), to maintain the current vertex v as well as a counter for the number of steps taken. Clearly, it never accepts when there isn’t a path from s to t. In the next section, we will prove that if G is a d-regular graph, then a random walk of length O˜(d^2 n^3 ) from s will hit t with high probability. Note that this suffices for the theorem, because make an arbitrary undirected graph 3-regular while preserving s-t connectivity by replacing each vertex v with a cycle of length deg(v). In fact, the algorithm actually works as described above for general undirected graphs and even directed graphs in which each connected component is Eulerian (indeg(v) = outdeg(v) for every vertex), but we will not prove it here. But it does not work for arbitrary directed graphs. Indeed, it is not difficult to construct directed graphs in which there is a path from s to t but a random walk from s takes exponential time to hit t.

Definition 7 For a regular directed graph G with random-walk matrix M , we define

λ(G) def = max π

‖πM − u‖ ‖π − u‖ = max x⊥u

‖xM ‖ ‖x‖

where the first maximization is over all probability distributions π ∈ [0, 1]n^ and the second is over

all vectors x ∈ Rn^ such that x ⊥ u. We write γ(G) def = 1 − λ(G).

To see that the first definition of λ(G) is smaller than or equal to the second, note that for any probability distribution π, the vector x = (π − u) is orthogonal to uniform (i.e. the sum of its entries is zero). For the converse, observe that given any vector x ⊥ u, the vector π = u + αx is a probability distribution for a sufficiently small α. It can be shown that λ(G) ∈ [0, 1]. (For undirected graphs, this follows from Problem Set 2 and the material in the next section.)

The following lemma is immediate from the definition of M.

Lemma 8 Let G be a regular digraph with random-walk matrix M. For every initial probability distribution π on the vertices of G and every k ∈ N, we have

‖πM k^ − u‖ ≤ λ(G)k^ · ‖π − u‖ ≤ λ(G)k.

Thus a smaller value of λ(G) (equivalently, a larger value of γ(G)) mean that the random walk mixes more quickly. Specifically, for k = ln(n/ε)/γ(G), it follows that every entry of πM k^ has probability mass at least 1/n − (1 − γ(G))k^ ≥ (1 − ε)/n. So the mixing time of the random walk on G is at most O((log n)/γ(G)), with respect to any reasonable distance measure. Note that O(1/γ(G)) steps does not suffice, because a distribution with ` 2 distance ε from uniform could just assign equal probability mass to 1/ε^2 vertices (and thus be very far from uniform in any intuitive sense).

Corollary 9 hit(G) = O(n log n/γ(G)).

Proof: As argued above, a walk of length k = O(log n/γ(G)) has a probability of at least 1/ 2 n of ending at j. Thus, we expect to hit j within 2n such walks, for a total expected walk length of 2 n · k = O(n log n/γ(G)).

Thus we are left with the task of showing that γ(G) ≥ 1 /poly(n). You will do this on Problem Set 2, using a connection with eigenvalues described in the next section.

3 Eigenvalues

Recall that v ∈ Rn^ is an eigenvector of n × n matrix M if vM = λv for some λ ∈ R, which is called the corresponding eigenvalue. A useful feature of symmetric matrices is that they can be described entirely in terms of their eigenvectors and eigenvalues.

Theorem 10 If M is a symmetric n × n real matrix with distinct eigenvalues μ 1 ,... , μk, then the subspaces Wi = {x : x is an eigenvector of eigenvalue μi} are orthogonal (i.e. x ∈ Wi, y ∈ Wj ⇒ x ⊥ y if i 6 = j) and span Rn^ (i.e. Rn^ = W 1 + · · · + Wk). We refer to the dimension of Wi as the multiplicity of eigenvalue λi. In particular, Rn^ has a basis consisting of orthogonal eigenvectors v 1 ,... , vn having respective eigenvalues λ 1 ,... , λn, where the number of times μi occurs among the λj ’s exactly equals the multiplicity of μi.

Notice that if G is an undirected graph, then its random-walk matrix M is symmetric. We know that uM = u, so the uniform distribution is an eigenvector of eigenvalue 1. Let v 2 ,... , vn and λ 2 ,... , λn be the remaining eigenvectors and eigenvalues, respectively. Given any probability distribution π, we can write it as π = u + c 2 v 2 + · · · + cnvn. Then the probability distribution after k steps on the random walk is πM k^ = u + λk 2 c 2 v 2 + · · · + λkncnvn.

On Problem Set 2, you will show that all of the λi’s have absolute value at most 1. Notice that if they all have have magnitude strictly smaller than 1, then πM k^ indeed converges to u. Thus it is not surprising that our measure of mixing rate, λ(G), equals the absolute value of the second largest eigenvalue.

Lemma 11 Let G be an undirected graph with random-walk matrix M. Let 1 = λ 1 ≥ |λ 2 | ≥ |λ 3 | ≥ · · · ≥ |λn| be the eigenvalues of M. Then λ(G) = |λ 2 |.

Proof: Let u = v 1 , v 2 ,... , vn be the basis of orthogonal eigenvectors corresponding to the λi’s. Given any vector x ⊥ u, we can write x = c 2 v 2 + · · · + cnvn. Then:

‖xM ‖^2 = ‖λ 2 c 2 v 2 + · · · + λncnvn‖^2 = λ^22 c^22 ‖v 2 ‖^2 + · · · + λ^2 nc^2 n‖vn‖^2 ≤ |λ 2 |^2 · (c^22 ‖v 2 ‖^2 + · · · + c^2 n‖vn‖^2 ) = |λ 2 |^2 · ‖x‖^2

Equality is achieved with x = v 2.

Thus, bounding λ(G) amounts to bounding the eigenvalues of G. On Problem Set 2, you will prove:

Theorem 12 If G is a connected, nonbipartite, and regular undirected graph, then γ(G) = Ω(1/(dn)^2 )

Combining Theorem 12 with Corollary 9, we deduce Theorem 6. (The nonbipartite assumption in Theorem 12 can achieved by adding a self-loop to each vertex, which only increases the hitting time.) We note that the bounds presented in this lecture are not tight.

4 Markov Chain Monte Carlo

Random walks are a very widely used tool in the design of randomized algorithms. In particular, they are the heart of the “Markov Chain Monte Carlo” method, which is widely used in statistical