finding short cycles in planar graphs using separators

13
JOURNAL OF ALGORITHMS 7, 382-394 (1986) Finding Short Cycles in Planar Graphs Using Separators DANA RICHARDS Department of Computer Science, University of Virginia, Charlottesville, Virginia 22903 Received August lo,1984 There are many known O(n) time algorithms for detecting both a C, or a C, in a planar graph. We present 0( n log n) time algorithms for detecting both a C, or a C, in a planar graph. The algorithm uses a planar separator that is a small simple cycle. The problem is open for longer cycles and is known to be NP-complete for general c, . 0 1986 Academic Press. Inc. The literature on detection of cycles of arbitrary length has a long and varied history. However, we are concerned only with the problem of detecting cycles of a given length. It is well known that finding the longest cycle in a graph is a hard problem, since finding a Hamiltonian cycle is N&complete. Hence finding a cycle of length k, for an arbitrary k, is NP-complete. This remains true if G is planar and under other restrictions [4]. Finding the smallest cycle in a graph G is, however, solvable in polynomial time. Suppose G has n vertices and m edges. Itai and Rodeh presented an O(nm) worst-case algorithm and an O(n*) average time algorithm to find the smallest cycle in a graph [5]. Anstee [l] gave O(nm) algorithms for finding the shortest even or odd length cycle. Monien [lo] gave an O(nm) algorithm for the shortest odd cycle but gave a faster algorithm for even cycles. That algorithm runs in O(n*min{ A(n), e(G)}) time, where A(n) is the inverse Ackermann function and e(G) is the length of the shortest even cycle. Apparently finding the shortest even or odd cycle without chords is unsolved [12]. There have been several linear-time algorithms discovered for detecting the presence of a C,, a cycle of length 3, in an undirected planar graph G. These are clear improvements over algorithms for general graphs. Itai and Rodeh [5] gave three algorithms for finding C3’s in general graphs with 382 0196-6774/86 $3.00 Copyright 0 1986 by Academic Press. Inc. All rights of reproduction in any form reserved.

Upload: dana-richards

Post on 21-Jun-2016

214 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Finding short cycles in planar graphs using separators

JOURNAL OF ALGORITHMS 7, 382-394 (1986)

Finding Short Cycles in Planar Graphs Using Separators

DANA RICHARDS

Department of Computer Science, University of Virginia, Charlottesville, Virginia 22903

Received August lo,1984

There are many known O(n) time algorithms for detecting both a C, or a C, in a planar graph. We present 0( n log n) time algorithms for detecting both a C, or a C, in a planar graph. The algorithm uses a planar separator that is a small simple cycle. The problem is open for longer cycles and is known to be NP-complete for general c, . 0 1986 Academic Press. Inc.

The literature on detection of cycles of arbitrary length has a long and varied history. However, we are concerned only with the problem of detecting cycles of a given length. It is well known that finding the longest cycle in a graph is a hard problem, since finding a Hamiltonian cycle is N&complete. Hence finding a cycle of length k, for an arbitrary k, is NP-complete. This remains true if G is planar and under other restrictions [4]. Finding the smallest cycle in a graph G is, however, solvable in polynomial time. Suppose G has n vertices and m edges. Itai and Rodeh presented an O(nm) worst-case algorithm and an O(n*) average time algorithm to find the smallest cycle in a graph [5]. Anstee [l] gave O(nm) algorithms for finding the shortest even or odd length cycle. Monien [lo] gave an O(nm) algorithm for the shortest odd cycle but gave a faster algorithm for even cycles. That algorithm runs in O(n*min{ A(n), e(G)}) time, where A(n) is the inverse Ackermann function and e(G) is the length of the shortest even cycle. Apparently finding the shortest even or odd cycle without chords is unsolved [12].

There have been several linear-time algorithms discovered for detecting the presence of a C,, a cycle of length 3, in an undirected planar graph G. These are clear improvements over algorithms for general graphs. Itai and Rodeh [5] gave three algorithms for finding C3’s in general graphs with

382 0196-6774/86 $3.00 Copyright 0 1986 by Academic Press. Inc. All rights of reproduction in any form reserved.

Page 2: Finding short cycles in planar graphs using separators

FINDING CYCLES IN PLANAR GRAPHS 383

worst-case running times of O(m312), O(nm), and 0( n’), respectively, where b is determined by the bounds on Boolean matrix multiplication, b < 2.496. There is a linear time algorithm for detecting a C, in a planar graph [3]. For longer cycles the problem for planar graphs obviously gets harder.

Itai and Rodeh [5] were the first to give a linear-time algorithm for detecting a C,. They build a rooted spanning tree of the graph. It is an easy exercise to find a C, if one of its edges is also a tree edge. If no C, is fotmd delete the edges of the tree and iterate on the smaller graph. It was shown that this algorithm requires O(m3i2) time. However, for planar graphs, since at least a third of the edges are deleted on each iteration, the algorithm runs in O(n) time. Broder [2] independently discovered this approach and noted that it runs in O(n) time for all graphs of fixed genus.

Chiba and Nishizeki [3] present a C, algorithm which runs in O(a(G)m) time, where a(G) is the arboricity of G. (The arboricity is the minimum number of edge-disjoint forests into which G can be decomposed.) Since it is known that a(G) I 3 for planar graphs, the algorithm runs in O(n) time in that case. For general graphs the algorithm has O(m3i2) performance. We would like to describe the algorithm to contrast it to the next algorithm.

First, the vertices are ordered in decreasing order by degree. The node of largest degree looks to see if any of its neighbors are adjacent. (It does this via marking with its adjacency lists.) The node of largest degree is deleted and it iterates on the reduced graph. It is surprising this simple algorithm has such an elegant analysis. On subsequent iterations it need not be true the “node of largest degree” is such on the reduced graph. The analysis only requires that with respect to the original graph its degree was no smaller than its current neighbors. Hence the original ordering suffices and they do not need a “priority queue” structure as was used in the next example.

The C, problem for planar graphs appeared on a Stanford exam [14] and the following algorithm appeared as a solution. The node of smallest degree looks to see if any of its neighbors are adjacent. (It does this via a pseudo-adjacency matrix.) The node of smallest degree is deleted and it iterates on the reduced graph. The key is that in planar graphs the node of smallest degree has 5 or fewer neighbors. Two obstacles remain. First, a “priority queue” structure is used to ensure that only O(n) total time is spent selecting the nodes of smallest degree. Second, though O(n2) space is needed for an adjacency matrix, they use the standard trick to identify uninitialized entries to allow a reliable linear time access to all the O(n) initialized entries.

The two algorithms above are remarkably similar in their structure, considering their underlying principles are dissimilar. It is surprising that such, conceptually, simple algorithms are efficient at all; it is additionally

Page 3: Finding short cycles in planar graphs using separators

384 DANA RICHARDS

surprising that it does not matter if you iterate on the node of largest or smallest degree. Matula and Beck [8] have independently investigated other linear time graph algorithms based on what they call “smallest-last order- ing.”

An O(n) time algorithm for C,-detection in planar graphs is given in [3]. It is based on the same outline of repeatedly deleting the node of largest degree. It uses a straightforward marking approach to determine if the node of largest degree is a comer of a C,. The algorithm runs in O(a(G)m) time for general graphs; however, O(n’) algorithms have appeared in [13, lo], and [14].

A fourth linear time algorithm for finding a C, in planar graphs was given by Papadimitriou and Yannakakis [ll]. They begin with some breadth-first search division into levels of an embedded planar graph. During preprocessing they inventory, for each edge, those inter- and intra- level edges that are cyclically adjacent. All Cs’s are either faces of the embedding or span two adjacent levels and can be readily detected after the preprocessing phase. As stated their algorithm does not work but the correction can be inferred from the text of the paper.

In the balance of this paper we prove:

THEOREM 1. There exist algorithms for detecting both a C, and a C, in planar graphs in O(n log n) time.

It is open whether linear-time algorithms exist for these problems. We only solve the detection problem, whereas the papers cited above actually enumerate all Cs’s or all C4’s. For general graphs, our best efforts require O(n3) time to detect a C, or a C, [13].

THE GENERAL APPROACH FOR PLANAR GRAPHS

We use a divide-and-conquer approach which relies on the Lipton-Tarjan separator algorithm [6]. Our analysis is simplified if we use the improved separator theorem due to Miller [9]. A set of vertices C is a separator of a graph G if the n vertices of G can be partitioned into sets A, B, C such that no edge joins a vertex of A with a vertex of B, and further neither A nor B contains more than 2n/3 vertices. We say a circuit is a set of vertices such that the graph can be triangulated so that the vertices lie on a simple cycle.

THEOREM 2 ([9]). Euery planar gruph has a separator C which is either a single vertex or a circuit of no more than 41% vertices. Further the separator can be discovered in O(n) time.

Our statement of the theorem differs from the original in that we only need a circuit, not necessarily a cycle. This is easily accomplished by, in

Page 4: Finding short cycles in planar graphs using separators

FINDING CYCLES IN PLANAR GRAPHS 385

(b) FIG. 1. Ways a C, can straddle C.

U(n) time, triangulating an embedding of the planar graph for the parti- tioning algorithm. After A, B, C are found G is restored. We note that a careful reading of [6] shows their algorithm uses at most 3 circuits to form C.

The general scheme we will use is as follows. We partition the graph as described above, and recursively search for cycles in the planar subgraphs induced by A U C and B U C. If both searches fail, we try to find a cycle that “straddles” C with at least one vertex in both A and B. In this case C must be a circuit, not a single vertex. The possible cases for a C, are seen in Fig. 1 and for a C, they are shown in Fig. 2. We proceed by discovering enough short paths in A u C and B u C. Then we try to “marry” a path from either collection to form a cycle. We will show how to do this in linear time.

6)

Cd) (e) (f) (6)

FIG. 2. Ways a C, can straddle C.

Page 5: Finding short cycles in planar graphs using separators

386 DANA RICHARDS

Suppose that we can do all the nonrecursive computation in O(n) time, both the partition step and the cycle marriage step. Let T(n) be the time to detect a C, or a C, in an n vertex graph, then

T(n) I T(an + 46) + T((l - a)n + 4fi) + en

for some constant c and with 5 5 a I $. It is easy to show that T(n) = O(n log n) (cf. [7, p. 6231). This is a clear improvement over the best-known algorithms for general graphs which are O(n3). We end this section with two results we will need.

LEMMA 1. The number of paths (i, j, k) is O(n2) in a planar graph.

Proof; The paths can be counted by considering each possible j and choosing distinct adjacent vertices i and k. Clearly the total number of paths is bounded by

i dj I d,,2m = O(n2), j=l

where dj is the degree of vertex j and d,, = max{ d, }. It is well known that m I 3n - 6 for planar graphs, with n 2 3. 0

LEMMA 2. The number of paths (i, v, j), where i andj are in a subset C of the vertices of size p, is O(n + p*) in a planar graph.

Prooj: Let V be the vertex set. Without loss of generality remove all edges from the graph G that are not involved in such paths. If v is in C then both edges are in the planar subgraph induced by C. By Lemma 1 we see the number of such paths is O(p2). If v is in V\ C then both edges are in the bipartite planar subgraph induced by C and V\ C. If the degree of v is 2 then its contribution to the total is 1, and the total contribution of such v is O(n). Let G’ = (V’, E’) be that bipartite graph with all such v deleted. We can conclude

since it is well known that for bipartite planar graphs m I 2n - 4, when n 2 3. It follows that

IV’1 I 3p - 4.

By Lemma 1 the number of these paths in G’ is 0( p2). 0

Page 6: Finding short cycles in planar graphs using separators

FINDING CYCLES IN PLANAR GRAPHS 387

FIG. 3. Various short paths used to construct cycles.

THE MARRIAGE STEP FOR THE C, CASE

In this section we show the CS’s shown in Fig. 1 can be discovered in O(n) time. We begin by restricting our attention to the graph induced by A u C and conducting a census of all the paths of types a, b, and c as shown in Fig. 3. For example, an “u-path” consists of two distinct vertices, i and j, in C and another vertex u in A. Let M~[i, j] = u, where u is some such vertex in A; if no such u exists let u be a null value. Define M,b[i, j] and Mf;[i, j] similarly. After computing these matrices consider the graph induced by B U C and compute the analogous matrices M& Mj, and i&.

If we can compute the six matrices in linear time then we can detect straddling C,‘s in the following straightforward manner. Check if there is

Page 7: Finding short cycles in planar graphs using separators

388 DANA RICHARDS

procedure bPQthS (A )

for each edge (k.j). with k, j in C do

for each i in C do

if M.z[ i , k 1 is non-null then

M.$[i.jl +- (Mj[i.k].k)

FIGURE 4

an (i, j) such that &[I’, j] is nonnull and either M,b[i, j] or &[i, j] is nonnull or vice versa (i.e., with A and B interchanged.) Since C has O(6) vertices there are only O(n) entries in each matrix. We proceed by showing how to compute A4; in linear time.

Begin by forming for each vertex a C-list of all those adjacent vertices in C, preserving the cyclic ordering implied by the embedding. Create I& by beginning with a null matrix. Consider each u in A and for each distinct pair (i, i) from its C-list enter u into Mi[i, j] if it is null. Lemma 2 guarantees this approach terminates in O(n) time.

To compute MA we first determine M$ and then use the procedure in Fig. 4. (We assume for simplicity that if (j, k) is considered in the outer loop then later (k, j) is, too. Note the entries of Mj are edges.) This procedure runs in O(n) time since C contains O(6) vertices and there are only O(G) edges in the planar graph induced by C.

To compute it4: we would like to proceed, as we did for MA, by choosing each edge from within A and exhaustively combining the corresponding pair of C-lists. However, this might take O(n3/*) time as seen by the example in Fig. 5. Much time is wasted doing repetitious work; the edges (ui, v) and (uk, u) convey the same information. In fact we want to identify all such vertices adjacent to i as one new vertex.

“k

FIG. 5. The role of l-vertices in constructing c-paths.

Page 8: Finding short cycles in planar graphs using separators

FINDING CYCLES IN PLANAR GRAPHS 389

FIG. 6. A tree corresponding to the topology of the 3-vertices.

Formally, we begin with the planar graph G’ induced by A’ u C, where A’ contains those vertices of A adjacent to C. A vertex of A’ is called a l-, 2-, or 3-vertex if it is adjacent to 1, 2, or more vertices of C, respectively. We now label the vertices of G’. Label all those l-vertices adjacent to the same i with “i.” Label all those 2-vertices adjacent to the same i and j with “i, j.” Give each 3-vertex a new label.

LEMMA 3. G’ has O(\l;;) distinct labels.

Proof. Recall C contains O(h) vertices. Clearly the number of distinct labels for l-vertices is O(G). To see this true for the 2-vertices consider the graph formed from the vertices of C with an edge (i, j) if there is a 2-vertex between i and j. This graph must be planar (since it is “isomorphic to within vertices of degree 2” to a planar graph) and hence has O(\l;;) edges. This implies the same bound on the number of labels of 2-vertices.

To count the number of 3-vertices draw the forest as implied by the dotted lines in the example in Fig. 6. (Draw a line from each 3-vertex to any contained 3-vertex or to C’s circuit if there are none.) The number of leaves, of course, is bounded by the size of C. Since the degree of each tree vertex is 2 2 the number of internal nodes, and therefore the number of 3-vertices, is O(h). 0

We now compute I& by using the procedure in Fig. 7. Let G” be the graph formed from G’ by identifying those vertices with the same label and removing any loops and parallel edges. Let A” be the set vertices of G” apart from C. To establish the correctness of this procedure first note that an edge (u, a) in a c-path does not connect two l-vertices of G’ with the same label. If (u, u) connects two 2-vertices with the same label in G’ they must be consecutive vertices in the cyclic list of such vertices about, say i, in the planar embedding. The second for loop finds all such (u, u). All other

Page 9: Finding short cycles in planar graphs using separators

390 DANA RICHARDS

procedure cPaths (A )

form G’

for each pair of vertices i, j in C do

form a cyclic list of all “i, j” 2-vertices

for each (i.j) list do

if two consecutive vertices are adjacent then

update M,$[i. jl

form G”

for each edge (u,v) in A” do

for each i adjacent to u and j adjacent to v do

if i f j then

update Mi[i. j]

FIGURE I

edges (u, 0) in c-paths must be between distinctly labelled vertices of G’. Hence the edges of G” will be enough to fill out MAC.

THEOREM 3. The procedure cPaths runs in O(n) time.

Proof: Clearly we can form G’ and G” in linear time, using the C-lists to facilitate the labelling. The first for loop can be implemented in several ways, such as cyclically reading the adjacency lists of each i -z j in C, building several lists in one sweep. Such approaches are bounded by the number of edges in G’.

To analyze the final nest of for loops, consider the number of times the entry Mi[i, j] is updated. There are only a few ways this event could occur. The most interesting case is seen in Fig. 8; not all the vertices shown are necessarily present. Note that u, u’, U, u’, W, i’, j’ are the only candidates for endpoints of an edge causing an update. These can only be combined in a constant number of ways, some being mutually exclusive. Other embed- dings give rise to fewer cases. Since there are only O(n) entries, each updated a constant number of times, the last step and the entire procedure runs in O(n) time. Cl

In summary we now see how to find h4$ MT, and MAC, each in linear time. Similarly we get MS, Mj, and M& These matrices can be used as

Page 10: Finding short cycles in planar graphs using separators

FINDING CYCLES IN PLANAR GRAPHS 391

FIG. 8. Possible intermediate vertices for a c-path from i to j.

described above to allow a linear time marriage step leading to an 0( n log n ) time algorithm for C,-detection.

FINDING A C, IN PLANAR GRAPHS

Now we consider the more complicated case of detecting a C,. We proceed as before with the divide-and-conquer approach with a separator C. We then look for cycles that span both A and B as shown in Fig. 2. We proceed to find paths of the forms shown in Fig. 3. If these can be found and married in linear time we will have an 0( n log n) time algorithm. Cases (e) and (f) of Fig. 2 are considered together. Also cases (a) and (b) will be handled simultaneously.

We proceed as before with A U C and compute M;, Mj, and MAC. The only difference is that if M,b[i, j] = (u, k) and we find M,b[i, j] = (D’, k) then we could not conclude that we have a C, such as in Fig. 2e, since the vertex k is used twice. This is easily remedied by allowing the procedure bPaths to let each entry M,b[i, j] contain up to two edges with distinct values of k. With two b-paths to choose from a C, of the form (e) or (f) could not be missed. To complete Mj we use a procedure analogous to bPaths except it is based on M$ instead of MA.

The difficult step is to compute Ml, which subsumes the need for M; since we will allow w to be in C. We define G’ as before but also include in the vertex set the vertices, A*, adjacent to vertices in A’. A* may intersect A’ and C. G” is formed as before by collapsing similarly labelled vertices into one vertex. G” includes all those vertices in A* and A” (the set of collapsed vertices), but parallel edges resulting from the collapsing are ignored.

We will use the algorithm in Fig. 9 to compute MAf. It begins as we did before, by checking that the collapsing of 2-vertices did not lose any

Page 11: Finding short cycles in planar graphs using separators

392 DANA RICHARDS

procedure fPaths (A )

form G’

for each pair of vertices i, j in C do

form a cyclic list of all “i . j” 2-vertices

for each ( i . j> list do

for each 2-vertex Y on the (i. j) list do

begin

mark those vertices adjacent and “ahead” of v

if v adjacent to a marked vertex “behind” it then

update MA[i, j]

end

form G”

initialize T

for each w in A’ do

for each u and v adjacent to w, in A” do

if T[ u , VI is false then

begin

for each i adjacent u and j adjacent to Y do

if w # i # j f w then

update Md[i. j]

T[u.v] + zrw?

end

FIGURE 9

FIG. 10. An f-path sandwiched between 2-vertices.

Page 12: Finding short cycles in planar graphs using separators

FINDING CYCLES IN PLANAR GRAPHS 393

potential f-paths. Such a path must have a vertex w between two vertices u and ZJ with the same ‘7, j” label, and further, u and’u must be adjacent in the cyclic ordering of such vertices about, say, i. The process in the second for loop is diagrammed in Fig. 10. When we are at u we mark those vertices that are ahead of it (in the obvious sense) and when we are at u we look behind for an adjacent w that is marked.

After forming G”, we look for other f-paths in a very straightforward manner. The only trick is to use a test matrix T indexed by the vertices in A”. By Lemma 3 we know A” has O(h) vertices and hence T has O(n) elements. As each pair (u, u) is joined by some w the entry T[ u, u] reflects this event and the pair will not be used again. (This nonredundancy was accomplished automatically, so to speak, in the C, case since we do not have parallel edges.)

THEOREM 4. The procedure fPuths runs in O(n) time.

Proof. Again G’ and G” can be formed with the (i, i) lists in linear time. The second for loop is dominated by the sum of the degrees of the vertices on the various (i, i) lists. This, in turn is dominated by twice the number of edges which is O(n).

To analyze the final nesting of loops we need two observations. First, as before, the update operation is used, cumulatively, only O(n) times. The proof of this parallels the argument in the previous theorem; recall the T matrix removes potential redundancy.

How often is the test “T[u, u] is false” performed? Consider the graph formed from the edges from A” to A*. We get an embedding from the original embedding if we place the l-vertex “i ” where i (originally in C) was placed before, and place the 2-vertex “i, j ” on any of the original such vertices. It is easy to see that this gives you a planar embedding. Lemma 2 with A” as C, implies the test will be performed O(n + IA”(*) times. By Lemma 3 we see this shows the test is performed O(n) times and so the entire procedure runs in O(n) time. 0

So, as with the C, case, the above results lead to an O(n log n) algorithm for finding a C, in planar graphs. The next logical step, to C,, has resisted a similar approach with a linear time marriage step. For larger cycles the number of times a cycle crosses the circuit may grow, complicating the marriage step. We have not investigated this direction.

REFERENCES

1. R. P. ANSTEE, “Shortest Even Cycle Problem,” Research Report, No. CORR 84-7, Univ. of Waterloo, 1984.

2. A. Z. BRODER. Personal communication, 1983.

Page 13: Finding short cycles in planar graphs using separators

394 DANA RICHARDS

3. N. CHIBA AND T. NISHIZEKI, “Arboricity artd Subgraph Listing Algorithms,” SIAM J. Comput. 14 (1985), 210-223.

4. M. GAREY AND D. JOHNSON, “Computers and Intractability,” p. 217, Freeman, San Francisco, 1979.

5. A. ITAI AND M. RODEH, Finding a minimum circuit in a graph, SIAM J Compur. 7 (1978), 413-423.

6. R. LIPTON AND R. E. TARIAN, A separator theorem for planar graphs, SIAM J Appl. Murh. 36 (1979), 177-189.

7. R. LIPTON AND R. E. TARIAN, Applications of a planar separator theorem, SIAM J Compur. 9 (1980), 615-627.

8. D. W. MATULA AND L. L. BECK, Smallest-last ordering and clustering and graph coloring algorithms, J. Assoc. Compur. Mach. 30 (1983). 417-427.

9. G. L. MILLER, “Finding Small Simple Cycle Separators for 2Coaaected Planar Graphs,” pp. 376-382, Sixteenth Symp. Theory of Comp., 1984.

10. B. MONIEN, The complexity of determining a shortest cycle of even length, Compuring 31 (1983). 355-369.

11. C. PAPADIMIT~UOU AND M. YANNAKAKK, The clique problem for planar graphs, Inform. Proc. Lerr. 13 (1981), 131-133.

12. M. GR~T~CHEL AND W. R. PULLEYBLANK, Weakly bipartite graphs and the max-cut problem, Oper. Res. Lerr. 1 (1981) 23-27.

13. D. RICHARDS AND A. L. LIESTMAN, Finding cycles of a given length, Ann. Discrere Marh., 27 (1985). 249-256.

14. “1981 Analysis of Algorithms Qualifying Exam,” Stanford Univ. Stanford, Calif., Inter- nally published, Problem 3c.