<<

The Extended Longest Problem

(Nov 2009, Theory seminar) Problem definion

: Given an undirected graph, G = (V,E) and an integer k ≥ 0, does G have a simple path of length k?

 Extended Longest Path Problem: Given an undirected graph, G = (V,E) and an integer k ≥ 0, find all pairs of verces that have a simple path of length k between them.

(Note: 1. “length k” denotes edge‐length k (i.e. a simple path of length k has k edges. 2. The Longest Path Problem, and the Extended Longest Path Problem – both are NP‐complete. ) • This talk will be based on the following two papers:

[1] Color‐coding: Alon, Yuster, Zwick. [1995]

[2] Divide‐and‐color: Kneis, Molle, Richter, Rossmanith [2006] • We shall look at three approaches to solve the Extended Longest Path problem. 1. Method of Random Orientaons [Alon et al.]

2. Color‐coding [Alon et al.]

3. Divide‐and‐color [Kneis et al.] Method of Random Orientaons

• Movaon for the method

• Consider , A of G = (V,E).

A has 0/1 entries (we’ll interpret them as integers). Now, A[i][j] ≠ 0 ⇒ there exists an edge between verces, i and j in the graph. • Movaon for the method

Consider matrix, A2 = A × A.

2 → there exists a path of length 2 between A [i][ j] ≠ 0 verces, € i and j.

Generalizing, we can say:‐ € there exists a path of length Ak[i][ j] ≠ 0 → k between verces i and j.

€ • Movaon for the method

• Each entry in the matrix, corresponds to a path of Ak length k. • Queson: Do entries of correspond to Ak simple paths of length k€?

• In other words, is the following statement true: € k there exists a A [i][ j] ≠ 0 → simple path of length k between verces, i and j. (?).

€ • Movaon for the method

Answer: No.

Remarks: 1. The paths represented by the matrix entries may contain cycles. Hence the statement is not true. 2. If the statement were true, we would have already solved in polynomial me the NP‐complete problem we out to solve (and hence it is not true). • Movaon for the method

• Simple Idea: If the graph itself did not have cycles, then all paths in the graph would be simple. Hence, we could then use the matrix, of that graph, Ak to find all pairs of verces having simple paths of length k between them. € • Movaon for the method

• Queson: How do we convert the given graph G=(V,E) into an acyclic graph?

• Soluon: Convert G into a . Method of Random Orientaons

• Idea

• Take a random permutaon, π : V → {1, …, |V|} of the Set, V of G.

• Orient each edge {i,j} of E from i to j iff π(i) < π(j).

Remark: By orienng edges in this manner, all cycles in the original graph get broken. Method of Random Orientaons

• Method:

• Call the directed acyclic graph obtained from G

as Ga .

• Let B be the adjacency matrix of Ga . Method of Random Orientaons

• Method k • there exists a simple path of B [i][ j] ≠ 0 →

length k between verces i and j in Ga. • This in turn implies that there exists a simple path of length k between verces i and j in the € original graph, G. Method of Random Orientaons

• Method

• Queson: Are all simple paths of G preserved in Ga ? (Suppose p is a simple path in G; do the edges forming p form a simple path in Ga ? )

• Answer: No. Method of Random Orientaons

• Method

• Example: Method of Random Orientaons

• Method

• Given a simple path, p in G of length k. What is

the probability that p is preserved in Ga ? • Answer: 2/ (k+1)!

• Therefore, we need to repeat the with an expected number of O( (k+1)!) permutaons to find all k‐length simple paths of G. Method of Random Orientaons

• We can now state the algorithm. • Input: undirected graph, G=(V,E), integer k ≥ 0. • Repeat (k+1)! / 2 mes. 1. Take a random permutaon, π and convert G into a directed acyclic graph based on π. 2. Compute to find all pairs of verces having a Bk simple path of length k between them under permutaon π.

€ Method of Random Orientaons

• Running Time • For a parcular permutaon, π – compung k takes B O(log k) matrix mulplicaons, each taking me. O(V ω ) • We repeat the same for (k+1)! permutaons. € • Running me: O( (k+1)! poly(V,E,k) ) € Color‐coding

• Movaon for color‐coding:‐

• Random orientaons method has a (k+1)! term in the running me. Color‐coding

• Idea

• Color each vertex in the vertex set of input graph G with one color from a set of colors. • Instead of trying to find a simple path, try to find a “colorful path” in the colored graph. Color‐coding

• Idea • Colorful path: A path in which each vertex along the path has a disnct color. • Example: Color‐coding • Idea • A colorful path is necessarily simple.

Therefore, if we find that there exists a colorful path of length k, between verces u and v in the colored graph, then there exists a simple path of length k between u and v in the original graph. Color‐coding

• Our aim now is to find a colorful path of length k in a colored graph. • Input: Colored graph G=(V,E) [each vertex is colored with one color from a set of (k+1) colors], integer k ≥ 0. • To find: All pairs of verces in V having a colorful path of length k between them. Color‐coding • Finding colorful paths in a colored graph • Simple algorithm (This algorithm finds all verces, v such that there is a colorful path of length k between v and a disnguished start vertex, s.) • i.e. Input: colored graph G=(V,E), integer k ≥ 0, start vertex, s ∈V. Color‐coding • Dynamic Programming algorithm • Idea/Example • Suppose we have a colorful path of length, 3 from s to some vertex, v.

• Now, suppose we wish to extend the path to vertex x (assuming edge {v3,x} exists). • We need to ensure that color(x) is disnct from all 4 colors present in the current path. Color‐coding • Idea behind dynamic programming algorithm

(1) In order to extend a path of length i into a path of length i+1, we need to know the set of colors used up so far in the path of length i. Color‐coding • Idea behind dynamic programming algorithm • Example:

• We want to extend ll vertex x, the colorful path of length 3 from s to v3. • Now, the colorful path s – v1 – v2 –v3 cannot be extended to x, while the colorful path s – v5 – v4 – v3 can. Color‐coding • Idea behind dynamic programming algorithm • Example:

• (We have 2 colorful paths from s to v3, which we want to extend to vertex x.) • Since we are only interested in the color‐set used in the current path, and not its actual verces, we do not to store different paths having idencal color‐sets. • Storing only disnct color‐sets will suffice. Color‐coding • Idea behind dynamic programming algorithm

(2) For proceeding from a colorful path of length i to one of length i+1, for each vertex, v we will store all sets of colors that are present on colorful path(s) of length i between s and v. • There can be at most C(k+1,i+1) = (k+1)! / ( i+1)! * (k‐i)!) such colors sets for each vertex v. Color‐coding • Idea behind dynamic programming algorithm • At any iteraon, we take all colorful paths of length i ( 0≤ i ≤ k‐1), and try to extend them to obtain colorful paths of length i+1. • We start with colorful paths of length 0. (The vertex, “s” is the only such path.) • At the end of the iteraon (for proceeding from paths ith . of length (i‐1) to i, for each vertex v ∈V, we store:‐ All color‐sets in colorful paths of length i‐1 from s to v. (Note: Each color‐set would have exactly € i colors; and there can be at most C(k+1,i) such color‐sets. ) Color‐coding • Dynamic Programming algorithm • Proceeding from ith iteraon to (i+1)th iteraon:‐ • Consider a vertex, v ∈V. • Compare color(v) with each of the color‐sets (each having i colors) of each of it’s neighbors. • All color‐sets (having i+1 colors that result in a colorful path of length i from s to v, now form the collecon of color‐sets of v aer iteraon i+1.) • Repeat the above 2 steps for every vertex in V. Color‐coding

• At the end of the algorithm: If there exists at least one color‐set for any vertex, v (corresponding to colorful paths of length k), then there exists a colorful path of length k between s and v.

Converse is also true. Color‐coding • Dynamic Programming algorithm • Running me: • At each iteraon: O( C(k+1,i)*i*E) • Therefore, running me over all iteraons is: k k , which is . O(∑C(k +1,i)*i * E) O(k *2 * E) i=1

€ The above is for finding colorful paths from a parcular € start vertex, under a given coloring. • We repeat the above procedure once for each vertex. • Therefore, running me is . O(k *2k *V * E)

€ Color‐coding • Queson: Are all simple paths of length k in the (uncolored) input graph G, preserved under a random coloring of the verces of G (using k+1 colors)? • i.e. If p is a simple path in original graph G, does it become a colorful path in the colored graph obtained from G? Color‐coding

• Answer: No.

• Example:

• Take k=3. Path s – v1 – v2 – v3 does not become a colorful path under the given coloring. Color‐coding

• Queson: What is the probability that any given path, p of length k in original graph G, gets converted into a colorful path under a random coloring (of verces of G using k+1 colors)?

• Answer: (k +1)!/(k +1)k+1 > e−(k+1)

(The inequality is obtained using Srling’s formula.)

€ Color‐coding

• Hence the dynamic programming algorithm needs to be repeated an expected number of mes. O(ek+1)

€ • Therefore, running me is: O((2e)k * poly(V,E,k))

€ Divide‐and‐color

• Extended Longest Path Problem: Given an undirected graph, G=(V,E) and integer k ≥ 0; find all pairs of verces having a simple path consisng of k nodes between them.

. (Note: A simple path of k nodes has length k‐1. We use number of nodes (instead of number of edges) here, for simplicity in calculaons.) Divide‐and‐color

• Idea behind this approach . Divide‐and‐conquer algorithm. . Color each vertex of input graph G, either Black or White. (Color the verces independently at random.) . In the subgraph induced by Black verces, find all pairs of verces having simple paths of k/2 nodes between them. . In the subgraph induced by White verces, find all pairs of verces having simple paths of k/2 nodes between them. . Combine the two soluons to get soluon to original problem. Divide‐and‐color Divide‐and‐color

• We can directly state the algorithm. . Algorithm L (G,k):  If k=1, return { (v,v) | v ∈V }.  Else: Repeat the following mes. 3*2k  Randomly & independently color the verces of V either Black or White. (Let V1 be set of Black verces, and V2 be the set of White verces.) €  Add pair (u,v) to L(G,k) iff (u,x) ∈ L (G[V1],k /2) and (y,v) ∈ and {L(G[V2],k /2) x,y} is an edge in G (for some verces, x and y.).  Return all pairs (u,v) that are in L(G,k). € € Divide‐and‐color

• If the algorithm returns a pair (u,v), then it means that there exists a simple path of k nodes between u and v. • What if the algorithm does not return the pair (u,v)? • What is the probability that the algorithm does not return pair (u,v) even when there exists a simple path of k nodes between u and v? Divide‐and‐color

• Error Probability • Suppose there exists a simple path, say p, of k nodes between verces u and v. Let be the probability pk that Algorithm L does not return pair (u,v).

€ • We will prove that . pk ≤1/4

€ Divide‐and‐color

• Error Probability

. For path p = , to be found: < v1 − v2 − ...− vk > . the first nodes of k /2 p must be Black (Pr= ), 2−k / 2 . AND last nodes of k /2 p must be White (Pr= ), 2−k / 2 (v ,v ) . AND should find pair , €L (G[V1],k /2) 1 k / 2 € (v ,v ) . AND should find pair . L(G[V1],k /2) € k / 2+1 k € Therefore, € k p ≤ [(1− 2−k ) + 2−k *(p + p €)] 3.2 € k k / 2 k / 2 € €

€ Divide‐and‐color

• Error Probability (Proof by inducon on k) • Simplifying, we get:

−k −k 3.2k pk ≤ [(1− 2 ) + 2 *2* pk / 2]

k → −k −k 3.2 pk ≤ [(1− 2 ) + 2 *2*(1/4)]

p ≤ e−3 / 2 <1/4 € → . k € € Divide‐and‐color

• Running me: • Let denote the number of recursive calls issued by L. Tk • For each of the iteraons: 3*2k  The “combining step” [adding pair (u,v) to L(G,k) if € (u,x) ∈ L and ((G[V1],k /2) x,v) ∈ ] L(G[V1],k /2) € takes me polynomial in V and E.  We have, T ≤ 3*2k *(T + T ) € k k / 2 k /€2

€ Divide‐and‐color

• Running me: • Simplifying, we get:

k Tk ≤ 3*2 *2*Tk / 2 Opening up the recurrence relaon, we get:

T ≤ (6*2k )*(6*2k / 2)*(6*2k / 2/ 2)... € k

€ Divide‐and‐color

• Running me: k k / 2 k / 2/ 2 • We have, Tk ≤ (6*2 )*(6*2 )*(6*2 )... • Using the fact that: k + k /2+ k /2/2+ ...+1≤ 2k + log k we get:‐ T = O(3log k * k 2 * 4 k ), which is O(k log 3 * k 2 * 4 k ) €k € • Hence the running me of the algorithm is O(4 k * poly(V,E,k)). €

€ We looked at 3 approaches for solving the Extended Longest Path problem: • Random Orientaons

• Color‐coding

• Divide‐and‐color Further applicaons of these methods

• Finding of length k. • Finding simple path/cycle of length k in directed graphs. • Graph Packing Problem: Given graphs G and H, a number k; are there k vertex‐disjoint copies of H in G? • Graph Edge‐Packing Problem: Are there k edge‐disjoint copies of H in G? Acknowledgements

I am grateful to:‐

. Prof. Piotr Berman. (For introducing our Randomized class to these 2 papers.) . Prof. Sofya Raskhodnikova. (For help in preparing for the talk.) • The methods developed in both of these papers were effecve as well as amazingly simple. • “It is a rare mind indeed that can render the hitherto non‐existent blindingly obvious. The cry “I could have thought of that” is a very popular and misleading one; for the fact is that they didn’t, and a very significant and revealing fact it is too.” – Douglas Adams.

Thank you!