Bipartite Edge-Colouring in O ( M) Time: Max Max Max

Download as pdf or txt
Download as pdf or txt
You are on page 1of 7

Bipartite edge-colouring in O(m) time

1
Alexander Schrijver
2
Abstract. We show that a minimum edge-colouring of a bipartite graph can be found in O(m)
time, where and m denote the maximum degree and the number of edges of G, respectively. It is
equivalent to nding a perfect matching in a k-regular bipartite graph in O(km) time.
By sharpening the methods, a minimum edge-colouring of a bipartite graph can be found in
O((p
max
() + log )m) time, where p
max
() is the largest prime factor of . Moreover, a perfect
matching in a k-regular bipartite graph can be found in O(p
max
(k)m) time.
1. Introduction
In a classical paper, K onig [9] showed that the edges of a bipartite graph G can be
coloured with (G) colours, where (G) is the maximum degree of G. (In this paper,
colouring edges presumes that edges that have a vertex in common obtain dierent colours.)
K onigs proof is essentially algorithmic, yielding an O(nm) time algorithm (n and m
denote the numbers of vertices and edges, respectively, of the graph). As was shown by
Gabow [4], the O(

nm) bipartite matching algorithm of Hopcroft and Karp [8] implies an


O(

nmlog ) bipartite edge-colouring algorithm. This was improved by Cole and Hopcroft
[1] to O(mlog m), by extending methods of Gabow and Kariv [5], [6].
Fixing the maximum degree , the methods found as yet are superlinear (albeit slightly).
In this paper we give a linear-time method for xed or bounded . More precisely, we give
an O(m) method for bipartite edge-colouring. It implies (in fact, is equivalent to) nding
a perfect matching in a k-regular bipartite graph in O(km) time.
Ultimately one would hope for an O(mlog k) (or even O(m)) algorithm nding a perfect
matching in a k-regular bipartite graph, and for an O(mlog ) algorithm for bipartite edge-
colouring (the rst algorithm implies the second, by a method of Gabow [4] see below).
We did not nd such algorithms, although our methods can be extended to obtain some
supporting results.
In particular, dene, for any natural number k,
(k) :=
t

i=1
p
i

i1
j=1
p
j
, (1)
where p
1
p
t
are primes with k = p
1
. . . p
t
. We give an O((() + log )m)
bipartite edge-colouring algorithm. Note that in () +log , the term () dominates if
is prime, while log dominates if is a power of 2. Note also that () 2p
max
(),
where p
max
() denotes the largest prime factor in . So xing the maximum prime factor
of , there is an O(mlog ) bipartite edge-colouring algorithm.
Moreover, we give an O((k)m) algorithm nding a perfect matching in a k-regular
bipartite graph. So bounding the maximum prime factor of k, there is a linear-time perfect
matching algorithm for k-regular bipartite graphs.
1
Key Words: bipartite, edge-colouring, complexity, timetabling, perfect, matching
Subject Classication: Primary: 68R10, 90C27, Secondary: 05C70, 05C85
2
CWI, Kruislaan 413, 1098 SJ Amsterdam, The Netherlands and Department of Mathematics, University
of Amsterdam, Plantage Muidergracht 24, 1018 TV Amsterdam, The Netherlands.
1
The proof idea is an extension of the following idea of Gabow [4] to nd a perfect
matching in a 2
t
-regular bipartite graph G in linear time. First nd an Eulerian orientation
of G (taking O(m) time), and consider those edges that are oriented from vertex-colour I
to vertex-colour II (in the 2-vertex-colouring of G). This gives a 2
t1
-regular subgraph of
G. Repeating this, we end up with a 1-regular subgraph of G, being a perfect matching in
G. The time is O(m+
1
2
m+
1
4
m+ ) = O(m).
One can similarly nd a 2
t
-edge-colouring in O(tm) time. In extending this method
to prime factors other than 2 we use some techniques of [10] for estimating the number of
perfect matchings and edge-colourings of bipartite graphs.
In this paper, all graphs may have multiple edges.
2. Some practical motivation
As is well-known, bipartite edge-colouring can be applied in timetabling. A pure instance
of timetabling consists of a set of teachers, a set of classes, and a list L of pairs (t, c) of a
teacher t and a class c, indicating that teacher t has to teach class c during a time-slot (say,
an hour) within the time-span of the schedule (say, a week). A pair (t, c) may occur several
times in the list, indicating the number of hours the pair t, c should meet weekly.
A timetable then is an assignment of the pairs in the list to hours, from a set H of
possible hours, in such a way that no teacher t and no class c occurs in two pairs that
are assigned to the same hour. This clearly is a bipartite edge-colouring problem, and by
K onigs theorem, there is a timetable if and only if [H[ is not smaller than the number of
times that any teacher t or any class c occurs in L. So by the result of Cole and Hopcroft
[1] a timetable can be found in O([L[ log [L[) time, and by our theorem, it can be found
also in O([H[ [L[) time. (In practice, several additional constraints are put on a timetable,
making the problem usually NP-complete cf. Even, Itai, and Shamir [3].)
In many countries, schools are merging, yielding an increase in size, including in numbers
of teachers and of classes. So the list L grows. However, the number of hours during a week
does not grow. This gives that, in this interpretation, the algorithm is linear in the size of
the school.
Moreover, often H is built up from smaller units (say, days), implying that [H[ does not
have large prime factors. ([H[ typically has prime factors 2,3, and 5 only, sometimes 7).
This gives that applying the O(([H[+log [H[)[L[)-time algorithm can be fruitful. Similarly,
the method is not very sensitive to doubling or tripling the time-span (say to 2 or 3 weeks).
3. An O(m) bipartite edge-colouring algorithm
Basic in the edge-colouring algorithm (as in [4]) is a subroutine nding a matching that
covers all maximum-degree vertices, and that hence can serve as our rst colour. To this
end we show:
Theorem 1. A perfect matching in a k-regular bipartite graph can be found in O(km)
time.
Proof. Let G = (V, E) be a k-regular bipartite graph. For any function w : E Z
+
, let
E
w
be the set of edges with w(e) > 0. For any F E, denote w(F) :=

eF
w(e).
Initially set w(e) := 1 for each edge e. Next apply the following iteratively:
2
Find a circuit C in E
w
. Let C = M N for matchings M and N with w(M)
w(N). Reset w := w +
M

N
.
(2)
Note that, at any iteration, the equality w((v)) = k is maintained for all v V (where
(v) is the set of edges incident with v).
To see that the process terminates, rst note that at any iteration the sum

eE
w(e)
2
(3)
increases by

eM
((w(e)+1)
2
w(e)
2
)+

eN
((w(e)1)
2
w(e)
2
) = 2w(M)+[M[2w(N)+[N[, (4)
which is at least [C[ (as w(M) w(N)). Moreover, (3) is bounded, since w(e) k for each
edge e. So the process terminates.
At termination, we have that the set E
w
is a forest, and hence is a perfect matching
(since w(e) = k for each end edge e of E
w
). This implies that at termination the sum (3)
is equal to
1
2
nk
2
= km.
Now by depth-rst we can nd a circuit C in (2) in O([C[) time on average. Indeed,
keep a path P of edges e with 0 < w(e) < k. Let v be the last vertex of P. Choose an edge
e = vu incident with v but not in P. If u does not occur in P, we reset P := P e and
iterate. If u does occur in P, let C be the circuit in P e, and apply (2) to C. Next reset
P := P ` C, and iterate.
If P = , choose any edge e with 0 < w(e) < k, and set P := e. If no such edge e
exists, we are done.
For k smaller than

log n, the O(km) bound is asymptotically better than the O(m+
nlog n(log k)
2
)) bound proved by Cole and Hopcroft [1]. (An algorithm related to, but
dierent from, the algorithm described in Theorem 1, was proposed by Csima and Lov asz
[2], giving an O(n
2
k log k) time bound.)
By applying a technique of Gabow [4], one can derive from Theorem 1 the following
stronger statement:
Corollary 1a. A k-edge-colouring of a k-regular bipartite graph can be found in O(km)
time.
Proof. If k is odd, rst nd a perfect matching M, remove M from G, and apply recursion
(M will serve as colour).
If k is even, nd an Eulerian orientation of G. Let k

=
1
2
k. Then split G into two
k

-regular graphs G
1
= (V, E
1
) (with E
1
the set of edges oriented from vertex-colour class
I to vertex-colour class II) and G
2
= (V, E
2
) (with E
2
:= E ` E
1
). Find recursively k

-
edge-colourings of G
1
and G
2
. The union of the two colourings is a k-edge-colouring of
G.
The time is bounded as follows. Starting with G, we can nd M (if k is odd), nd
the Eulerian orientation, and split G into G
1
and G
2
, in time ckm for some constant c.
Then the whole recursion takes time 2ckm. This can be shown inductively, as 2ckm =
3
ckm+ 2ck

+ 2ck

, where m

= [E(G
1
)[ = [E(G
2
)[ =
1
2
m.
This implies the sharper statement:
Corollary 1b. A (G)-edge-colouring of a bipartite graph G = (V, E) can be found in
O((G)m) time.
Proof. Let k := (G). First iteratively merge any two vertices in the same colour class
of G, if each has degree at most
1
2
k. The nal graph H will have at most two vertices of
degree at most
1
2
k, and moreover, (H) = k and any k-edge-colouring of H yields a k-edge-
colouring of G. Next make a copy H

of H, and join each vertex v of H by kd


H
(v) parallel
edges with its copy v

in H

(where d
H
(v) is the degree of v in H). This gives the k-regular
graph G

, with [E(G

)[ = O([E(G)[). By Corollary 1a we can nd a k-edge-colouring of G

in O(k[E(G

)[) time. This gives a k-edge-colouring of H and hence a k-edge-colouring of


G.
4. Towards an O(mlog ) method?
The results of Section 3 can be sharpened by using divisibility properties of (G). First
we sharpen Corollary 1a. We repeat the denition of (k) for any natural number k:
(k) :=
t

i=1
p
i

i1
j=1
p
j
, (5)
where p
1
p
t
are primes with k = p
1
. . . p
t
.
Theorem 2. A k-edge-colouring of a k-regular bipartite graph G = (V, E) can be found in
O(((k) + log k)m) time.
Proof. Let k = pk

with p prime. Split each vertex v into k

new vertices v
1
, . . . , v
k
, and
distribute the edges incident with v over v
1
, . . . , v
k
in such a way that each vertex v
i
is
incident with exactly p edges. This gives the p-regular graph

G. Find a p-edge-colouring of

G. The colours give a partition of E into classes E


1
, . . . , E
p
, in such a way that each graph
G
j
= (V, E
j
) is k

-regular. Next nd a k

-edge-colouring of G
p
, yielding perfect matchings
M
1
, . . . , M
k
.
Now we apply the following iteratively. We have a partition of E into perfect matchings
M
1
, . . . , M
k
and k

-regular graphs E
1
, . . . , E
p
. (Initially, = 1.) Let q := min, p.
Choose r such that qk

+ r is a power of 2 and such that r qk

. Let E

:= M
1

M
r
E
1
E
q
. Then G

:= (V, E

) is a qk

+ r-regular graph. Next qk

+ r-edge-
colour G

, yielding colours N
1
, . . . , N
qk

+r
. Now replace M
1
, . . . , M
r
by N
1
, . . . , N
qk

+r
and
E
1
, . . . , E
p
by E
q+1
, . . . , E
p
and iterate. We stop if = p.
So at any iteration, is replaced by + q. Moreover, at any iteration except possibly
the last iteration, we have q = . So at any iteration except possibly the last one, q is twice
as large as at the previous iteration.
4
By [4], the work in the iteration takes time O([E

[ log(qk

+ r)) = O([E

[ log k), since


qk

+ r is a power of 2 and since qk

+ r k. Since [E

[ =
1
2
(qk

+ r)n qk

n, over all
iterations the work is O((1 + 2 + 2
2
+ + 2
log p
)k

nlog k) = O(pk

nlog k) = O(mlog k).


To this time bound we must add the time needed to obtain G
1
, . . . , G
p
which takes
O(pm) time by Corollary 1b, since it amounts to p-edge-colouring the p-regular graph

G, having m edges, and the time needed to edge-colour G


p
, which takes (by induction)
O(((k

) + log k

)m

) time, where m

= m/p is the number of edges of G


p
. Since (k) =
p +(k

)/p, we have the required time bound.


This gives:
Corollary 2a. A (G)-edge-colouring of a bipartite graph G can be found in O((((G))+
log (G))m) time.
Proof. Directly from Theorem 2 by the method of Corollary 1b.
Note that
(k) 2p
max
(k) (6)
(where p
max
(k) is the largest prime factor of k). This follows inductively, since if k = pk

,
with p the smallest prime factor of k, then (k) = p +(k

)/p p
max
(k) +(2p
max
(k

)/p)
2p
max
(k). This implies:
Corollary 2b. A (G)-edge-colouring of a bipartite graph G can be found in O((p
max
((G))+
log (G))m) time.
Proof. Directly from Corollary 2a with (6).
Note that in performing this method one does not need to apply deep number-theoretic
algorithms to nd the prime-factorization of k. Indeed, the factors p
1
, . . . , p
t
can be found
in O((k)k) time, since the smallest prime factor p can be found in time O(pk), by trying
i = 2, 3, . . . as divisor of k (for each i taking O(k) time), until we reach p. Next we can
apply recursion to k

:= k/p, taking recursively O((k

)k

) time. This gives O((k)k) time


over-all, since (k) = p +(k

)/p.
A sharpening can be obtained also for nding perfect matchings in k-regular bipartite
graphs.
Theorem 3. A perfect matching in a k-regular bipartite graph G can be found in time
O((k)m) time.
Proof. Write k = pk

with p the smallest prime factor of k. Make the graph



G as in the
proof of Theorem 2. So

G is p-regular. Find a perfect matching M in

G. It gives a k

-regular
subgraph G

= (V, E

) of G. In G

we nd recursively a perfect matching.


Finding perfect matching M in

G takes time O(pm) by Theorem 1. Finding matching
N in G

takes time O((k

)m/p) by induction (as G

is k

-regular and has m/p edges). Since


5
(k) = p +(k

)/p, the whole process takes O((k)m) time.


Corollary 3a. A matching covering all maximum-degree vertices in a bipartite graph can
be found in O(()m) time.
Proof. Directly from Theorem 3, using the technique of Corollary 1b.
By (6), Theorem 3 can be stated in a weaker form as:
Corollary 3b. A perfect matching in a k-regular bipartite graph can be found in O(p
max
(k)m)
time.
Proof. Directly from Theorem 3, using (6).
5. Some open questions
It would be surprising if divisibility properties of the maximum degree (G) of a bi-
partite graph G would determine the complexity of edge-colouring G. Our results are
blocked however by the primes. If (G) is a prime, we do not have anything better than
an O((G)m)-time algorithm. So the main problem is to break a prime. More precisely,
Is there an O(mlog k) algorithm for nding a perfect matching in a k-regular
bipartite graph?
(7)
The method of Cole and Hopcroft [1] gives an O(m + nlog nlog
2
k) algorithm to nd a
perfect matching in any k-regular bipartite graph. If there would be an O(mlog k) perfect
matching algorithm for k-regular bipartite graphs, there exists an O(mlog ) bipartite
edge-colouring algorithm (by methods like in Theorem 2 above), thus answering our second
question:
Is there an O(mlog ) algorithm for bipartite edge-colouring? (8)
Similar methods as used for proving Theorem 2 give an approximative method, namely a
bipartite (+log(1)|)-edge-colouring algorithm, with time bound O(mlog ). Indeed,
let G = (V, E) be a bipartite graph of maximum degree . In O(m) time we can split E
into E

and E

such that both G

= (V, E

) and G

= (V, E

) have maximum degree at


most

:=
1
2
|. We may assume that [E

[
1
2
m. Let t :=

+ log(

1)|. Then
t-edge-colour G

recursively, giving colours M


1
, . . . , M
t
. Choose s t such that

+s is a
power of 2. Next (

+s)-edge-colour the graph H made by M


1
M
s
E

. With the
remaining M
s+1
, . . . , M
t
it gives an edge-colouring of G with
(

+s) + (t s) = 2

+ log(

1)| + log( 1)| (9)


colours. Since the number of edges in G

is at most
1
2
m and since edge-colouring H takes
O(mlog(

+s)) = O(mlog ) time, this gives an O(mlog ) time bound.


6
The nonbipartite case is NP-complete, by the well-known result of Holyer [7]: it is NP-
complete to decide if a 3-regular graph can be 3-edge-coloured. However, it is not dicult
to see that a 3-regular graph can be 4-edge-coloured in linear time. Actually, any graph of
maximum degree 3 can be 4-edge-coloured in O(m) time.
By Vizings theorem, each simple graph Gcan be ((G)+1)-edge-coloured. (If (G) 3
we can delete the condition that G be simple.) This prompts the question:
Is there an O(m)-time ( + 1)-edge-colouring algorithm for simple graphs? (10)
Of course, the stronger question is to ask for an O(mlog ) algorithm.
References
[1] R. Cole, J. Hopcroft, On edge coloring bipartite graphs, SIAM Journal on Computing 11 (1982)
540546.
[2] J. Csima, L. Lov asz, A matching algorithm for regular bipartite graphs, Discrete Applied Math-
ematics 35 (1992) 197203.
[3] S. Even, A. Itai, A. Shamir, On the complexity of timetable and multicommodity ow problems,
SIAM Journal on Computing 5 (1976) 691703.
[4] H.N. Gabow, Using Euler partitions to edge color bipartite multigraphs, International Journal
of Computer and Information Sciences 5 (1976) 345355.
[5] H.N. Gabow, O. Kariv, Algorithms for edge coloring bipartite graphs, in: Conference Record of
the Tenth Annual ACM Symposium on Theory of Computing [10th STOC, San Diego, California,
May 13, 1978], The Association for Computing Machinery, New York, 1978, pp. 184192.
[6] H.N. Gabow, O. Kariv, Algorithms for edge coloring bipartite graphs and multigraphs, SIAM
Journal on Computing 11 (1982) 117129.
[7] I.G. Holyer, The NP-completeness of edge-colouring, SIAM Journal on Computing 10 (1981)
718720.
[8] J. Hopcroft, R.M. Karp, An n
5/2
algorithm for maximum matchings in bipartite graphs, SIAM
Journal on Computing 2 (1973) 225231.
[9] D. K onig, Graphok es alkalmaz asuk a determin ansok es a halmazok elmeletere [Hungarian],
Mathematikai es Termeszettudom anyi

Ertesit o 34 (1916) 104119 [German translation:

Uber
Graphen und ihre Anwendung auf Determinantentheorie und Mengenlehre, Mathematische An-
nalen 77 (1916) 453465].
[10] A. Schrijver, On the number of edge-colourings of regular bipartite graphs, Discrete Mathematics
38 (1982) 297301.
7

You might also like