An Õ m 2 n Randomized Algorithm to compute a Minimum Cycle Basis of a Directed Graph

Similar documents
Algorithms to Compute Minimum Cycle Basis in Directed Graphs

Acyclic Digraphs arising from Complete Intersections

A Polynomial Time Algorithm for Minimum Cycle Basis in Directed Graphs

ACYCLIC DIGRAPHS GIVING RISE TO COMPLETE INTERSECTIONS

Preliminaries and Complexity Theory

ALTERNATING KNOT DIAGRAMS, EULER CIRCUITS AND THE INTERLACE POLYNOMIAL

Notes on Systems of Linear Congruences

Discrete Wiskunde II. Lecture 5: Shortest Paths & Spanning Trees

Timetabling and Robustness Computing Good and Delay-Resistant Timetables

On the Exponent of the All Pairs Shortest Path Problem

* 8 Groups, with Appendix containing Rings and Fields.

Shortest paths with negative lengths

CSE 206A: Lattice Algorithms and Applications Spring Basic Algorithms. Instructor: Daniele Micciancio

Cost-Constrained Matchings and Disjoint Paths

CSE 591 Foundations of Algorithms Homework 4 Sample Solution Outlines. Problem 1

NATIONAL UNIVERSITY OF SINGAPORE CS3230 DESIGN AND ANALYSIS OF ALGORITHMS SEMESTER II: Time Allowed 2 Hours

Algorithms (II) Yu Yu. Shanghai Jiaotong University

1 Matchings in Non-Bipartite Graphs

Single Source Shortest Paths

Week 4. (1) 0 f ij u ij.

Reverse mathematics of some topics from algorithmic graph theory

Chapter 7 Network Flow Problems, I

Algebra. Modular arithmetic can be handled mathematically by introducing a congruence relation on the integers described in the above example.

1 Some loose ends from last time

Math/Phys/Engr 428, Math 529/Phys 528 Numerical Methods - Summer Homework 3 Due: Tuesday, July 3, 2018

HOMEWORK #2 - MATH 3260

On the adjacency matrix of a block graph

Lecture 7. Econ August 18

CMPS 2200 Fall Carola Wenk Slides courtesy of Charles Leiserson with small changes by Carola Wenk. 10/8/12 CMPS 2200 Intro.

Unit 2, Section 3: Linear Combinations, Spanning, and Linear Independence Linear Combinations, Spanning, and Linear Independence

ACO Comprehensive Exam October 14 and 15, 2013

Questionnaire for CSET Mathematics subset 1

NOTE: You have 2 hours, please plan your time. Problems are not ordered by difficulty.

NOTES ON SIMPLE NUMBER THEORY

Packing and Covering Dense Graphs

Index coding with side information

Algebraic Methods in Combinatorics

ACO Comprehensive Exam 19 March Graph Theory

Algebraic Methods in Combinatorics

14.1 Finding frequent elements in stream

Classical Complexity and Fixed-Parameter Tractability of Simultaneous Consecutive Ones Submatrix & Editing Problems

MAT 243 Test 2 SOLUTIONS, FORM A

Discrete Optimization 2010 Lecture 2 Matroids & Shortest Paths

1 Counting spanning trees: A determinantal formula

William Stallings Copyright 2010

Induction and Recursion

THE UNIVERSITY OF TORONTO UNDERGRADUATE MATHEMATICS COMPETITION March, 2005

Analysis of Algorithms. Outline. Single Source Shortest Path. Andres Mendez-Vazquez. November 9, Notes. Notes

Chapter Summary. Mathematical Induction Strong Induction Well-Ordering Recursive Definitions Structural Induction Recursive Algorithms

Preliminaries. Graphs. E : set of edges (arcs) (Undirected) Graph : (i, j) = (j, i) (edges) V = {1, 2, 3, 4, 5}, E = {(1, 3), (3, 2), (2, 4)}

Packing and decomposition of graphs with trees

chapter 12 MORE MATRIX ALGEBRA 12.1 Systems of Linear Equations GOALS

Discrete Math, Second Problem Set (June 24)

Ir O D = D = ( ) Section 2.6 Example 1. (Bottom of page 119) dim(v ) = dim(l(v, W )) = dim(v ) dim(f ) = dim(v )

MATHEMATICAL OBJECTS in

Induction and recursion. Chapter 5

Fraction-free Row Reduction of Matrices of Skew Polynomials

Conceptual Questions for Review

Know the Well-ordering principle: Any set of positive integers which has at least one element contains a smallest element.

ANALYTICAL MATHEMATICS FOR APPLICATIONS 2018 LECTURE NOTES 3

Single Source Shortest Paths

On the number of cycles in a graph with restricted cycle lengths

MATHEMATICAL ENGINEERING TECHNICAL REPORTS

FRACTIONAL PACKING OF T-JOINS. 1. Introduction

ON COST MATRICES WITH TWO AND THREE DISTINCT VALUES OF HAMILTONIAN PATHS AND CYCLES

[06.1] Given a 3-by-3 matrix M with integer entries, find A, B integer 3-by-3 matrices with determinant ±1 such that AMB is diagonal.

MA015: Graph Algorithms

CS Data Structures and Algorithm Analysis

Approximation algorithms for cycle packing problems

Linear Systems of n equations for n unknowns

Determinant of the distance matrix of a tree with matrix weights

Design and Analysis of Algorithms

CSE 206A: Lattice Algorithms and Applications Winter The dual lattice. Instructor: Daniele Micciancio

Breadth First Search, Dijkstra s Algorithm for Shortest Paths

CMPS 6610 Fall 2018 Shortest Paths Carola Wenk

Reduction of Smith Normal Form Transformation Matrices

STABLE MARRIAGE PROBLEM WITH TIES AND INCOMPLETE BOUNDED LENGTH PREFERENCE LIST UNDER SOCIAL STABILITY

25.1 Markov Chain Monte Carlo (MCMC)

A combinatorial algorithm minimizing submodular functions in strongly polynomial time

Linear Algebra Massoud Malek

A Note On Minimum Path Bases

An Analytic Approach to the Problem of Matroid Representibility: Summer REU 2015

Homework #2 Solutions Due: September 5, for all n N n 3 = n2 (n + 1) 2 4

Lecture 2: Divide and conquer and Dynamic programming

A Review of Matrix Analysis

Product distance matrix of a tree with matrix weights

Rings. EE 387, Notes 7, Handout #10

Jim Lambers MAT 610 Summer Session Lecture 2 Notes

CSE 431/531: Analysis of Algorithms. Dynamic Programming. Lecturer: Shi Li. Department of Computer Science and Engineering University at Buffalo

= 1 2x. x 2 a ) 0 (mod p n ), (x 2 + 2a + a2. x a ) 2

Modern Algebra Prof. Manindra Agrawal Department of Computer Science and Engineering Indian Institute of Technology, Kanpur

Definition A finite Markov chain is a memoryless homogeneous discrete stochastic process with a finite number of states.

Relation of Pure Minimum Cost Flow Model to Linear Programming

VARIETIES WITHOUT EXTRA AUTOMORPHISMS I: CURVES BJORN POONEN

The Strong Largeur d Arborescence

HW2 Solutions

Linear Algebra. Min Yan

Homework #2 solutions Due: June 15, 2012

Math 121 Homework 5: Notes on Selected Problems

On the Splitting of MO(2) over the Steenrod Algebra. Maurice Shih

Transcription:

An Õ m 2 n Randomized Algorithm to compute a Minimum Cycle Basis of a Directed Graph T Kavitha Indian Institute of Science Bangalore, India kavitha@csaiiscernetin Abstract We consider the problem of computing a minimum cycle basis in a directed graph G The input to this problem is a directed graph whose arcs have positive weights In this problem a 0 incidence vector is associated with each cycle and the vector space over generated by these vectors is the cycle space of G A set of cycles is called a cycle basis of G if it forms a basis for its cycle space A cycle basis where the sum of weights of the cycles is minimum is called a minimum cycle basis of G The current fastest algorithm for computing a minimum cycle basis in a directed graph with m arcs and n vertices runs in Õ m ω n time (where ω 2 376 is the exponent of matrix multiplication) If one allows randomization, then an Õ m 3 n algorithm is known for this problem In this paper we present a simple Õ m 2 n randomized algorithm for this problem The problem of computing a minimum cycle basis in an undirected graph has been well-studied In this problem a 0 incidence vector is associated with each cycle and the vector space over 2 generated by these vectors is the cycle space of the graph It is not known if an efficient algorithm for undirected graphs automatically translates to an efficient algorithm for directed graphs The fastest known algorithm for computing a minimum cycle basis in an undirected graph runs in O m 2 n mn 2 logn time and our randomized algorithm for directed graphs almost matches this running time Introduction Let G V A be a directed graph with m arcs and n vertices A cycle C in G consists of forward arcs C and backward arcs C such that C C C and reorienting all arcs in C results in a closed path Associated with each cycle is a 0 vector, indexed on the arc set A This vector, also called C, is defined as follows For each arc a A if a is a forward arc of C C a if a is a backward arc of C 0 if a! C " # The cycle space of G is the vector space over that is generated by the incidence vectors of cycles in G When G is connected, the cycle space has dimension d m n A cycle basis of G is a basis of the cycle space of G The arcs of G have positive weights assigned to them A cycle basis where the sum of the weights of the cycles is minimum is called a minimum cycle basis of G In this paper we consider the problem of computing a minimum cycle basis in a given digraph Background The problem of computing a minimum cycle basis in a graph is well-studied Apart from its interest as a natural question, it is motivated by its use as a preprocessing step in several algorithms That is, a cycle basis is used as an input for a later algorithm, and using a minimum cycle basis instead of any arbitrary cycle basis usually reduces the amount of work that has to be done by this later algorithm Such

algorithms include algorithms for diverse applications like structural engineering [4], cycle analysis of electrical networks [5], and chemical ring perception [7] And in many cases the network graphs of interest are directed graphs The problem of computing a minimum cycle basis in a directed graph is related to the problem of computing a minimum cycle basis in an undirected graph In an undirected graph U N E, with each cycle C we associate a 0 incidence vector x, indexed on E, where x e if e is an edge of C, x e 0 otherwise The vector space over 2 generated by these vectors is called the cycle space of U A minimum cycle basis of U is a set of linearly independent (over 2) cycles that span the cycle space of U and whose sum of weights is minimum For a directed graph G, we obtain the underlying undirected graph of G by removing the directions from the arcs A set of cycles C C d of G projects onto an undirected cycle basis, if by removing the orientations of the arcs in the cycles, we obtain a cycle basis for the underlying undirected graph If C C C d is a set of cycles in a directed graph G that projects onto an undirected cycle basis, then C is a cycle basis of G But the the converse is not true Similarly, a minimum cycle basis of a digraph need not project onto a cycle basis of the underlying undirected graph The Appendix contains such examples The books by Deo [6] and Bollobás [3] have an in-depth coverage of the subject of cycle bases Previous Results Algorithms for computing a minimum cycle basis in undirected graphs have been well-studied [2, 5, 9, 0, 2] and the current fastest algorithm for this problem runs in O m 2 n # mn 2 logn time [2], where m is the number of edges and n is the number of vertices The first polynomial time algorithm for computing a minimum cycle basis in a directed graph had a running time of Õ m 4 n [] Liebchen and Rizzi [5] gave an Õ m ω n algorithm for this problem, where ω 2 376 is the exponent of matrix multiplication This is the current fastest deterministic algorithm known for this problem But faster randomized algorithms are known Kavitha and Mehlhorn [] gave an Õ m 3 n Monte Carlo algorithm for this problem Algorithms for cycle bases of directed graphs have also been studied in [3, 4, 8] The focus in these papers is on special classes of cycle bases, like integral cycle bases [3, 4] - these are cycle bases whose d m cycle-arc incidence matrix has the property that its regular d d submatrices have determinant (such cycle bases of minimum length are important in cyclic timetabling) In [8] algorithms for computing cycle bases in strongly connected digraphs that consist of cycles which always follow the directions of the arcs (these cycles have no backward arcs) were studied Such cycle bases are of particular interest in metabolic flux analysis 2 What is new? In this paper we present a simple O m 2 nlog n randomized algorithm to compute a minimum cycle basis in a directed graph G with m arcs and n vertices This algorithm always returns a cycle basis and we show that with high probability this cycle basis is a minimum cycle basis We obtain this algorithm through an effective use of randomization, which enables us to work entirely over the finite field p for a randomly chosen prime p instead of working over " We recall here that the Õ m 3 n randomized algorithm given in [] works by sampling log 2 m random primes independently in each iteration of the algorithm Then the algorithm either uses at least logm suitable primes from this sample to compute cycles in that iteration or it quits if there is no large enough subset of suitable primes in this sample In Section 2 we first present a deterministic algorithm, whose correctness is simple to show But the numbers used in this algorithm grow very large and so this algorithm is not interesting from an implementation point of view However, the analysis of this algorithm leads to our efficient randomized algorithm Section 22 contains our randomized algorithm and its analysis 2

A key step in our algorithm is a subroutine to compute a shortest cycle whose inner product with a given vector is nonzero modulo p Such a subroutine was also used in [] and we first review that method in Section 3 However that subroutine is not good enough for us since using it would make the running time of our algorithm Õ m 4 n Here we modify Dijkstra s algorithm for this particular problem and improve this subroutine Section 32 contains this implementation This leads to an O m 3 # m 2 nlog n randomized algorithm for computing a minimum cycle basis in a directed graph We can improve the running time even further As mentioned earlier, the current fastest algorithm for computing a minimum cycle basis in an undirected graph has a running time of O m 2 n # mn 2 log n This running time is achieved through the use of fast matrix multiplication to speed up certain operations on vectors In Section 4 we use the same technique to get rid of the m 3 term in our running time and we thus get an O m 2 nlogn algorithm 2 An Õ m 3 randomized algorithm Our algorithm is broadly based on the approach used in [5, 2, 2, ] for computing a minimum cycle basis We are given a digraph G V A, where V n and A m There is no loss of generality in assuming that the underlying undirected graph of G is connected Then d m n # is the dimension of the cycle space of G The notation v v 2 denotes the standard inner product or dot product of the vectors v and v 2 First we will assume that we have ordered the arcs in the arc set A so that the arcs a d a m form the edges of a spanning tree T of the underlying undirected graph This means that in the incidence vector representation of cycles, the first d coordinates correspond to arcs outside the tree T and the last n coordinates are the arcs of T Before we present our randomized algorithm, let us first consider the following deterministic algorithm The deterministic algorithm is not an efficient algorithm and we are not interested in its computational complexity But its analysis leads to our randomized algorithm, which is presented in Section 22 2 Deterministic-MCB Initialize the vectors S S d of " m to the first d vectors e e d of the standard basis of " m (The vector e i has in the i-th position and 0 s elsewhere) 2 For i to d do compute C i to be a shortest cycle such that C i S i 0 for j i # to d do update S j as: S j S j S i C i S j C i S i Lemma For i d the above algorithm maintains the following invariant: at the end of the i-th iteration the vectors S i S d are orthogonal to the cycles C C i C Proof We will prove this by induction on i At the end of the first iteration S j S j S S j C S j 2 d The inner product C S j C S j C S 0 C S j C S for each This proves the base case Suppose the above invariant is maintained till the end of iteration k So at the beginning of the k # -th iteration S k S d are orthogonal to C C k After the update step 3

of the k # -th iteration, it is easy to see that S k 2 S d are orthogonal to C k But each of the new S k 2 S d is a linear combination of the corresponding old S k 2 S d and S k - but all these vectors are already orthogonal to C C k Hence their linear combinations are also orthogonal to C C k Thus we maintain our invariant at the end of the k # -th iteration It is easy to see that the set C C d is a minimum cycle basis Theorem The set C C d is a minimum cycle basis of G Proof (from [5, ]) Suppose C C d does not form a minimum cycle basis Then there exists a minimal i such that C C i any minimum cycle basis So C C i some minimum cycle basis C Then C i λ K # λ 2 K 2 # # λ l K l for some K K l C and λ λ l " and each λ t 0 Since S i C i 0 K t K K l such that S i K t 0 Then by the very definition of C i, it follows that weight K t weight C i Hence C C C i K t is also a minimum cycle basis The cycle K t that has been omitted from C cannot be one of C C i since the inner product of each of C C i with S i is zero whereas S i K t 0 Hence, C C i C, which is a minimum cycle basis - a contradiction Let us now understand the structure of the vectors S j in Deterministic-MCB The vector S j gets updated in each iteration till iteration j Call the version of S j at the beginning of iteration i as S i j And S j j is finally used in iteration j to compute the cycle C j (Let us denote the final version S j j by S j itself) S i j has the form r r 2 r i 0 0 0 0, where r r i are some rational numbers and the occurs in the j-th coordinate Since S i j is orthogonal to C C i, we have C k r r i 0 0 T 0 for k i Let the incidence vector of C k be c k c km and let C k be the restriction of this vector to its first i coordinates Then r r i is a solution to C k x x i T c k j for k i () We will show that this set of equations has a unique solution Suppose the linear combination i α j C j 0 (2) j and not all α j are 0 Then consider the largest t such that α t 0 and take the inner product of both sides of Equation (2) with S t, where S t is the restriction of the vector S t to its first i coordinates Then the left hand side is t k α k C k S t t k α k C k S t since S t has all the non-zero entries of S t for each t i This is equal to α t C t S t since C k S t 0 for k t Since C t S t 0 and the right hand side is 0 we get α t 0 - a contradiction Hence each α k has to be 0 for k i So the C k s are linearly independent So we can conclude the following lemma Lemma 2 The i i matrix M i whose k-th row is the vector C k for k i is nonsingular Thus Equation () has a unique solution, which is r r i By Cramer s rule, each r l is of the form r l y l! k i, where k i is the determinant of M i and y l is the determinant of the matrix obtained by replacing the l-th column of M i by the vector on the right hand side of Equation () So multiplying S i j with k i gives us an integral vector N i j y y i 0 k i 0 Since k i is the determinant of an i i 4

matrix whose entries are 0, it follows from Hadamard s inequality that k i i 2 Similarly, i the absolute value of each y l is bounded from above by i 2 So we have i N i i i 2 d d 2 since i d Let us denote each N j j by N j, respectively Definition Call a prime p good if for each i d: C i N i is not good i 0 mod p Call a prime p bad if it Lemma 3 Let P be a set of d 2 primes, each of which is at least d 2 Then at least 3! 4-th of the set P is good Proof For any i, C i S i 0 is equivalent to C i N i 0 since N i k i S i and k i det M i 0 by Lemma 2 So for each i d, it holds that C i N i 0 Since C i is a 0 vector we also get that C i N i N i So C i N i d d 2 Since N S 0 0, the number C N is always So no prime can divide it For i 2, we will use 0 C i N i d d 2 Since each prime in P is at least d 2, at most d #! 4 elements in P can be divisors of C i N i So the number of primes in P that can divide at least one of C 2 N 2 C 3 N 3 C d N d is at most d d #! 4 Hence the fraction of bad primes in P is at most d d #! 4d 2! 4 Now we present the algorithm Randomized-MCB This is similar to Deterministic-MCB But here we work over the field p for a randomly chosen prime from the set P, instead of working over " 22 Randomized-MCB Compute a set P of d 2 primes p 0 p where each p j d 2 Choose a prime p uniformly at random from this set 2 Initialize the vectors X X d of m p to the first d vectors of the standard basis e e d 3 For i to d do compute B i to be a shortest cycle such that B i X i 0 mod p for j i # to d do update X j (over the finite field p) as: X j X j X i B i X j B i X i (The proof of Lemma shows that X i X d are now orthogonal to B B i over We will now show that B B d is always a cycle basis Lemma 4 The cycles B B d are linearly independent Proof We know that B j X i 0 mod p for all j i It is now easy to see that B i is linearly independent of B B i over p X i is a witness of this linear independence since B j X i 0 mod p for each j i, so the inner product of X i with any linear combination of B B i has to be zero modulo p but B i X i 0 mod p Hence the whole set B B d is linearly independent over p, which means that it is linearly independent over " We will next show that the set B B d is a minimum cycle basis with probability at least 3! 4 Theorem 2 When p is good, Randomized-MCB computes a minimum cycle basis We will assume that the algorithm Deterministic-MCB breaks ties for the shortest cycle in the same way as Randomized-MCB breaks them That is, both the algorithms use the same rule to determine the shorter cycle between two cycles of equal weight Then we can show the following p) 5

Lemma 5 When p is good, B i C i, for each i d We will show this by induction The vector X S 0 0 The inner product of any cycle with 0 0 is or 0 The inner product will be if and only if the cycle contains the arc a Also, looking at the inner product modulo p does not change a or a to 0 So B is a shortest cycle that contains the arc a C is also a shortest cycle that contains the first arc a and so by our assumption that both these algorithms break ties identically, we have that B C Let us now assume that B j C j for j i N i is a vector in m of the form y y i k i 0 0, where y y i is the unique solution to C C i x k i c i k i c i i (3) where C j is the incidence vector of cycle C j restricted to its first i coordinates and k i det M i (recall that M i is the i i matrix above whose rows are C s) Note that y y i mod p is a solution to this set of equations in p X i is a vector in m p of the form x x i 0 and X i is orthogonal to B B i in p Since B j C j for j i, this means that X i is orthogonal to C C i in p So in p x x i is a solution to C C i x c i c i i So k i x x i mod p is a solution to Equation (3) in p We would like to prove that Equation (3) has a unique solution in p Lemma 6 If C j N j 0 mod p for j i, then k i 0 mod p Let us assume the above Lemma and complete the argument Then we will prove Lemma 6 Since det M i k i 0 mod p, Equation (3) should have a unique solution in p So k i x x i mod p y y i mod p In other words, k i x x i 0 0 mod p y y i k i 0 0 mod p That is, k i X i mod p N i mod p So N i is just a scalar multiple of X i when these vectors are viewed as elements of m p Hence for any cycle D D N i 0 mod p if and only if D X i 0 mod p Since p is a good prime, C i N i 0 mod p So C i X i 0 mod p Let K be any cycle such that K X i 0 mod p Then K N i 0 mod p, hence K N i 0 This is equivalent to K S i 0 So every cycle that satisfies K X i 0 mod p is also a candidate cycle of Deterministic-MCB in its i-th iteration Since C i was the shortest among all these cycles, we get that C i also has to be the shortest cycle for Randomized-MCB in its i-th iteration That is, B i C i This proves the induction step Proof of Lemma 6 We know that C j S l 0 for j l, so when we multiply the i m matrix whose rows are C s with the m i matrix whose columns are N s we get: C C i N T NTi C N 0 0 0 C 2 N 2 0 0 C 3 N 3 0 C i N i 6

Since each N j has only 0 s after its j-th coordinate, we can restrict the matrix of N s to its first i and the matrix of C s to its first i columns and we still have: C C i Ñ T ÑTi C N 0 0 0 C 2 N 2 0 0 C 3 N 3 0 C i N i rows where N j is the restriction of N j to its first i coordinates Now all the matrices are square matrices The determinant of the matrix of C s is k i and the determinant of the matrix of N j s is an integer So k i divides the determinant on the right hand side, which is C N C i N i Since no C j N j 0 mod p for j i, the prime p does not divide this product So p cannot divide k i Hence k i 0 mod p This completes the proof of Lemma 5 This lemma immediately implies Theorem 2 since C C d is a minimum cycle basis So the cycle basis computed by Randomized-MCB is a minimum cycle basis with probability at least 3! 4 (from Lemma 3) Note that by running Randomized-MCB a constant number of times and taking the cycle basis whose weight is the least, we can make the error probability less than δ for any given constant δ 0 3 Running Time of Randomized-MCB The value of π r, the number of primes less than r, is given by r! 6log r π r 8r! log r [] So the elements in P can be bounded by 00d 2 logd Using sieving, we can compute the set of primes in the first 00d 2 logd numbers in O d 2 log 2 d time So the set P can be determined in O d 2 log 2 d time 3 Computing B i Now we consider the problem of computing a shortest cycle in G whose inner product with X i is nonzero modulo p Let us first review the technique in [] and then we describe our improved algorithm for this problem Using the digraph G V A and the vector X i, an undirected graph U i p can be constructed The graph U i p can be visualised as a graph with p levels Call these levels as level 0,, level p Each level has a copy of every vertex v V Let v j be the copy of vertex n level j The edge set of U i p also consists of p copies of each arc a A The edges corresponding to arc a u v are u j v k where k j # X i a modulo p for each j 0 p Each edge u j v k in U i p inherits the weight of its corresponding arc u v of G For example, let a u v X i a 3 and p 5 Then U i p has 5 copies of a which are u 0 v 3 u v 4 u 2 v 0 u 3 v u 4 v 2 So we have a well-defined map from the vertex set of U i p to the vertex set of G and from the edge set of U i p to the arc set of G We can extend this map to paths of U i p Any path in U i p maps to a chain in G by mapping the vertices and edges in U i p to their images in G We say that path e 0 e r in the graph U i p has repeated edges if e i and e j for some i j, map to the same arc of G The following properties of U i p capture the essence of this graph any v 0 v path in U i p maps to a closed chain in G a v 0 v path in U i p with no repeated edges maps to a cycle in G the inner product of such a cycle with X i is (in p) a chain is an alternating sequence of vertices and arcs x 0 a x a 2 a r x r such that either a k x k x k or a k x k x k 7

The following lemma from [] is what we need Its proof follows easily from the above properties Lemma 7 Let q min v min 0 shortest v 0 v path in the graph U i p Then q corresponds to a shortest cycle in G whose inner product with X i is nonzero modulo p So B i can be computed by running Dijkstra s algorithm from v 0 for each v V and taking the minimum over v, of these shortest v 0 v 0 paths Since U i p has pn nodes and pm edges, Dijkstra s algorithm takes O pm # pnlogn time for each v 0 Hence the total time taken to compute the cycle B i is O n pm # pnlogn Now we will show that we can modify Dijkstra s algorithm for this application so that we take O mlogn time for each v 0 instead of O pm # pnlogn time 32 Improved implementation of computing a shortest v 0 v 0 path We will not build the graph U i p explicitly Whenever we are at a vertex u j, we know its neighborhood as follows If there is an arc a between u and a vertex w in G, then in U i p, w k is a neighbor of u j where k j # X i a mod p if a u w (directed from u to w), and k j X i a mod p if a w u (directed from w to u) The key observation here is that to compute min 0 shortest v 0 v path, it is enough to look at those intermediate vertices which are the closest or second closest of their type to v 0 That is, if u j is a vertex in min 0 shortest v 0 v path, then u j is closest or second closest to v 0 among all of u 0 u u p So while running Dijkstra s algorithm to determine min 0 shortest v 0 v path, we only explore neighborhoods of such vertices in the priority queue Then the maximum number of vertices that we process in the priority queue is 2 degree(u) O m So Dijkstra s algorithm for this application can be modified to run for at most O m iterations and not O pn iterations and the number of edges that we look at is also O m and not O pm More formally, we will have u for each vertex u in U i p and the priority queue Q contains all the nodes of U i p, keyed by their values Then we start computing single-source shortest paths for each vertex in level 0 Call one such vertex as v 0 This procedure runs as follows: set v 0 0 Maintain an array for the n vertices of G and initially u 0 for each u V Repeat Extract the vertex x with the smallest value from Q (in case of ties, x is the vertex which was assigned this value earliest) If x is v for some 0, then store v and the path computed to v and quit the Repeat loop Else let x u k if u 2, then increment u and for each neighbor w of x do w min w x # weight x w and set predecessor of w to x if its value has changed else do nothing For each vertex whose distance was made finite in our loop, set its back to and insert back to Q the deleted vertices (so that we can now run this procedure for another vertex w 0 of level 0) Remark There is always a v 0 v path for some 0 in the graph U i p for each v G This is because X i on its last n coordinates (which are the arcs of the spanning tree T) is 0 and X i 0 So each level of the U i p graph is connected and there is at least one edge from level 0 to some nonzero level 8

Running time of the above algorithm We look at neighborhoods of only those vertices which are of the type u j such that u j is the first or second among all the vertices in u 0 u p to be extracted from the priority queue For such vertices we make the value of their neighbors to be finite The total number of vertices whose distance is ever made finite in our loop is bounded by u G deg u j for all u j which are closest or second closest to v 0 among the u vertices Since deg u j deg u, we get the bound of 2 u deg u O m Let us implement the priority queue as a binary heap so that each of the operations needed above can be implemented in O log pn O logn amount of time In the Repeat loop we charge the cost of extracting a vertex x to x s predecessor in shortest-path v 0 u So for each vertex u j which is closest or second closest among u vertices to v 0, we do O deg u log n amount of work For the other vertices we do no work We take O pn time to build the binary heap But we do this just once in the entire algorithm, at the beginning of our first iteration Thereafter, we simply reset to infinity the value of only those vertices which were made finite while running our procedure for the previous vertex Also, we insert the deleted vertices back into the heap This takes O m log n work In iteration i, once we compute min 0shortest v 0 v path for all v V, we have determined B i This takes time O n mlogn given the priority queue Q containing all the vertices with their values So the total amount of time to compute all the cycles B B d given the vectors X X d is O pn # d n mlogn which is O m 2 nlog n All we need to show now is the following lemma Lemma 8 In order to compute min 0 shortest v 0 v path in U i p, it is enough to look at vertices which are of the form: closest or second closest of their type to v 0 Proof Let v r be the closest vertex to v 0 among v v p Let q be the shortest path from v 0 to v r Suppose u k is a vertex on q which is not of the description: closest or second closest among u vertices to v 0 By the construction of the graph U i p, we know that if there is a u k v r path, then there is also a u t v r k t mod p path which is just a translation of the u k v r path, for every t 0 p (Note that all these paths correspond to the same chain in G with endpoints u and v, so they have the same length) Let u f be the closest u vertex to v 0 Add the u f v r k f mod p path described above to the shortest-path v 0 u f This gives us a path from v 0 to v r k f mod p, which is shorter than q So v r k f mod p is closer than v r to v 0 But there is one catch: it could be the case that r # k f mod p 0 Then consider the path which is obtained by adding the analogous u s v r k s mod p path to the shortest-path v 0 u s, where u s is the second closest u vertex to v 0 It cannot be the case that both r # k f mod p and r # k s mod p are 0 because that would mean that f s 0 mod p but f and s are distinct numbers in 0 p So we get the result that in order to compute min 0 shortest v 0 v path, it is enough to consider only the special vertices as intermediate vertices The overall running time of Randomized-MCB Under the assumption that arithmetic on O log m bits takes unit time, it follows that addition, subtraction and multiplication in p can be implemented in unit time since p is O d 2 logd However we also need to implement division efficiently since the update step of X j involves division Once p is chosen, we will compute the multiplicative inverses of all elements in p by the extended Euclid s gcd algorithm by solving ax mod p for each a p This takes time O log p for each element and hence O plog p for all the elements Thereafter, division in p gets implemented as multiplication with the inverse of the divisor We need to account for the time taken to update the vectors X i X d in iteration i Adding a scalar multiple of X i to a vector X j takes Θ i time So the time taken by the update step in iteration i to update d i vectors is Θ i d i So the entire time taken by the update steps of all the iterations is Θ d 3 So the total time taken by the algorithm Randomized-MCB is O m 3 # m 2 nlog n 9

4 Faster implementation Instead of spending Θ m 3 time for the update step, using the technique in [2] we can implement the update step in O m ω time, where ω 2 376 is the exponent of matrix multplication This then gives us an O m 2 nlogn randomized algorithm for computing a minimum cycle basis The algorithm FAST-Randomized-MCB is described below Compute a set P of d 2 primes p 0 p where each p j d 2 Choose a prime p uniformly at random from this set Call the procedure extend cycle basis e e d d, where e e d are the first d vectors of the standard basis The procedure extend cycle basis takes as input a partial cycle basis, say, D D i (denoted by D), a parameter k, and k vectors k of m p which are orthogonal to D D i over p and computes k new cycles D i D i k to extend the cycle basis The role of k is identical to the role played by the vectors X i X i 2 at the beginning of iteration i in the algorithm Randomized- MCB (Section 22) Just as the vectors X j got updated in Randomized-MCB, the vectors v j get updated during the course of extend cycle basis But the difference is that we will update many v j s with respect to many cycles in one bulk update step and this bulk update can be implemented efficiently using fast matrix multiplication For clarity we will sometimes use the notation v j to denote the version of v j that is orthogonal to the cycles D D We describe below the recursive procedure extend cycle basis Note that all the arithmetic that we do here is over the field p The procedure extend cycle basis D k k : if k, compute a shortest cycle D i such that D i 0 mod p if k, use recursion Let t k! 2 call extend cycle basis D t t to extend the current cycle basis by t elements That is, the cycles D i D i t are computed in a recursive manner 2 call update t t k This updates i t vi i k en masse into the desired versions i t t vi i t k that are orthogonal to D D i t 3 call extend cycle basis D D i D i t t k k t to extend the current cycle basis by k t cycles That is, the cycles D i t D i k will be computed recursively The key subroutine in extend cycle basis is update We want to update the vectors t k in update Each of these vectors is now in the version j and we want to update it to its version t j The version t j will be orthogonal to D D i t Let us call t j as w j We define w j as follows: w j v j # a j # a j2 2 # # a jt t for some a j a jt p (4) Since w j is a linear combination of vectors which are orthogonal to D D i, w j will always be orthogonal to D D i We will determine these coefficients a j a jt so that w j is orthogonal to the cycles D i D i t Writing Equation (4) for all i # j i # k in matrix form, we have w i t A I w i k 0 k

where A is a k t t matrix whose th row has the unknowns a j a jt, where j i # t # I is the k t k t identity matrix And w j (similarly, v j ) represents a row with the coefficients of w j (resp, v j ) as its row elements Let us multiply both sides of this equation with an m t matrix whose columns are the cycles D i D i t That is, w i t w i k D Ti DTi t A I k D Ti DTi t (5) Then the left hand side is the 0 matrix since each of the vectors w i t w i k has to be orthogonal to each of D i D i t Let us split the product of the matrix of v s and the matrix of D T s on the right hand side as B Then Equation (5) becomes t D Ti DTi t ; C 0 A I B C t k We get AB # C 0 We can determine A CB if B is invertible D i D i t 2 D i 2 D i t D Ti DTi t 0 0 0 B t D i t D i t 0 0 0 B is an upper triangular matrix over p with nonzero elements on the diagonal, since for indices j in the range i # j i # t, the vector v j is in its final version v j j using which D j was computed This means v j j D j 0 mod p and v j j D 0 mod p for all j Hence, B is invertible over p Thus A CB 4 Correctness It follows from the initialization and the implementation of update that the vector always has a in its i-th coordinate and 0 s in coordinates i # m And whenever extend cycle basis D D i is called, is a vector in m p that is orthogonal to D D i over p So if D j B j for j i, where B j is the cycle computed by our original algorithm Randomized-MCB in its j-th iteration, then the vector X i Then D i B i, since both Randomized-MCB and FAST-Randomized-MCB will use the same subroutine to compute a shortest cycle whose inner product with X i is nonzero modulo p Hence, it follows from Section 22 that whenever p is good, FAST-Randomized-MCB computes a minimum cycle basis 42 The running time of FAST-Randomized-MCB The recurrence of our FAST-Randomized-MCB algorithm is as follows: cost of computing a shortest cycle D T k i such that D i 0 mod p if k 2T k! 2 # cost of update if k

The computation of matrices B and C takes time O mk ω using the fast matrix multiplication algorithm, where ω 2 376 To compute B (similarly, C) we are multiplying k! 2 m by m k! 2 matrices We split the matrices into 2m! k square blocks and use fast matrix multiplication to multiply the blocks Thus multiplication takes time 2m! k k! 2 ω O mk ω We can also invert B in O k ω time and we also multiply C and B using fast matrix multiplication in order to get the matrix A And we use the fast matrix multiplication algorithm again, to multiply the matrix A I with the matrix whose rows are v i k to get the updated vectors w i t w i k With a preprocessing cost of O m 2 nlog n, we can compute the set of primes P and initialise the binary heap for computing shortest paths Thereafter, the computation of a cycle takes O mn log n time (from Section 32) So the recurrence turns into T k O mnlogn if k 2T k! 2 # O mk ω if k This solves to T m O m mnlogn # m ω We can assume that G is a simple graph, 2 so m n 2 Then m ω m 2 n and the running time reduces to T m O m 2 nlogn Hence we can conclude the following theorem Theorem 3 A minimum cycle basis of a directed graph can be computed with high probability in time O m 2 nlog n Acknowledgments I am grateful to Kurt Mehlhorn for useful discussions and his help in improving the presentation of the paper I also wish to thank Jaikumar Radhakrishnan for his helpful comments References T M Apostol Introduction to Analytic Number Theory Springer-Verlag, 997 2 F Berger, P Gritzmann, and S de Vries Minimum Cycle Bases for Network Graphs Algorithmica, 40(): 5-62, 2004 3 B Bollobás Modern Graph Theory, volume 84 of Graduate Texts in Mathematics, Springer, Berlin, 998 4 A C Cassell and J C Henderson and K Ramachandran Cycle bases of minimal measure for the structural analysis of skeletal structures by the flexibility method Proc Royal Society of London Series A, 350: 6-70, 976 5 JC de Pina Applications of Shortest Path Methods PhD thesis, University of Amsterdam, Netherlands, 995 6 N Deo Graph Theory with Applications to Engineering and Computer Science Prentice-Hall Series in Automatic Computation Prentice-Hall, Englewood Cliffs, 982 7 P M Gleiss Short cycles: minimum cycle bases of graphs from chemistry and biochemistry PhD thesis, Universität Wien, 200 8 P M Gleiss, J Leydold, and P F Stadler Circuit bases of strongly connected digraphs Discussiones Math Graph Th, 23: 24-260, 2003 9 Alexander Golynski and Joseph D Horton A polynomial time algorithm to find the minimum cycle basis of a regular matroid In 8th Scandinavian Workshop on Algorithm Theory, 2002 0 J D Horton A polynomial-time algorithm to find a shortest cycle basis of a graph SIAM Journal of Computing, 6:359 366, 987 T Kavitha and K Mehlhorn A Polynomial Time Algorithm for Minimum Cycle Basis in Directed Graphs In Proc of STACS, LNCS 3404: 654-665, 2005 2 T Kavitha, K Mehlhorn, D Michail, and K Paluch A faster algorithm for Minimum Cycle Basis of graphs In Proc of ICALP, LNCS 342: 846-857, 2004 3 Christian Liebchen Finding Short Integral Cycle Bases for Cyclic Timetabling In Proc of ESA, LNCS 2832: 75-726, 2003 4 C Liebchen and L Peeters On Cyclic Timetabling and Cycles in Graphs Technical Report 76/2002, TU Berlin 5 C Liebchen and R Rizzi A Greedy Approach to compute a Minimum Cycle Basis of a Directed Graph Technical Report 2004/3, TU Berlin 2 we can easily reduce the problem of computing a minimum cycle basis in a multigraph to that of computing one in a simple graph 2

Appendix Some Examples As mentioned in Section, every cycle basis of a directed graph need not project onto an undirected cycle basis The following example (Fig ) shows this e 2 2 e 4 e 6 e 5 e 2 4 e 3 3 4 3 Fig Directed K 4 and the underlying undirected graph The three 4-cycles in the above directed graph in Fig : C e e 2 e 3 e 4, C 2 e e 6 e 3 e 5 and C 3 e 2 e 5 e 4 e 6 given by the vectors 0 0 0 0, and 0 0 are linearly independent over " Hence they form a cycle basis for the directed K 4 But in the underlying undirected graph, each of these cycles is equal to the sum of the other two modulo 2, so C C 2 C 3 do not form a cycle basis for undirected K 4 Similarly, a minimum cycle basis of a digraph need not project onto a cycle basis of the underlying undirected graph The following example was given in [4]: the smallest set of cycles that forms a minimum cycle basis for a directed graph but does not project onto a cycle basis for the underlying undirected simple graph is 2 3 2 4 3 5 4 6 5 6 2 3 6 2 4 5 2 5 6 3 4 5 3 4 6 on the directed K 6 (with edges oriented arbitrarily) and unit arc weights On one hand, the set only contains triangles, hence its weight is minimum And as there are 0 0 submatrices of the cycle matrix that have non-zero determinant, it is indeed a cycle basis of the graph K 6 On the other hand, as every edge is hit exactly twice, it cannot be a cycle basis for the undirected graph 3