Research Collection
Doctoral Thesis
Transitive orientation, boolean matrix multiplication and the test
for transitivity
Author(s):
Trunz, Paul
Publication Date:
1998
Permanent Link:
https://doi.org/10.3929/ethz-a-002017673
Rights / License:
In Copyright - Non-Commercial Use Permitted
This page was generated automatically upon download from the ETH Zurich Research Collection. For more
information please consult the Terms of use.
ETH Library
t
Diss. ETH No. 12917
Orientation,
Transitive
Boolean Matrix
Multiplication and the
for Transitivity
Test
A dissertation submitted to the
SWISS FEDERAL INSTITUTE OF TECHNOLOGY
ZURICH
degree
for the
of
Doctor of Technical Sciences
presented by
PAUL TRUNZ
Dipl. Informatik-Ing. ETH
born 28.5.1967
citizen of
Niederhelfenschwil,
accepted
on
Switzerland
the recommendation of
Simon, examiner
Welzl, co-examiner
Prof. Dr. Klaus
Prof. Dr. Emo
1998
Acknowledgments
introducing me to the field
graph theory and for offering me the opportunity to study a lot of
interesting problems. While guiding this work he was always open for
discussion and provided many useful suggestions. I would also like to
thank Prof. Dr. E. Welzl for accepting to be my co-examiner and his
I want to thank Prof. Dr. Klaus Simon for
of
valuable comments.
Many thanks to all my friends at ETH, Nicola Galli, Davide Crippa,
Raschle, Bernhard Seybold and Thomas Bickel, for many in¬
teresting discussions and for making me smile every now and then.
Thomas
Last but not least I thank my parents, without their support I would
never
have been able to endeavor this work.
Abstract
The main
of
topic of this
objects.
thesis is the
computation of a
linear order of
a
set
The linear order is restricted
by additional constraints which
the graph the vertices represent
an abstract graph. In
objects and the edges represent the additional constraints. Each
edge only relates to two vertices. If a graph has a linear order which
satisfies all constraints then it is called a comparability graph. Usually
recognition algorithms for comparability graphs operate constructively,
that is they also compute an order which satisfies all constraints.
we
represent in
the
In
[GH62]
Ghouila-Houri first characterized
comparability graphs.
published of which those by
Golumbic and Spinrad are most important. The Golumbic algo¬
rithm is less efficient than the Spinrad algorithm, but it is based on
In fact it is the main problem of Spinrad's
a more elegant theory.
solution that it does not sufficiently relate to previous literature. In
Chapter 2 we endeavor to provide a simplified presentation of a unified
theory.
Several
recognition algorithms
Our
algorithm
have been
recognition of comparability graphs to
transitivity.
usually done using
If we only consider the asymptotic
a boolean matrix multiplication.
worst case, then this is the most efficient way known.
However, the
a
test for
reduces the
In the literature this test is
algorithms
by huge
simple, easy to
implement algorithms in Chapter 3. In the average case a surprisingly
simple combination of two obvious strategies performs better than the
complicated algorithms.
are
complicated
constant factors.
For this
and the
reason
running
we
time is affected
concentrate
on
Unfortunately the probabilistic input models for boolean matrix are
appropriate for the test for transitivity. Therefore we need to resort
to experimental results for claims about average running time in Chap¬
ter 4. Moreover, our algorithms for boolean matrix multiplication have
to be modified to adapt to the specific inputs of the test for transitivity.
not
From
puted
can
as
be
a
practical point of
fast
a
view the test for
transitivity can be com¬
comparability graphs
transitive orientation and therefore
recognized
in time
0(n2).
Zusammenfassung
In dieser Arbeit
beschaftigen wir uns mit der Bestimmung einer linearen
Anordnung
Menge von Objekten. Die Moglichkeiten der Anordsind
dabei
durch
nung
Nebenbedingungen eingeschrankt. Als Abstraktionsmodell benutzen wir einen Graphen mit den Objekten als Knoten
und den Nebenbedingungen als Kanten, wobei sich eine Kante immer
nur auf zwei Objekte bezieht. Ein Graph, fiir den eine zulassige Anord¬
nung existiert, wird als comparability graph bezeichnet. Erkennungsalgorithmen fiir diese Graphenklasse sind normalerweise konstruktiv,
berechnen also auch eine zulassige Anordnung.
einer
Comparability graphs wurden zum ersten Mai von Ghouila-Houri
[GH62] charakterisiert. In der Folge wurden verschiedene Algorith¬
men zur ihrer Erkennung veroffentlicht, die wichtigsten stammen von
Golumbic und Spinrad. Der Algorithmus von Golumbic ist weniger
effizient als das Verfahren von Spinrad, verwendet aber eine eleganteDie Losung von Spinrad leidet vor allem darunter, dass
re Theorie.
sie nicht in die bestehende Theorie eingebettet wurde. In Kapitel 2
bemiihen wir uns um eine einfache Formulierung einer vereinheitlichten
in
Theorie.
Unser Ansatz fiihrt die
Erkennung
den Test auf Transitivitat zuriick.
von
comparability graphs
auf
Dieser Test wird in der bestehen-
den Literatur meist als boolesche
Matrixmultiplikation realisiert. Bei
Betrachtungung des asymptotisch schlechtesten Falles ist dies die
beste bekannte Methode, die Algorithmen sind jedoch kompliziert und
mit grossen konstanten Faktoren behaftet. In Kapitel 3 konzentrieren
wir uns deshalb auf einfache, leicht zu implementierende Algorithmen
der
mit guter mittlerer Laufzeit.
Eine einfache Kombination zweier nahe-
liegender Strategien erreicht im Mittel sogar
die komplizierten worst case Algorithmen.
eine bessere Laufzeit als
Leider lassen sich die
probabilistischen Eingabemodelle fiir boole¬
Matrixmultiplikation nicht geeignet auf den Test auf Transitivitat
iibertragen. In Kapitel 4 sind wir deshalb bei Aussagen zur erwarteten Laufzeit iiberwiegend auf experimentelle Resultate angewiesen.
Dariiber hinaus miissen die untersuchten Algorithmen fiir boolesche
Matrixmultiplikation auf die speziellen Eingaben beim Test auf Transi¬
sche
tivitat angepasst werden.
Aus praktischer Sicht kann der Test auf Transitivitat ebenso rasch
durchgefiihrt werden wie die Berechnung einer transitiven Orientierung,
comparability graphs konnen somit in Zeit 0(n2) erkannt werden.
Contents
1
Introduction
1
2
Transitive Orientation
9
3
9
Origin
2.1
Roots of
2.2
Definitions
13
2.3
The Problem
15
2.4
An
2.5
Implication Classes
2.6
The
0(n2)
Transitive Orientation
and
Graph Decomposition
Equivalence of Recognition and
2.8
Conclusions
Boolean Matrix
Test
Multiplication
44
48
49
Introduction
3.2
The Four Russian
3.3
Combination
algorithm
Simple Algorithms
A Review of
3.3.2
Combination of the
3.3.3
A Robust
3.3.4
Another Model
simple algorithms
Algorithm
The Basic
53
55
58
63
66
A Recursive Solution
The Three
50
52
Algorithms
3.3.1
3.4.2
18
46
3.1
3.4.1
17
24
Algorithm
2.7
3.4
Algorithm
Layer Representation
67
67
Strategy
i
ii
Table of Contents
3.5
3.6
4
3.4.3
Implementation Issues
71
3.4.4
Optimization
72
Empirical Analysis
73
3.5.1
General Issues
73
3.5.2
Experimental Setup
79
3.5.3
Comparison of Algorithms
80
3.5.4
The Four Russian
81
3.5.5
Combination
3.5.6
Recursive
3.5.7
Choosing
Algorithm
Algorithms
Algorithm
an
algorithm
Transitivity
93
The Problem
4.2
Reduction to Boolean Matrix
4.4
89
91
4.1
4.3
88
Conclusions
The Test for
83
93
Multiplication
Simple Algorithms
94
95
Algorithm
4.3.1
The Basic Path
4.3.2
Exploiting Transitivity
4.3.3
A Recursive Solution
101
4.3.4
Reducing
106
the Number of Zeros
Empirical Analysis
95
96
109
4.4.1
General Issues
4.4.2
Topological
4.4.3
Recursive
4.4.4
Comparing Algorithms
115
4.4.5
Additional Considerations
119
Order
109
Algorithm
Algorithm
110
113
5
Results and Outlook
123
A
An introduction to
126
graph theory
A.l
Basics
126
A.2
Graph Representations
127
A.2.1
Adjacency
Matrix
127
Table of Contents
A.3
B
iii
A.2.2
Adjacency
Basic
Algorithms
Lists
128
129
A.3.1
Topological Sort
129
A.3.2
Sort
129
A.3.3
Transitive Closure
Edges
Notation
Algorithm
131
132
B.l
Graph theory
132
B.2
Probability Theory
134
Bibliography
135
iv
Chapter
1
Introduction
problem of this thesis
In order to motivate the main
called seriation
we
consider the
so
problem.
Suppose an archaeological expedition which retrieves a number of
pieces from a field of graves. The pieces belong to different
ceramic
types of ceramics in
types
are
abstract
use
at different
older than others.
times,
In
representation
findings.
ceramics, represented by
of
our
our
consider six types of
numbers. We connect two circles with
of the
respective types
Figure 1.1:
The original
the
A
in the
same
a
a
partial
on
generate
an
1.1
we
circles and identified
by
example
line when
we
we
in
Figure
found two pieces
grave.
graphical representation of
version is shown
complement with
want to know which
we
To determine this order
the
left,
orientation.
1
our
on
findings for
the
right
we
ceramics.
have drawn
Chapter
2
If the circles
in
were
use
are
at the
connected
same
by
a
time and
line, then
concurrently.
occur
the other
Therefore
To reflect this
one.
structure which contains the
only
if they
not
are
the lines in the
present
type of ceramics
circles,
same
we
but lines
are
Obviously
than
if
Based
c.
d and b
a
on
lines
or
we
by a line (we call this adjacent)
complement of our ceramics graph, but
at the
same
directions for
we
desire.
a
directed line
a
is also older
introduce the notion of forcing. If
connected
are
before
present if and
is older than b and b is older than c, then
this observation
adjacent in the
adjacent (they occur
before
of
beginning
(denoted by an arrow).
at the end
one
use
express the information
We define that the type of ceramics at the
is older than the
in
was
in
not
complement of our original
original. By determining
can
ceramics
one was
connected, then they do
consider the
in the
complement
not
are
one
we
corresponding
cannot determine which
we
earlier. However if two circles
use
the
Introduction
1.
and
e
d and
and b
are
e are
not
time), then either d and e occur both
usually allows us to direct several
both after b. This notion
once we are
right graphic
able to determine the direction of
Figure
in
1.1 shows the
with all the directions forced if
complement
we can
therefore have to determine their relation in
in this thesis
we
can
specific
line. The
determined that 4 is older than
1. Note that the order of 5 and 6 is not forced
algorithms
for a given
a
of the left structure
by
some
determine if such
line,
Using
any other
other way.
an
order is
we
the
possible
structure.
Throughout
the rest of this
thesis, structures like those in Figure
graphs. Graphs are very common structures to model
combinatorics, discrete mathematics and computer science.
1.1 will be called
problems
Formally
in
a
graph G
(V, E)
=
V
usually
identified
consists of two sets, the set of vertices
=
{l,...,n},
numbers and the set of
by
edges
ECVxV-{(i,i)\iGF}.
We consider
an
edge
to be
an
ordered
prohibits parallel edges (two edges
and
loops (edges
represent
some
between them
"is married to"
them).
of the form
pair of
(v, v)).
As in
(e.g.
or a
set of
set
Our definition
our
example
endpoints)
usually
relationship
vertices
edges some kind of
people
relationships "is child
of traffic crossings with the streets that
kind of entities and
a
vertices.
with identical start- and
with
of" and
connect
3
Figure
As in
Figure
1.2:
A directed and
an
undirected
triangle.
circles to
graphically represent the vertices
problems in this thesis arise in the
edges.
context of comparability graph recognition, although some of them have
applications in other domains. The two graphs in Figure 1.2 demon¬
strate two kinds of graphs we have to deal with, namely directed and
undirected graphs.
In a directed graph we indicate the direction of
each edge by an arrow. Edges in directed graphs can be traversed only
in one direction; they correspond directly to our definition of edges as
ordered pairs of vertices. Edges in undirected graphs can be traversed
in both directions. There are therefore two possibilities to represent
undirected graphs. First we can use unordered pairs of vertices to rep¬
resent edges, second we can use a pair of corresponding ordered pairs,
1.1
we use
and lines to represent the
one
The
for each direction.
The
use
of unordered
pairs for undirected edges is an appropriate
occur. However, in this thesis
representation if only undirected graphs
we
have to deal with directed and undirected
Because the simultaneous
use
graphs
at the
same
time.
of ordered and unordered
pairs often leads
generally represented as a pair of
confusion, undirected edges are
edges in the theory of comparability graph recognition. Each
undirected edge in a graph is then represented by two directed edges in
opposite directions, allowing us to use the same notation for directed
and undirected graphs. The disadvantage of this approach is of course
that we have to maintain consistency among the edges of undirected
E there must also be the edge
graphs, that is for every edge (u, v)
to
directed
(v,u)
£ E.
Throughout the
rest of this thesis
of the notation of graph theory.
Appendix
A and
we
becomes necessary.
we assume a
We
introduce the
provide
more
For convenience
we
a
basic
understanding
brief introduction in
specialized
notation when it
have included
a
survey of
our
4
Chapter
notation in
Appendix
A directed
graph
Va,b,c£
B.
G
V
:
(V, E)
=
(a,b)
is called transitive if
EE A
(b,c)
eE
=>•
(a,c)
That is every
every
Introduction
1.
triangle is oriented as the left graph
two-path (a, b), (b,c) has a short cut (a,c).
in
e E.
Figure
(1.1)
1.2 and
A
comparability graph is an undirected graph which allows a tran¬
orientation, that is we choose exactly one of each pair of edges
representing an undirected edge such that the resulting directed graph is
transitive. Formally, an undirected graph G
(V, E) is a comparability
it
if
has
a
that
satisfies
graph
subgraph (V, F)
sitive
=
FHF_1=0
FUF_1=£
A
A
F2
C F
where
F'1
F2
=
{(u,v)\{v,u)e F}
=
{{a,c)\3beV:(a,b),{b,c)eF}.
and
An
interesting property of a transitive orientation of a comparability
a partial order. This allows us to use specialized algo¬
graph
rithms for certain AfP-complete problems. If the solution for the partial
order also holds for the undirected graph regardless of the orientation
chosen, then we can solve these problems efficiently for comparability
graphs. To do this we must be able to determine a transitive orientation
efficiently.
is that it is
In
[DGT97]
Dell'Olmo et al. consider the
Comparability Augmen¬
problem, which arises in multiprocessor schedul¬
ing, consists of adding edges to the original graph such that it becomes
a comparability graph in which the weight of the maximum clique is
as small as possible. For comparability graphs the problem reduces to
finding the maximum weighted clique. It is somewhat surprising that no
other class of graphs is known for which we can solve the Comparability
Augmentation Problem efficiently.
tation Problem. This
In an application it may not always be possible to guarantee that the
input graph is a comparability graph (as it is in the seriation example).
However, the application may inherently provide a reasonable proba¬
bility
that
typical inputs
are
comparability graphs.
first step is to test whether the
usually
involves
assigning
a
input
is
a
In such
a case our
comparability graph.
transitive orientation to the
The test
input graph
5
©
o^—o—^o
o
Figure
although
1.3:
The vertices
3, 4 and 5 form
this is not
strictly necessary.
comparability graphs.
first characterized
In
module.
a
[GH62]
Ghouila-Houri
Following
his characteriza¬
[GH62] Gilmore and Hoffman gave another characterization
in [GH64]. They also outlined an algorithm to recognize comparability
tion in
graphs
sults
without
on
analyzing
the structure of
Pnueli, Lempel
running time. Gallai derived many re¬
comparability graphs in [Gal67]. In [PLE71]
its
and Even refined the work of Gilmore and Hoff¬
Golumbic further refined this procedure in [Gol77b] where he
basically presented a version of Gilmore and Hoffman's algorithm
man.
suitable for
implementation.
showed that
He
finally analyzed the running
comparability graphs
can
be
recognized
time and
and oriented in
0(n m).
time
The Golumbic
algorithm
from there to assemble
an
starts with
a
implication class,
single edge
and
proceeds
it may therefore be
seen
bottom up
algorithm. In [Spi85] Spinrad presented a different
which
is
more top-down oriented.
He noticed that modules
approach
are an important tool in the theory of
comparability graphs. A module
as
a
M is
subset of V with the property that all vertices in V
adjacent to either all or none of the vertices in M. We will
a
M
are
use
the
—
terminology introduced in [Spi82] where Spinrad presented his 0(n2)
modular decomposition algorithm. In particular he realized that it was
not necessary to orient the graph and check the result for
transitivity
at the same time.
The modular
of
a
graph
form
a
[Spi82]
of
a
decomposition
is
recursive
partitioning of the vertices
Figure 1.3 the vertices 3,4 and 5
Using his 0(n2) modular decomposition algorithm from
a
into maximal modules. In
module.
Spinrad found that he could determine
comparability graph
in
0(n2)
time.
The
a
transitive orientation
SPlNRAD-algorithm
re-
Chapter
6
Introduction
1.
duced the
complexity of comparability graph recognition
transitivity. Moreover, Spinrad showed in [Spi85] that
tion
also be done in the
can
Section 2.7. The two
in time
0(n2)
one can
and
such
reduc¬
a
opposite direction. We present this proof
problems
can
to the test for
can
therefore be reduced to each other
be considered worst
be solved in less than
in
case
equivalent
until either
0(n2).
Chapter 2 we present a simplified theory of transitive orientation
integrates the concepts used by Spinrad and Golumbic. By
explicitly pointing out the connection between modules and implication
classes we yield a simplified theory from which we can naturally derive
Like the Spinradan improved algorithm for transitive orientation.
of the input
orientation
our
an
algorithm
algorithm always computes
if the input
Note
that
this
be
orientation
transitive
can
only
graph.
is
if
orientation
exists at
transitive
a
a
graph
comparability graph (i.e.,
therefore
To
have
to
test the
recognize a comparability graph we
all).
result for transitivity.
In
which
To
perform
this test for
an
orientation T
=
(V, F)
we
have to
verify
that
(a,b),(b,c)
Spinrad
proposed
F
to solve this
=>
(a,c)eF.
problem by computing
the transitive
closure of his orientation and compare the result and the
the oriented
transitive.
reduced to
input.
If
is identical to its transitive closure then it must be
graph
computation of the transitive closure may in turn
the computation of a boolean matrix multiplication.
The
be
multiplication also has other applications
Chapter 3. We present several solutions
independently
of 0(n2lnn) for the general problem
time
expected running
Because boolean matrix
we
discuss it
with
an
in
with random
input matrices. In addition
analysis
we
suggest that
we
case
to the mathematical average
provide empirical analyses of our algorithms which
may expect even better performance in practice.
also
Besides
comparing average running times we also demonstrate how
probability assumptions influence the performance of our algo¬
rithms for boolean matrix multiplication. We state hypotheses and use
experiments to either support or refute them. Using this technique we
can support that one of our algorithms for boolean matrix multiplica¬
different
tion still
runs
in
0(n2 log(n))
randomness than the
In
Chapter
2
we
one we
time
even
for models which involve less
used to prove
show how to reduce the
our
average
recognition
case
of
result.
comparability
7
transitivity in time 0(n2). Therefore this test is
expensive step in the recognition of comparability graphs. The
graphs generated by our transitive orientation algorithm do not conform
to our input model for boolean matrix multiplication. It is therefore not
surprising that the average case results of Chapter 3 do not hold for the
test for transitivity. Because of this we investigate further ways to test
for transitivity in Chapter 4.
graphs
to the test for
the most
The matrices
we
test for
random model. Therefore
a
transitivity do
a simple
analysis of our
not conform to
mathematical average
case
algorithms seems very difficult. Thus we have chosen to compare differ¬
possibilities empirically. Our analyses support that the test can be
done in expected time 0(n2), although we can not prove this.
ent
provide several analyses for the algorithms we present. For our
algorithm for transitive orientation we present a classical worst case
analysis. The 0(n2) worst case bound is the same as the lower bound,
therefore the analysis for this algorithm is optimal, even if faster algo¬
rithms are possible.
We
multiplication the situation is different, the
0(n3) worst case bound is much higher than the lower bound. For this
problem we have reasonable models for the distribution of the inputs.
This allows to determine the expected running time for several models.
For the boolean matrix
In order to
verify the quality of
pirical analyses
our
average
and introduce biased
also compare algorithms
actually practical.
data
we can
they
are
When
testing
for
transitivity
we
case
results
we
input models. Using
provide
our
em¬
empirical
and evaluate the range for which
also face different
problems.
The
again 0(n3) and again this is higher than the lower
However, when we apply the same input models as for the
worst case bound is
bound.
multiplication, then the algorithm will terminate quickly
Because we can deter¬
no random graph is transitive.
mine a violation of transitivity based on a simple local condition this
can be done quickly in many cases, even if an algorithm would take
a lot of time to prove that a graph was transitive.
When we want to
then
do
because there is
we
so
recognize comparability graphs,
usually
a reasonable probability to find one.
boolean matrix
because almost
For this
investigate the running time for the test
inputs. Unfortunately there is no mathematical model
for the distribution of transitive graphs. Nevertheless we were able to
generate transitive input graphs using an ad hoc procedure. Using our
on
reason we
transitive
chose to
Chapter
8
input graphs
the test
we
usually
ran
run
experiments which show that
in
0(n2),
even
for transitive
While it is desirable to have worst
algorithms, there
are
them. In this thesis
multiplication
many
we
show
our
algorithms for
inputs.
average
case
bounds for
possible to compute
that simple algorithms for boolean matrix
orientation perform well empirically.
cases
and transitive
case or
Introduction
1.
in which it is not
Chapter
2
Transitive Orientation
Roots of
2.1
Origin
Transitive orientation is the first step in the
recognition
of compara¬
improve the
by
[Spi85]
bility graphs.
in
Golumbic
which
presented
[Gol77b]. Before
recognition algorithm
the
review
detail
in
we
the
development of
briefly
problem
discussing
It
was
Spinrad in
introduced
to
comparability graph recognition.
G
comparability graph
A
allows
a
—
(V, E)
transitive orientation.* That
is
an
is, G has
graph which
subgraph (V, F) which
undirected
a
satisfies
FnF~1=Q
In
[GH62]
Fur'=£
A
Ghouila-Houri
A
F2
C F.
the first characterization of
provided
(2.1)
com¬
parability graphs.
Theorem 1 An undirected
if G
is
irreflexive
and every
Note that in this theorem
vertex
ously
ing
(or
even an
edge)
a
graph G is a comparability graph if and only
cycle of odd length has a triangular chord.
cycle does
may
not have to be
occur more
than
this characterization is not very well suited for
'Throughout this chapter we represent
directed edges (a, 6) and (6,a).
9
an
undirected
simple, that is a
cycle. Obvi¬
algorithmic test.
in the
once
edge
an
ab by two correspond¬
10
Chapter
Transitive Orientation
2.
Gilmore and Hoffman rediscovered this characterization in
where
they
algorithm
man
E,
on
we
(a, b)
presented
some
lemmas which led to
a
first
[GH64]
recognition
for
did not
is based
set
also
comparability graphs. However, Gilmore and Hoff¬
analyze the running time of their simple algorithm which
the notion of
denote it
~
by
~
and define it
44
(a', b')
The
forcing.
a
=
a'
A
forcing
as
relation is defined
on
the
follows
{b, b') £
E
or
b
=
b'
A
(a, a') $
E.
(2.2)
This definition
tains the
F
implies
edge (a, b)
forces (a',b')
Based
that every transitive orientation F which
must also contain the
edge (a', b').
The
con¬
edge (a, b)
£
6 F and vice versa.
this local condition Gilmore and Hoffman start with
on
arbitrary edge which they orient arbitrarily. From this edge they
proceed by orienting all the forced edges until they either find a contra¬
diction or no further edges are forced. As long as not all the edges have
been oriented a new edge is oriented arbitrarily, forcing other edges in
turn. The symmetric closure of
is an equivalence relation which we
an
~
denote
by
cation,
the
The
~.
If
one
edge
equivalence
edges
in
and Hoffman
forces another then this is also called
classes of
~
are
implication class
an
algorithm
if
also called
are
choose
an
implication
all forced
by
impli¬
classes.
the Gilmore
of them for the
arbitrary
However, Gilmore and Hoffman only use this property of
implication classes implicitly. In [PLE71] Pnueli, Lempel and Even
introduce the concept of implication classes more clearly. They also
we
one
orientation.
V(A) of vertices spanned by an implication class
(though this term was only introduced in [Spi82]). A
discovered that the
forms
a
module
module is
a
set
set of vertices M C V for which
adj(z)HM^0
VzeV-M:
=>
adj(z)nM
=
M.
(2.3)
However, Pnueli,
Lempel and Even did not
Their
ties of this structure.
Gilmore and Hoffman
Golumbic in
of
[Gol77a].
comparability graphs
algorithm
algorithm and
and
only if A
n
A~x
an
it
was
exploit the possibili¬
improved version of the
the basis for the work of
Golumbic introduced
which relies
Theorem 2 An undirected
if
is
=
graph G
on
=
a new
characterization
implication classes.
(V, E)
is
a
comparability graph
0 for all implication classes A of E.
2.1.
Roots of
11
Origin
The structure of his
resembles the
algorithm
algorithms by GlLMORE
Even, but Golumbic ex¬
by Pnueli,
these algorithms. He in¬
in
what
actually goes on
poses more clearly
troduced the G-decomposition to derive a new characterization of com¬
parability graphs. A G-decomposition is a partition of the edges of
and Hoffman
G
=
{V, E)
Lempel and
or
such that
E
=
Si
W
B2
W
•
•
W
5fct
and
Bt is
implication
an
Gt
class in
=
(V,
E
B\
—
—
•
•
—
B,-i).
following
although he did not
To prove Theorem 2 Golumbic extended it and found the
theorem which
consider its
was
algorithmic aspects.
[Gol77b, Gal67]
Theorem 3
G-decomposition
equivalent:
1.
G
=
2. A n
3.
discovered by Gallai before,
(V,E)
A-1
BtDB~1
=
E
=
is
a
B\
W
For
B%
W
•
an
•
•
undirected
W
graph G
Bk the following
=
(V, E)
with
statements
are
comparability graph.
0 for all implication classes A of E.
=
$ fori
=
1,... ,k.
Golumbic observed that sometimes implication classes
were
united
graph. He was able
to show that if such a union takes place then implication classes have
to be united pairwise. He also showed that all implication classes At
are transitive if and only if every part B% of the G-decomposition is
transitive. Because of the definition of
as an equivalence relation this
if another
implication
class
was
removed from the
~
corresponds
to
Bt
n
B~x
=
0.
Structurally the Golumbic algorithm is determined by the defini¬
a G-decomposition. It arbitrarily picks an edge and successively
forces edges until an implication class B is found. The edges of B are
then removed from the graph, possibly resulting in the union of implica¬
tion classes. The algorithm continues to choose an edge and determine
the corresponding implication class to remove until it either finds a
contradiction or all edges have been deleted.
tion of
'We
use
W to indicate
a union
of
disjoint
sets
12
Chapter
2.
Transitive Orientation
Specialized algorithms on comparability graphs (e.g. finding a mini¬
coloring) usually depend on two preconditions. The input must
a comparability graph and a transitive orientation must be available.
mum
be
The
algorithms outlined so far recognize a comparability graph by
successively assigning a transitive orientation to its edges. In this way
We
we obviously satisfy both preconditions of specialized algorithms.
determine that a graph is a comparability graph and we also provide
a
transitive orientation because
we
construct it while
recognizing the
graph.
However, it is not necessary to establish these two properties at once.
possible to devise an algorithm which only determines if a
graph is a comparability graph (e.g. by orienting all implication classes)
it turned out that it is more interesting to perform transitive orientation
on its own. In [Spi85], Spinrad presented an 0{n2) algorithm to orient
a graph such that the orientation is transitive if the input graph is a
comparability graph. The algorithm always returns an orientation of the
undirected input graph, even if the graph is not a comparability graph.
In order to determine if the input graph is a comparability graph we
therefore have to test if the resulting orientation is transitive.
While it is
interesting, since it reduces comparability graph recog¬
transitivity in 0(n2) time. A simple test for tran¬
sitivity has the same running time behavior as a simple recognition
algorithm, but this can be improved. The test can be executed by com¬
puting the square of the adjacency matrix as defined in Appendix A.2.
This result is
nition to
Then
If
we
We
we
a
test for
can
a
in the output.
in the
input
is
position then the graph
is not
transitive, otherwise it is.
check if
find such
one
of the
zeros
compute the square of
an n x n
nonzero
boolean matrix in time
0(n2-38)
algorithm of Coppersmith and Winograd in [CW90]. How¬
fast
algorithms for boolean matrix multiplication are difficult to
ever,
implement and involve huge constant factors. We therefore present sim¬
pler approaches with good average case behavior. In Chapter 4 we show
how we can exploit the special structure of the input matrix in order to
get practical algorithms to test for transitivity.
using
the
Golumbic and Spinrad both have
presented algorithms to recog¬
comparability graphs, but both approaches are based on complex
theories. The Golumbic algorithm can be considered as a bottom-up
approach to comparability graph recognition. It is based on Theorem
14 in [Gol77a] which describes how implication classes merge when an
implication class is removed from the graph. The proof of this theorem
nize
13
Definitions
2.2.
is difficult to
understand,
but it is central in
and theorems used to prove that 5; n
equivalent
seems
like
to A D
a
lot of
A-1
=
theory
S,"1
a
=
series of about 20 lemmas
0 in
G-decomposition is
a graph. This
and probably originates
a
0 for all implication classes of
for
a
simple
from the omission of modules in the
statement
approach
of Golumbic.
algorithm of Spinrad is strongly based
availability of the modular decomposition
The transitive orientation
on
modules,
it presumes the
presented in [Spi82]. The structure was given different
previous literature, but Spinrad presented the first algorithm
to compute it in time 0(n2). Using the modular decomposition, which
is defined without reference to implication classes, he presented an algo¬
rithm for transitive orientation. However, this again created a complex
theory since implication classes are closely related to modules. Impli¬
cation classes appear implicitly in this theory, that is their properties
have to be established separately which complicates many statements.
which Spinrad
names
in
chapter we present a simplified theory for transitive orienta¬
tion, G-decomposition and modular decomposition which is basically a
synthesis of the theories of Golumbic and Spinrad. We demonstrate
the connection between modules and implication classes to yield a new
theory which is conceptually simpler than previous literature. Moreover
our theory directly motivates an algorithm for transitive orientation
which retains the 0(n2) running time without the two step approach of
In this
Spinrad.
2.2
Definitions
Before
describing
review
some
our
classical
algorithm for transitive orientation we want to
algorithms for comparability graph recognition.
Our basic notation is the
Appendix B. In this
entirely standard.
An induced
B CV and
subgraph Gg
edge set
EB
Gb
[PLE71]
we
by
of G
B.
[Gol80],
introduce
{ (a, b) I a, b
is said to be induced
defined in
E>,
=
in
same as
section
=
(V, E)
B
A
we
some
is
a
(a, b)
Further, for E'
have summarized it in
notation which is not
graph with
vertex set
}.
E
E,
we use
to denote the set of vertices which
are
V(E')
as
spanned by
14
Chapter
Transitive Orientation
2.
©
^V^
Figure
2.1:
with directed
the
on
A two-path from
edges on the left,
us
usual shortcut
our
for
undirected
graphs
right.
V(E')
Let
The representation
vertex 1 to vertex 3.
=
{
v
G V
|
3
u
V
G
:
(v, u)
restate the definition of ~, in
G
E'
V
(u, v)
undirected
an
G
E'}.
graph G
=
(V, E)
have
we
44
(a,6)~(a',6')
a
=
a'
A
(6,6') i
E
or
6
6'
=
A
(a,a') <£
E
(a, b) directly forces (a',b') if the vertices spanned by the
Because E does not
a two-path (see Figure 2.1).
edges
contain self-loops, it is not difficult to verify that (a, b)
(a, b) but
also that (a, b) / (6,a). The reflexive, transitive closure
of
is an
We say that
induce
two
~
~
~
equivalence relation. Its equivalence classes decompose the edges E of
G into implication classes. Two edges (a, b) and (c, d) are in the same
implication class if and only if there is a sequence of edges
(a, b)
(a0, &o)
-
~
We call this sequence
(a,b) forces (c,d)
(ai, *»i)
a
<•
(a, b)
~
(a,b)^(a',b')
(a, b)
^(a,6)
also
the
is the
use
=
an
edge
e
(a, 6)
(a0, b0)
to a node d if there is
(a* A)
to denote the
we
say that
(6',a')~(6,a).
^
=
with k > 0.
(a,b) to (c, (i) and
(c,d). Further we get
implication class of G which
{A^^y
(c, d)
=
~-chain from
whenever
A ~-chain leads from
(a*, &fc)
~
~
(c> d)>
fc > °-
contains the
implication
~-chain
a
class of
edge (a, b).
Gy which
We will
contains
edge (a, b).
Observation 4 Let A be
G
=
of
G.
(V, E)
Then
and
we
an
furthermore
implication
let T
=
class
(V, F)
be
of
a
have
inF^0
=>
ACF.
an
undirected
graph
transitive orientation
15
The Problem
2.3.
We will show that
which
we
define
Definition 5 Let G
called
a
if
module
an
=
the
(V, E)
if Gm
parallel
•
a
series module
•
a
neighborhood module if
a
related to
closely
a
module
A set M CV is
graph.
property holds:
adj(z)nM
=>
M.
=
module M is
a
module
module M
module
is
undirected
an
adj(^)nM^0
•
For
a
a
be
following
VzV-M:
Furthermore,
implication class
follows.
as
we
M', 0 ^
if Gm
^
M
connected,
is not
a
—
and
Gm and Gm
both
call the setV
M'
connected,
is n°t
M its
submodule
o,re
connected.
complement. Finally, we call
of M if it is a module in Gm-
already appeared implicitly in the proof of the first charac¬
comparability graphs by Ghouila-Houri in [GH62]. The
notion got different names in subsequent literature, e.g. partitive sets
in [Gol80], externally related sets in [HM79] or closed set. We will use
Modules
terization of
the term module which
2.3
was
introduced
by Spinrad
in
[Spi82].
The Problem
Transitive orientation is the first part of the fastest
algorithms
known
for
undirected
graph
G
comparability graph recognition.
=
(V,E)
we
have to determine
an
For
is
a
given
(V,F). While an
edges (u, v) and (v,u) only
=
graph simultaneously contains
edges is present in an orientation. That is,
subgraph of G with the same vertices and a subset
undirected
one
a
orientation T
of those
an
orientation
F of the
edges
for which
F U
In addition
definition
a
F'1
E
=
and
F P\ F_1
transitive orientation satisfies
have drawn
F2
=
0.
C F. To illustrate this
comparability graph together with a tran¬
sitive orientation in Figure 2.2. A graph always has an even number
of transitive orientations. The graph depicted in Figure 2.2 has four
we
a
transitive orientations. It is easy to
see
that the
reverse
of
a
transitive
Chapter
16
Figure
2.2:
orientation
not all
(T"
graphs
shown in
it is not
Figure
=
comparability graph and
(V,F))
do have
Figure
a
A
2.
a
is
always
a
Transitive Orientation
a
transitive orientation
transitive orientation.
Obviously
graph
transitive orientation. For instance the
2.3 does not have
a
transitive
orientation, and therefore
comparability graph.
2.3:
This
graph
tations is transitive.
is not
(The
a
double
comparability graph, none of its orien¬
arrows denote the forcing relation.)
problem consists of the assignment of a
a comparability graph.
However, in general
is
a comparability graph, but this
input graph
The transitive orientation
transitive orientation to
we
do not know if
our
exactly what we want to determine. The transitive orientation al¬
gorithm therefore assigns an orientation to every graph, even if it is
not a comparability graph. To recognize comparability graphs we then
have to test the resulting orientation for transitivity which we treat in
Chapter 4.
is
In the
tation.
following
section
we
present
our
algorithm for
transitive orien¬
An
2.4.
0(n2)
An
2.4
Transitive Orientation
0(n2)
17
Algorithm
Transitive Orientation
Algo¬
rithm
graphs which contain only parallel or series modules are
cographs. There is an incremental algorithm to recognize them
linear time, see Corneil, Perl and Stewart [CPS85]. These two
Undirected
called
in
kinds of modules
In the
same
are
trivial to orient
as
paper he also describes two
orientation of
Spinrad describes in
procedures
neighborhood modules which
possible to find a
graph
=
(V, E)
in time
0(|V|2)
His transitive orientation
position. This
graph,
it
leaves.
can
structure is
recursive
consists of the
are
We will show that the
a
can
be
to orient
our
algorithm
of the vertices of
labeled
according
types).
5 for the
to the
a
as
type
As series and
on a
modules.
process for
integrated
of
modular
based
the modular decom¬
recognition and orientation
simple
decomposition,
a
on
neighborhood
in the
solution which computes
and
one.
is based
are
a
trivial to orient the main part of Spinrad's paper
algorithm
borhood modules
part.
transitive orientation of
partitioning
they represent (see Definition
parallel modules
[Spi85].
transitive
tree structure with the vertices
a
The inner nodes of the tree
of module
yields
procedure
a
represented by
be
if there is
a
is the most difficult
Spinrad showed that it is
G
to find
within
algorithm
both,
a
This
transitive orientation
time
running
neigh¬
[CPS85].
0{\ V\2).
We
develop
combination of the theories of Golumbic and
Spinrad. We show that modular
decomposition and G-decomposition
a simpler concept of the theory of
imply
its
comparability graphs, especially
algorithmically relevant parts.
each other.
Our
approach
This leads to
does not
improve the running time of previous solu¬
conceptual simplicity. Even though there are now lin¬
ear algorithms for modular decomposition and transitive orientation we
think it is a valid goal to thrive for simplicity. This is certainly true for
the recognition of comparability graphs which involves more expensive
steps than the transitive orientation. For the problems which can now
be solved in linear time (e.g. the recognition of permutation graphs) we
may still gain some insight through our theory.
tions,
but the
We start this section with
some
theorems and lemmas about
we are
graph.
then able to derive
an
a
tran¬
decomposition. Using
algorithm for the transitive orientation
sitive orientation and the modular
We also show that the
running
our
time of
our
theorems
of a
transitive orientation
18
Chapter
algorithm
is bounded
We start with
[Gol80,
see
Lemma 6 Let A be
(V, E)
Classes and
technical fact which is
a
triangle lemma,
and let a,
Transitive Orientation
by 0(n2).
Implication
position
2.5
2.
an
b,z be
a
Lemma
Graph
simpler
a
Decom¬
version of Golumbic's
5.3].
implication class of an undirected graph G
triangle in G. For the edges (a, b), (a, z), (b, z)
=
find
we
(a,b)
Proof:
(y,b)
Let
observe y =£
we
our
be
an
edge
with
/
z£V(A).
=>
(a,b)
y and
that
(b, z) £
A.
The
a
~
(y,b).
First
contradiction to
contradiction follows for
same
hence
must hold. From the definition of
(a,b)~(y,b)
which
a
A
because otherwise there would be
z
assumption
(z,y) £ E,
AA{a,z) $ AA(b,z) $.
G
~
infer
we
{a,y)iE
=»
implies
Induction
on
the
length
(afl,^)
~
k of
an
(2:3,2:2)
~
~-chain
gives, using the
above arguments
and b and xk
y
(i) W,
as
l<t<k:
(2!fc_l, xk)%
(2:3,2:4)
repeatedly
with x^-2 and £fc-i
as
a
{xe,z)EA(xe,z)<£A,
(ii) z£{xi,...,xk}.
The lemma follows from part
tAn ~-chain
may also start with
(ii).
(xi,X2)
~
(xi,X3)
~
•
•
•
or
end with
(xfe,X(t_i)
Implication
2.5.
Classes and
Graph Decomposition
19
directly shows the second part of property 2 in [HM79]
originally found by Arditti in [Ard76]. The following lemma
corresponds to the first part of Arditti's property. Together with
This lemma
which
was
Lemmas 8 and 9 it
out the connection between modules and
points
implication
classes.
Lemma 7
[Gol80, Proposition 5.10] Let
V(A) is a module in G.
G,
A be
implication class of
an
then the set
Proof: Suppose
this lemma is wrong.
which is connected to
Then there is
but not all vertices in
some
V
a v
V(A).
—
V(A)
We define
R={ueV{A)\{u,v)E}
and
U
Because
Gv(A)
there exists
an
{u £V(A)\(u,v) $ E).
=
(there
is connected
edge (a, b)
must be
A with
a
~-chain to each
6 U and b £ R.
a
As
vertex),
(a, b)
A
we
obtain the contradiction
(a,b)eAA(b,v)eEA(a,v)<£E
Lemma 8 Let M be
an
a
implication class of
Proof:
Definition 5
z
V
M
x
implies
-
of
G
=
(V, E)
e A
and
=>
V(A).
6
v
furthermore
let A be
Then
A C M
either
x,y e M and
module
G.
(b,v)
=
or
An(M
that for all
x
M)
—
0.
edges (x,y),(y,z)
6
E with
M
{x,y)eEA{y,z)eE
=>
(x,z)eE
=
(x,y) •/> (y,z)
from which the lemma follows.
D
The next lemma outlines the
relationship between
spanning
V(A). It also implies the
[HM79] as a special case.
class A and its
property 1 in
set
Lemma 9 Let A and B be
implication classes of G
obtain
iflS
=
0
=>
V{A)^V{B).
an
implication
second
=
part of
(V, E).
We
Chapter
20
Transitive Orientation
2.
V(A)
V(B). Now look at a
V(A).
edges {a,c) G A and (b,c) G B.
Because (a, c) >/> (b,
infer
0 we get
(a, b) G E. By A D 5
c) we
(a, b) £ A or (a, 6) ^ 5. Let without loss of generality (a, b) £ B, then
Lemma 6 implies a £ V(B) in contradiction to V{A)
V(B).
Proof: Suppose
vertex
the contrary that
on
=
There must be
G
c
=
=
The next theorem will show the connection between
and the transitive orientation of the
Definition 10 Let T
G
=
(V, E); further,
called
=
let
induced^ by the
(V, F)
be
x
vertex
be
if
VzeV-M,veM:
That is in the
where
are
(sink)
source
ready
graph Tm&{z}
(1)
is
(2) Gm
(3)
Let M be
following
The
G
of a
following
F
the vertex
of G,
then T
(x, z)
«=>
£ F.
a source
or a
(only) entering edges.
no
is
condition holds:
is either
z
graph
undirected
module M
(v, z)
vertex with
an
sink,
Now
we
transitive
our
algorithm.
Theorem 11
M.
a
the
of
orientation
module M
a
give
we
to state the theorem which forms the basis of
orientation
in
is
First
vertex
a
x
an
graph.
a
module
of
are
a graph G
equivalent:
=
(V, E)
and
x
a
vertex
comparability graph.
and
G has
a
statements
G(y_M)a{x}
comparability graphs.
are
transitive orientation induced
a
by
x.
comparability graph" is a hereditary
a partial order and therefore it follows for
property.
For this reason the implication (1) => (2)
a comparability graph, too.
is trivial by inheritance of transitivity. As the implication (3) =>• (1) is
trivial as well, we only need to show (2) => (3).
Proof:
First notice that "to be
a
This is clear for
Let T
{M,F')
=
orientations of
F'"
Gm and
=
orientation induced
was
{{V
-
M)
W
{x},F")
G(v-m)w{x}- Furthermore,
{ (z, y) |
Our claim is that T
notion
=
we
be transitive
define F'"
as
{(y,z)\yeMAzeV-MA(x,z)eF"}
U
§This
and T"
=
by
first
y e M A
(V, F)
x.
z
with F
e V
=
-
M A
(z, x)
G
F"
FuF"U F'" is
As T" and T"
are
a
}.
transitive
transitive orientations
developed implicitly by Ghouila-Houri [GH62]
2.5.
of
Implication Classes
Gm and
and
Graph Decomposition
only
we
a,b,c eV with (a,b)
distinguished.
1.
{a, b) i
F'" and
must hold.
{b, c) i
F'". Either a,
edge (a, c)
The
and
G F
(b,c)
b,
c
G F.
G M
Four
or
a,
b,
induced
an
transitivity.
need to show its
three vertices
be
it is clear that T is
G(v-m)w{x} respectively,
orientation of G and
21
Consider
must
cases
c
6 V
-
F' and F"
must exist because
M
are
transitive.
2.
{a,b)
F'" and
G
follows and
we
F'".
(b,c) $
Suppose
(a,b)GF'"
by
F"
6
A
F"
(6, c)
(a,b)F"'
(a, 6) ^
4.
(a, 6)
F'" and
e
M,
b,c
so
G V
-
M
(z,6)gF"
=
F"
(x, c)
=*
by definition of F" and F'". In the other
6, c 6 M, the transitivity follows by
3.
6
10, which implies
Definition
(x, b)
a
obtain
(b,c)
F'" and
(a,x)eF"
=>
F'".
6
F'".
(b,c)
e V
a
case,
C F
M and
—
(a,c)eF"'.
=»
Analogous
F"'
(a, c)
=>
to 2.
For b e M the definition of F'"
implies
(a, a;)
G
F"
(x, c)
A
by the transitivity of F".
as we
G
F"
(a, c)
=>
The reverse, 6 G V
—
G
M,
F"
may not
occur
would find
(a, b)
which is
G
a
F'"
=
(a:, b)
G
F" und
(b, c)
G
F'"
=*>
contradiction to the definition of F"
oiG{v-M)u{x}the last
(6, x)
as an
G
F",
orientation
D
Note
that,
(u, v)
with u,v G M does not influence the orientation outside M.
as
case
may
never
apply,
the direction of any
edge
Any
Gm combined with the constructed orientation
edges yields a transitive orientation of G. The construc¬
transitive orientation for Gm is completely independent of the
transitive orientation of
of the other
tion of
a
construction of
The
proof of
an
following
induced orientation for the rest of the
graph.
Theorem 12 is identical to the induction step in the
Theorem 3. We
give
a new
constructive
proof
for the
necessity.
Chapter
22
implication class of a graph G
(V, E). G
comparability graph if and only if G'
(V,E A) and G"
(V, A)
Theorem 12 Let A be
is
a
a
=
module.
a
G induced
7, the spanning
Lemma
Therefore,
by
a
there is
V(A).
G
v
T'
is not
=
—
transitive orientation.
Proof: (=>) By
z
an
=
have
is
Transitive Orientation
2.
a
V(A)
set
of
an
implication class
(V, F) of
transitive orientation T
—
Now suppose
=
(V,F')
with F'
transitive orientation of G'
F-A
=
Then there exist vertices x, y,
G V with
(x,y)GF'
A
(y,z)eF'
(x,z)£F',
A
because T" is
obviously an orientation of G'. Because T is transitive,
edge in E and (x, z) £ F' implies (x, z) G A. On the other
A.
hand, we get (x,y) £ A and (y,z) ^ A, because (x,y), (y,z) G F
From this we observe by Lemma 6
(a;, z)
is
an
—
i v(A)
y
and
together
tion of F
a
source
as
or
(x, y), (y, z)
with
an
induced
sink in
a
therefore T' is
a
Tm\s{v}(V, A)
=
transitive. Then there
y would have to be either
Hence the assumption
where
wrong and
was
G A A
(b, c)
again
suppose
we
three nodes a,
are
(a, b)
we
contradiction to the defini¬
a
transitive orientation of G'.
Now consider T"
Now
G F this is
orientation, because
b,
G A A
c
that T" is not
with
(a, c) ^
A.
have
either
In the first
orientation
case
T\
—
(a,c)
G
A~x
or
consider, without
we
(V,Fi)
of G with
(a, b)
(a,c) £
loss of
G
F\.
A.
generality,
a
transitive
From Observation 4
get
(a, b)
G
On the other
(Fi
n
A)
hand, by
(a, 6)
G
ACFi
=$>
the
Fi
(b, c)
=>
transitivity of 7\
A
(6, c)
G
Fj
=$
we
G
Fi
A
(c, a)
have
(a, c)
G
F^
G
Fi.
we
Implication Classes
2.5.
Hence
we
obtain the contradiction
(a,c)
Fi A(c,o)
e
£
Fi.
Finally the case (a, c) ^ A must be considered. Let B
class containing (a, c) in G. Then Lemma 6 implies
b
With Theorem 11
induced
by
we
obtain
a
particular
for
v
=
be the
implication
i V{B).
T2
(V, F2) of G
F2 then
transitive orientation
Let without loss of
o.
Vt; £
and in
23
Graph Decomposition
and
K(5)
generality (a, b)
G
=
{v,b)£F2,
:
c
(c,b)eF2.
But this is
a
contradiction, too,
(a, b)
For this
e
T"
reason
(F2
n
A)
(V, A)
=
as
Observation 4
ACF2
=>
implies
(b, c)
=>
e
F2.
is transitive and this concludes the
proof of
the first part.
(«=) [Gol80,
of G' and G".
orientation T
(a, b),(b, c)
(6, c)
123]
(V, F)
=
F.
by transitivity
G
p.
Because F is
of G and
If both
of F'
F". Because
therefore the
Let F' and F" denote the transitive orientations
We need to show that F
or
or
be in E.
Now
F' and
(a, b)
7^
(6,
c) and
get (a, 6)
that
(a, c) ^ F.
suppose
observe
(c, a)
e F
Assume therefore that
(b, c)
edge (a, c) must
an
must not be in
orientation,
F' l±) F"
yields a transitive
by considering two edges
F" respectively, (a,c) exists
=
do this
in F'
are
F".
we
we
A,
we
=
F'
(c,a)F'A(a,6)GF'
=>
(c,i)ef
(6,c)eF"A(c,a)eF"
=>
(b,a)eF"
U
F". But for
or
we
get
{a,c)
a
contradiction to the definition of
For this
reason
F
=
an
implication
class and
We argue similarly if (a, 6) e F" and (6, c) e F'.
F' U F" is indeed a transitive orientation of G.
£ F must hold.
24
Chapter
2.6
The
Transitive Orientation
2.
Algorithm
With Theorem 12
our strategy becomes clear, namely: Find and orient
implication class and find the corresponding module. Orient the
submodules recursively and then assign the induced transitive orienta¬
tion to the entire graph. In order to find an implication class, we might
proceed in the same way as Golumbic in [Gol77b], but unfortunately
this requires too much time. Therefore we perform a reduced version of
Golumbic's procedure explore to find the set V(A) and use a different
scheme to orient the edges.
one
We start with
an
arbitrary edge {x,y), orient it and proceed from
spanned by the implication class -A(x,a).
there to collect all the vertices
These vertices must be
V(j4(X]!/)).
successively
adjacent
to
some
V(A(x,y))
To determine
collect the vertices in
a
but not all other vertices in
start with
we
x
and y and and
set B which violate the module
property of B.
In
algorithm
invariants of the
the
following
Algorithm
(1)
(2)
(3)
(4)
(5)
(6)
(7)
(8)
(9)
(10)
(11)
(12)
(13)
(14)
(15)
1 lines 2-5 initialize this condition for
loop
6-13 preserve this
property. They
lemma.
1 find.modulel
E);
procedure find_modulel((a;,2/)
B^{x};
Q^{y};
R<r-adj(x) -{y};
U <- V
({x} W adj(x));
-
while
q
Q # 0
<r- a
do
vertex in
Q;
Q^Q- {</};
Q<-Q\H{R- adj(g))
B <-BW{?};
R<r- i?nadj(g);
Ut-U-adJiq)-,
od
return
B;
end find.modulel
W
(U
n
adj(g)));
x
and y. The
are
stated in
2.6.
Algorithm
The
Lemma 13 For the
25
loop
algorithm
6-13 in
1 the
following
invariants
hold:
V
(2.4)
B\SQ\HR\SU
=
VrGflV&eB:
{r,b)E
(2.5)
VueUVbGB:
(u,b) <£
(2.6)
\/b£(B®Q)3b'
Proof:
assume
E
(x,y)~{b,b')\/(x,y)~(b',b).
eB:
(2.7)
The invariants hold after the initialization in lines 2-5.
that
they
loop
hold before the i-th execution of the
We
in lines 6-13
B',Q', R' and U' denote the corresponding sets after this execution.
(2.4) is maintained because every vertex removed from a set
will be added to exactly one of the other sets during the iteration.
Let
Invariant
Lines 7 and 8 do not
change
the
remaining
adds the vertex q to B and therefore
As in line 11
only
holds for R'.
from U and
added to
there is
a
Q
those vertices
Similarly,
(2.6)
to q
in line 12 all vertices
q'
(2.5)
ensure
and
stay in R, invariant
adjacent
to q
are
(2.6).
(2.5)
removed
One of the nodes q
(2.5)
of these vertices.
one
By
invariant
are
(2.7)
G B with
(x,y)
with invariant
adjacent
three invariants. Line 10
have to
holds for U'. The vertices removed from R and U
in line 9. Let b be
vertex
we
or
q'
~
(q,q')
or
(x,y)
~
(q',q).
fulfills the definition of b' for
b,
since
we
infer
So
we
have
for b G R
(q,q')~(b,q')
and for b G U with invariant
(2.6)
(q',q)
In both
cases
invariant
(2.7)
~
(b,q).
holds after the
loop as
loop.
well.
shown that all invariants hold at the end of the
Corollary
Proof:
14
find_modulel((a;,t/))
Consider the invariants
observe from invariant
(2.7)
returns
proved
in Lemma 13.
that
B C
V(A(X^).
V(AlXtV)).
In line 14
we
Chapter
26
With invariant
that B is
(2.6).
a
(2.4)
Q
and
=
0
we
2.
Transitive Orientation
find U W R
module at the end of the
=
procedure
V
-
B which
because of
implies
(2.5)
and
With Lemma 7 this implies
x£V(A{x,y)).
Wxe(U\HR):
=
U
V-B
procedure find.modulel all the vertices spanned by the implication
containing {x,y) have been found. Invariants (2.4),(2.5) and (2.6)
make clear that V(A(X^) is a module and (2.7) shows that the edges
between its vertices contain an implication class. Before looking at the
implementation of find_modulel, some modification is necessary because
we want to orient the edges of A^x^ and not just find its spanning
After
class
vertices.
Observation: We
can
modify procedure find-tnodulel
minimal module containing
a
vertex
x
a
set of vertices
V
C V.
to
compute the
At first
we
choose
£V' and initialize B,Q,R and U accordingly. The algorithm
successively adds all the
Note however that
vertices to B which violate the module property.
cannot maintain invariant
we
(2.7)
for this modified
algorithm.
Definition 15 Let A be
set S C
V(A)
called
is
x£SAy£V(A)-S
V(x,y)E:
Furthermore,
we
implication class of a graphG. A non-empty
splitting set of V(A) if
an
a
(x,y)
e
A.
denote with
S{A)
the set
=>
=
(Sx(V(A)-S)nA)
of splitting edges.
a splitting set for a module V{A) of a compara¬
(V,E). Further, let A' be a subset of A containing
bility graph G
the splitting edges of S. Then for given sets V(A), S, and A' a call
refine(V(A),S,A') (see algorithm 2) computes the implication class A
Lemma 16 Let S be
=
and
a
partition Part
=
{Z\,... ,ZS} of V(A)
Gv(A)-A
=
with
GZl\a---\aGZs.
2.6.
The
27
Algorithm
Algorithm
2 refine
procedure ref\ne(V(A),S, A');
(1)
(2)
(3)
(4)
(5)
(6)
(7)
(8)
(9)
(10)
(11)
(12)
(13)
(14)
(15)
(16)
(17)
(18)
(19)
(20)
{S, V(A) S}; (* Initial decomposition *)
S; out(V(A)
S) <- S;
out(S) <- V(A)
while 3 Z e Part with out(Z) ^ 0 do
choose a vertex v from out(Z) and remove it;
Z'<-Z n adj(v); Z" i-Z
udj(v);
Part
<-
-
-
-
-
if
0 # Z' ^ Z then
out(Z') <- out{Z) l±l Z";
out(Z")<-out(Z)WZ';
Part ^-(Part-Z)WZ'WZ";
E with u; e Z'
forall (u;, u)
if («,«;) Gi4'
then i4'<- A'u{(u,w)};
else il'^-i4'U{(t«,u)};
A
u
6
Z" do
fi;
od;
fi;
od;
(A', Part);
return
end
refine;
Zi are distinct submodules of V(A) and all edges be¬
Z{ and Zj, i ^ j, belong to A. The running time of the call
That is the sets
tween
refine(V(A),S,A')
is bounded
by
0(\®(V(A))-
[J
Ki<s
®(Zi)|).
Proof: Let us consider a call refine(V(A),S, A'), where A' contains the
splitting edges of S (see algorithm 2). The procedure works by refining
a partition Part of the vertices which is initialized with 5 and V(A)
S
-
where
we
we
have
have oriented all
a
set
out(Z)
out(S)
edges
in between. For each element Z 6 Part
which is initialized
=
V(A)
This initialization fulfills the
-
S and
as
follows:
out(V(A)
following
-
S)
=
S.
invariants for the
loop
4-18:
Chapter
28
(i)
Zx
For any set
(ii)
£ Part and any vertex
adj(x)
have either
we
£
Zi,y
Z\
=
0
£
x
(V(A)
adj(a;)
or
n
which makes
out(S)
(i)
the parameters
of the
1.
loop
=
v
0)
5)
-
(ii)
trivial and
V(A),S
PI Z
=
which
W
ou*(V(,4)
equivalent
is
and A'. Induction
following
-
S)
the number of executions
D Z
adj(v) and Z"
(Z\ l±l out(Zi))
=
^
Z
x
7^
Z.
then
adj(:r)nZ
v,
=
equivalent
We
adj(u).
(i) does
-
assumption.
out(Z))),
we
For
to the
replace
If
Zx
not
the set Part
the induction
Z\
case
as¬
Z and
=
assumptions.
Z in Part
$ { Z',
change
Z"
}
by Z'
and
x
and it holds
{Z',Z"}
Zx
and
x
£
£
-
the in¬
by
(V{A)
Z n
=
V{A)
-
(Z
ttl
find
z=^uz"
0
case
=
is
V(A)
=
input conditions of
to the
on
i.
C
cases:
or
again
0 # adj(u)
duction
E with
loop gives:
Z). In this
(adj(u) C\Z
remains unchanged and (ii) holds because of
sumption. For (i) we only need to prove the
x
2.
(V{A)
=
leads to the
(adj(u)
(Z\ \t)out(Zi)))
Z\.
Z2 the
£
The initialization before the first execution of the
S W
Z\
-
=
Zi,Z2 £ Part and for any edge (x,y) £
following holds: Zx ^ Z2 => (z,y) £ i'
For any two sets
x
n
Transitive Orientation
2.
adj(:r)nZ'=0Aadj(aOnZ"
=
0
or
adj(x)nZ
Z
=
z=z^z"
adj(x)nZ'
=
Z'
Aadj(i)nZ"
=
Z".
The induction
assumption guarantees that either the first or the
implication holds, such that x fulfills (i) even after the
execution of the loop 4-18. The last case is Z\ £ { Z', Z" } and
x
v, but here (i) holds after the loop because of the definition
of Z' and Z" respectively. For invariant (ii) it is enough to show
that any edge (w,u) £ E with w £ Z' and u £ Z" must be in A.
The definition of Z' and Z" in line 6 gives
second
=
(v,w)
E/\(w,u)
With the induction
as
claimed and
we
E
A(v,u) £
assumption (v, w)
have
proved
both
E
£
=>
A'
our
(v,w)
C A
we
~
find
invariants.
(u,w).
(u, w)
£
A
The
2.6.
loop
The
Algorithm
4-18 terminates because there
elements in the
a
set
29
out(Z).
partition
and in each
can
be
no
at least
loop
|V(A)|
than
more
one v
is removed from
When the termination condition is reached
out(Z)
0
=
holds for any set Z G Part. Combining this with invariant (i) we find
for all sets Z G Part and for all vertices x G (V(-A)
(Zfctl out(Z))) that
—
either
adj(z)nZ
By Definition 5, out(Z)
in
GV(A)- Together
a£
0
=
or
adj(z)nZ
0 implies that
=
Z.
=
any Z G Part is
a
module
with Lemma 13 this shows for any three vertices
V(A)-Z, b,ceZ
(a,b)
which
G
EA(b,c)£E
(a,c)
=>
G E
=>
(a,b) ^ (c,b),
implies
An(ZixZi)
=
(D.
Since this holds for any element of the final partition,
(ii)
By
comparability graph, therefore Theorem 3 part
which implies A'
A at the end of refine.
with invariant
that A
A' U A'~
=
our
.
2
we can
conclude
precondition G
is
A D A"1
requires
a
=
0
=
For the
running
sult which is based
implementation
the
same
the
of refine
graph G. The
in the
=
set E and the
matrix, this allows
in constant time for any
we
procedure refine we want to prove a re¬
resulting partition Part
{Z\,..., Zs}. The
relies on an adjacency matrix representation of
time of the
on
may state that
one
implication classes At
to evaluate
pair (x, y)
G V
x
"(z, y)
may be stored
"(x, y)
G £"' or
V. With this
G A"
representation
execution of lines 11-16 costs time
0(\Z'\ \Z"\)
proportional to the maximal number of edges in Z' x Z". As
the elements of the partition are never united, no subsequent execution
of lines 11-16 will examine these edges again. If we sum over all execu¬
tions of lines 11-16, the running time is limited by the total number of
which is
examined
edges. This
is
given by
\®(V(A))-
(J
®(Z0|.
(2.8)
1<1<S
Note that
Zj
none
of the
would not be
The matrix
follows:
an
edges
in
<2>(Zj)
is
ever
element of the final
representation
examined because otherwise
partition.
allows the
implementation
of line 6
as
30
Chapter
(1)
(2)
(3)
(4)
(5)
(6)
(7)
Z'
0; Z"
<-
0;
forall weZdo
X(v,w)eE
then Z' <-Z'\t)
else Z"
Z"
+-
{w}
{w}
W
fl
od
We
compute the
now
of times
(v,w)
«-
Transitive Orientation
2.
edge
an
cost of line 6. As
above,
is examined in line 6 and
which is examined in line 6 is
out(Z). For any set
out(Z) U Z J v holds.
only
again
we
count the number
we
find that
examined
edge
an
because
once
v
is
removed from
Z'" which contains
out(Z'")
We find that in line 6 there will be
no more
C
subsequently,
w
than
0(\®(V(A))-
|J
®(Z,)|)
(2.9)
1<1<S
time spent.
So there
as
only
linear lists.
out(Z)
and
once
anymore.
remain lines 8 and 9.
The cost of
copying
are
extended,
one
the sets
implement
out{Z")
and
the list itself because
reuse
These lists
We
out(Z')
To find the lists
by Z".
newly created list.
proportional to the total
and the other
is attributed to the cost of the
The total cost of lines 8-9
(including
line
2)
is
number of list elements created. But any list element may
once
as
vertex
in line 6 and
v
of executions of the
loop 4-18.
loop, this
each execution of the
together which is
summing up (2.8)
We
which,
now
state
when
and
splitting
(2.9)
for
equal
serve
As the cost of line 6 is at least
0(1)
9 and 2
more
than the cost of lines
expression
running
its
a
in
8,
in
(2.9). Now,
time for refine.
splitting
set
S
computation.
implication class of G with (x,y)
implication class exists if
an
the
exactly
to the number
is
leads to the claimed
satisfied, allows
set S
this number is
condition for the existence of such
Lemma 17 Let A be
a
so
therefore also less than the
a
out(Z)
copy the list
do not need it for Z
we
by Z'
we
3zeV{A)-{x,y}:
(x,z) <£
E A
(y,z) i
E.
E A.
Then
The
2.6.
Proof: We
base
31
Algorithm
construct
splitting
a
set
using procedure find_modulel and
procedure. Consider a
argument edge. B.l,Ul,Rl,Ql
qt indicate the contents of the corresponding variables after the
execution of line 7 in the loop 6-13. The index i
oo denotes
situation at the end of the procedure. By induction on i we define
0
mappings d(v) and dd(v) for all vertices v £ V. Initially for i
vertices v £ Q0 let
method
our
the structure of this
on
(x,y)
of find_modulel with
the
as
=
=
d(v)
=
and
x
dd(v)
<=»
y
=
v
£
adj(x)
-
call
and
i-th
the
two
and
adj(y)
(2.10)
and
d(v)
=
y and
dd(v)
=
<=>
x
v
adj(y)
—
adj(x).
(2.11)
For
vertex
a
(Qt+i
v
d(v)
—
—
Q%) ^ 0,
qt and
dd(v)
i >
1,
d(qt)
=
define
we
«=^
v
G
Ut
(2.12)
Rt.
(2.13)
and
d(v)
(2.12)
Case
called
a
=
d(qt)
dd(v)
=
q,
<=>
v
G
forward implication whereas situation (2.13) is
implication. Directly from this definition we find for
is called
backward
and
a
x^v^y
(v,d{v))
By
induction
on
i
we
{dd{v),d{v)).
~
(2.14)
have
VvQ,
:
d(v),dd(v)
Bt
(2.15)
and
VveB^.
Let j be the
That
j
we
largest
<
j
<
(2.16)
index such that
is, in step j there
find 1
(v,d(v))A.
was
\V(A)\
adjfe)nt/J^0.
(2.17)
the last forward
implication. For this index
preconditions of Lemma 17
-3. Because of the
32
Chapter
there is
a
vertex
V(A)
G
z
therefore must be in
£/0.
which is neither
Next
S
is
splitting
a
G
w
Boo
by
(Q3+i
(2.19)
C\
BJ+1
-
definition
R3)
is true for
is also correct for
implications
implies
(2.19)
Qt,
Next
we
we
U
•
•
•
was
q3
(2 15)
G
w
d(qt)
=
Q8+i
is correct for
B3
(2.19)
B]+i.
G
just added
to
1.
G
Qoo
U
=
Qt+\
—
Bj+i.
together
Boo
—
with
BJ+i
argumentation.
G
E with
a
splitting
s
G S and
w
G
set
Let
.
V{A)
—
us
S.
consider
By
an
definition
(2.20)
=
of the
following
three
cases
must be true:
q3. Lemma 13 gives:
(2.21)
(s,q,)eA.
2.
the step
know
one
w
B}
B]+1.
C
weBoo-Bj.
Now,
edges
Assume
G
and this
show that S indeed is
arbitrary edge (s, to)
of S
all the
inductively that (2.19)
Qt- As all subsequent
implications, the induction hypothesis
must be backward
our
as
Q3+i-
G
w
d{w)
:
j + 1 < i. Let
Qj+i
completes
(2.18)
get
we
d{w)
Hence
to y and
nor
UJr\a,d){qJ)
=
d(w) =d{qJ)
Therefore
x
-
G S this holds
w
to
V(A). To do this we have to show that
V(A) S lie in A. First we show that
Vw G
before. For
adjacent
show that
we
set for
between S and
For
Transitive Orientation
2.
lii/jjA d(w) ^
q3. From equation
(2.19)
we
derive
d(w)BJLem^13(s,d(w))iE
which in turn
implies
(w,s)~(w,d{w))
(U6)
{w,s)eA.
(2.22)
The
2.6.
3.
w
Algorithm
^ q}
dd(q3)
Lemma
and
d(w)
q3. With (2.20) w e R3 must hold, (2.15) gives
and
(2.17) implies s G U,. All this, together with
Bj
13 and (2.14) implies {dd(q3),s) <fc E, (dd{qJ),q]) g E
A
G
33
=
{dd{q3),w)
-
A
(2 16)
3
E. So
we
(w, d(w))
find the —chain
=
(w, q3)
(w, dd{qj))
~
~
(w, s)
(2.23)
(w, s)
which shows that
Our
A
as
claimed.
goal is the integration of refine into find.modulel such that
running time does not exceed the time bound of refine. In
achieve this running time, V(A) must be a neighborhood mod¬
next
the combined
order to
ule. We must make
parallel
is
module
as
is not
a
guaranteed
to be
connected). Fortunately
small
subgraph which
neighborhood module.
a
a
chordless
Theorem 19
ing
statements
path
[CLS81J
are
,
xS!
(xt,Xj)
Vl<i<J<s:
is
series module
s
>
E <=3> i + 1
For
an
undirected
graph
G
if
j.
=
(V, E),
the
follow¬
equivalent.
•
G does not contain
a
neighborhood module.
•
G does not contain
a
P4.
For this
a
Xi,X2,X3,x$.
G
a
=
a
there
is called chordless
3,
•
is
cannot be
is necessary and sufficient to characterize
Definition 18 A simple path xi,...
A P4
(it
V(A)
that
sure
it is
cograph.
reason
the
required initialization
is
given by
a
P4.
Lemma 20 Let xi,... £4 be a P4 in a comparability graph G
Further, let A be the implication class containing (xj,X2). Then
=
,
procedure find_module(V, xi,... X4) computes V(A),
of V{A) in submodules Part
{Z\,... Zs} of V(A)
,
=
,
Gv{A)-A
=
Gz,®---\&GZa.
A and
with
a
(V, E).
a
call to
partition
Chapter
34
Algorithm
(1)
(2)
(3)
(4)
(5)
(6)
(7)
(8)
(9)
(10)
(11)
(12)
(13)
(14)
(15)
(16)
(17)
(18)
(19)
3 find.module
procedure find_module(V,
x
a
chordless
path
x\,...
,X4);
0;
y 4— X2\ S 4-
<— xi;
A4-{(x,y)}; B 4-{x,y}\
U 4-V
({x} U adj(x) U {y} U adj(j/));
fl<-adj(x)nadj(j/);
Q 4- (adj(x) Uadj(y))
(adj(x) n adj(y));
forall v
adj(x)
adj(i/) do
d(v) 4- x; dd(v) 4— y;
A 4- A&{(x,v)};
-
-
—
od;
forall
A
adj(y)
G
v
d(v)
4—
4-
y\
Am
adj(x)
dd(v) 4- x;
{(v,y)};
do
—
od;
while
if
Q yt 0 do
x3,x4
nQ/fi
then choose X3
else choose
a
or
q and
as
X4
remove
Q and
vertex q
remove
it from
Q;
it;
A;
4- BttJ {<?};
adj(g) n [/ / 0 then q3 4- q;S 4- adj(g) n
forall «£((fi- adj(g)) U (U n adj(q))) do
if (g,i;)
£
then d(v) 4- q; dd{v) 4- d{q); U 4- U
else d(v) 4- d(q); dd(v) 4- q; R 4- R
(20)
(21)
(22)
(23)
(24)
(25)
(26)
(27)
(28)
(29)
(30)
(31)
(32)
Transitive Orientation
2.
B
if
1/
fi;
{v};
{v};
—
—
fi;
Q 4-QH){v};
if
(d(u),dd(i;))
else /I
<-
6 A then .4
<-
A®
{{d{v),v)};
{(v,d(v))};
.41+1
fi;
od;
od;
(33)
(34)
(35)
(36)
(37)
(38)
forall
(39)
(40)
od;
(41)
(42)
return
s
e S do
forall
if
w
G
adj(s)
(u),d(u;))
else A
n
(B
-
4-
A\tl
od;
<- reRne(B,S,A);
(B, A, Part);
end find-module
l±l
{<7j}))
<-
{(s,w)};
fi;
(A, Part)
(5
G A then A
.4 l±t
do
{(u>, s)};
The
2.6.
35
Algorithm
running time of find-module(V,Xi,... ,£4)
of \V\ and the number of pairs in
The
sum
is
\J
V(A)x(V-V(A))U®(V(A))-
to the
proportional
®{Zl).
1<1<S
Lines 2-32 represent
Proof:
this
reason
Next
the correct
that x\
we see
Lemma 17. For this
=
a more
detailed version of find.modulel. For
computation of V(A) follows from Corollary 14.
z fulfill the precondition of
x, x^
y and £4
=
=
reason a
nonempty splitting
Because lines 33-39 represent
line 33.
statements
(2.21)-(2.23)
a
direct
set S is determined in
implementation of the
splitting
of Lemma 17, the set A contains all
edges of S after line 39. But now in line 40 the sets V(A), S and A fulfill
the precondition of Lemma 16, which implies the correct computation
of A and Part.
To analyze the running time of find_module we again use the matrix
representation of the graph G. With this representation the loop in
lines 7-10 looks
forall
Lines 3-14
v
e
can
follows
as
V do if
be
loop
e E A
(y, v) $
implemented similarly.
executed in linear time,
lines. For the
(x, v)
so no more
15-32
the 2-th execution of this
...
We find that
0(|V|)
fi
od;
they
can
be
time is spent in these
the same implementation. The cost of
proportional to the number of possible
we use
loop
than
E then
is
edges
(qt,u),
loop
The
22-31 is
implemented
forall
v
G
forall
v
£ U do if
and
we
utRiUU,.
R do if
(q, v) £
(q, v) £
as
E then
...
fi
E then
...
fi
observe two facts. First of all,
no
od;
od;
edges from
(V-V(A))x(V-V(A))
are
examined in lines 15-32 because
q%iV- V(A)
holds for all qt. A similar result is found for
submodules. Let M £ Part be
a
edges between vertices of
V(A), M C V{A), then
submodule of
\{xu... ,i4}nM|<l.
(2.24)
36
Chapter
To verify (2.24), remember that xi,...
implies that all edges (xi, xl+i), 1 < i < 3,
From this
because
verify
{
by
Lemma
do not
,
chordless
A
path.
=
This
A(XltX2).
{xt,xl+l}%M,
cV(A).
Without loss of
that the two other cases,
xi,...
a
elements of
8, the contrary would imply V(A)
M
assumption
our
,x4 is
are
infer
we
Vl<i<3:
to
Transitive Orientation
2.
}
x4
apply.
n M
In the first
case
Va,beV{A)-M
M
generality,
as
opposed
it remains to
namely
{ xi, x3 }
=
C
{
or
xi,...
Definition 5
:
adj (a)
x4
,
}
n M
=
{
xi, x4
}
requires
n M
=
adj (6)
n M
(2.25)
which
implies
adj(a;2) f){xi,x3}
a
=
adj(ar4)
{xi,x3},
n
contradiction to the definition of x\,... ,X4
same
contradiction arises in the second
as
chordless
a
path. The
(2.24)
and statement
case
is
proved.
Therefore
1.
{
X\, X2
one
of the
} flM
=
easily derive
the
by
induction
i.
on
following
|V(j4)|:
This shows that
in the
holds for M.
invariant for
loop
=
or
in
f/o and
15-32 from
(2.25)
MC(B,UQ,).
(2.26)
the current execution of the
loop
no
edge
may be examined.
{ii,i2}nM={ii}.
adjacent
of the choice q\
cases
Mn(5,UQ,)^
during
graph Gm
but not
three
0. Then M is either contained in Rq
we
Vl<t<
2.
following
Then every node
to x3.
=
(xi,x2)
x3
~
we
By (2.24)
we
v
M is
have x2,x3
adjacent to xi
g M. Because
get
(x3,x2)
~
(v,x2)
=^
MCQj.
The
2.6.
3.
{
37
Algorithm
}
xi, x2
n M
{
=
adjacent
but not
{x1,x2)
x2
Then every node
}•
to £4. With q\
(x3, x2)
~
Therefore the cost of the
~
(x3, xA)
v
E M is
X3 and q2
=
~
=
(x3,u)
£4
adjacent
we
M C
=>•
to X3
find
Q2.
15-32 without the first two executions is
loop
by
bounded
0(\V(A)x(V-V(A))\
+
(J
\®(V(A))-
®(Zfc)|).
(2.27)
i<h<*
The first two executions of the
clearly bounded by |V|.
consider edges in Gzk by definition of
loop 15-32
Finally, in lines 33-39 we do not
Part. Adding the cost of find_module
0(\V\)
+
0(\V(A)
are
without refine
we
\J
(V -V(A))\ + \®(V(A))-
x
obtain
®(Zfc)|).
l<h<s
This time bound also holds for
Next
we
cographs
Corneil,
present
have
a
some
unique
refine,
Lemma 16.
see
properties of cographs.
tree
representation,
Lerchs and Stewart
[CLS81].
the
First
so
we
note that
called cotree,
see
The leaves of the cotree
represent the vertices of the graph G. Internal nodes are labeled P
or S such that the nodes on every path from the root to a leaf are
V are adjacent
alternatively. In this tree two vertices x,y
the tree meets
the
from
of
root
to
the
r
if
x
only
unique path
the unique path from y to r at a node z with label S. The node z
labeled
if and
is called the nearest
common
ancestor of
x
and y.
The cotree
can
be
following way. Since the vertex set V of a cograph
(trivial) module, Theorem 19 requires that either G
constructed in the
(V, E)
G
=
or
G is not connected.
is
a
In the former
case we
recursively build
for the connected components of G and make them children of
created root
r
r
with label P. In the latter
case
cotrees
a
newly
replace G by G and label
with S.
In [CPS85] an 0(n + m) algorithm is presented for the recognition
cographs and the construction of the corresponding cotrees. For us
the most interesting aspect of this algorithm is that it proceeds in¬
crementally, that is the vertices are processed one at a time. Note
that the cograph property is hereditary, therefore the induced subgraph
Gx,X c V of a cograph G
(V,E) is also a cograph. The results of
of
=
[CPS85]
can
be summarized in
Chapter
38
Theorem 21 Let Gx, X
G
{V,E) and let v be
—
cograph
not
is
a
time
in
cograph,
V, be
vertex
0(|adj(u)|) if
then
a
subgraph of
a
V
in
Tx- Then the
with given cotree
determined
c
a
—
cotree
an
graph
undirected
Further, let Gx be
X.
a
7xu{«} °fGxu{v]
Moreover, ifGxu{v]
can
be
it exists at all.
forbidden subgraph, namely
Although the argumentation presented
P4 only for one of several cases it is not
algorithm to find a P\ in all cases.
Theorem 21 will be
Transitive Orientation
2.
in
[CPS85]
a
P±,
found.
is
shows how to find
difficult to extend the
a
presented
central argument in developing our final
procedure orient (see algorithm 4). First we
show that this procedure is correct, that is the output T
(V,F) is
a transitive orientation of the undirected graph G
(V, E) if such an
orientation exists at all. For this proof we use induction on the number
our
recursion scheme in the
=
=
n
of vertices in G. Let
we
initialize F
as
an
consider the main call of
us
empty
Next,
set.
we
orient(V, 0,0).
check for the
in order to avoid trivial calls.
The parameters C and
The induction starts with
1, but this
n
=
case
case
Tc
are
V
First
=
0,
empty.
is trivial because there
assume
a call of
edges
for
transitive
orientation
all
a
orient(V, C", Tc) computes
comparability
graphs with \V'\ < n, where C" is a subset of V and Gc is a cograph
are
to orient.
no
Tc^-
with cotree
We
Then
correct orientation of G
we
for the induction that
onent(V,0,0)
have to show that
finds
a
(V,E).
=
an incremental way if G is a cograph
By this an induced subgraph Gc, C C V, is computed which is a
cograph with cotree Tc If the condition in line 7 is always false then
the loop 3-31 stops with Gc
G and G is a cograph. In this case a
transitive orientation of G is given by
In
loop
3-31
first test in
we
=
Lemma 22
[Spi85]
Gc be
corresponding cotree
edges
of the parallel
nodes of a cotree, a transitive orientation T
(C, F) of Gc is given by
Let
a transitive orientation of edges between children of series nodes.
be
the
children
node
where
the
of a series
ordering on the
ci,...,cs
v,
children is arbitrary but fixed. Furthermore, let C, the set of leaves in
the subtree of c%. Then we define
Tc-
Since there
are
Let
no
a
cograph with
different
between
a
children
=
Vm G
Ct,v
G
Cj,l
< i, j < s
:
(u, v)
G F
<=>
1
< J.
'The parameters C and Tc are introduced to speed up the running time
fact, they could be dropped during the discussion of correctness
matter of
As
a
2.6.
The
Algorithm
Algorithm
(1)
(2)
(3)
4 orient
procedure orient(V, C, 7c);
(*
C C V, Tc is the cotree of Gc
while V
(4)
/ 0
C
-
choose
(5)
(6)
(7)
(8)
(9)
(10)
(11)
(12)
(13)
(14)
(15)
(16)
(17)
(18)
(19)
(20)
from V
v
Tcm{v}
C;
7cu{ v};
cotree
undefined then
let x\,...
be
X4
,
a
(V(A), A, Part)
F
—
-{v};
compute the
if
*)
do
vertex
a
V ^V
^
chordless path in
<-
Gc®{ v}!
find-module(V, xi,...,x4);
FuA;
\Z\
forall Z S Part with
Cz
<-
z n
> 2 do
C;
compute the cotree
7cz;
orient(Z, Cz, Tcz);
od;
let
x
be
of the vertices in
one
{ xi,..
.
,
14
V'<-V-(V(A)-{x});
C<-C-(V(A)-{x});
compute the
if
(21)
(22)
(23)
(24)
(25)
(26)
(27)
(28)
(29)
(30)
(31)
(32)
(33)
(34)
(35)
(36)
(37)
39
\V'\
forall
if
V'
w
(x, tu)
—
Tc';
orient(V", C", Tc) fi;
{x}
do
F then
forall
F
if
cotree
> 2 then
2
«-
(w,x)
forall
6
V{A)
{ x } do
{ (z, w) } od; fi;
-
F l±l
6F then
z
e
{ x } do
{ (w, z) } od fi;
F(,4)
F <r- F l±l
-
od;
V<-0; C<-0;
else C
•<-
C1+1
{v}
fi;
od;
if
|C|
> 2
then orient the
cograph Gc
add this orientation to F
fi;
end orient;
with Lemma
22;
}
fl
C;
Chapter
40
Algorithm
(1)
(2)
(3)
(4)
(5)
(6)
(7)
(8)
Transitive Orientation
2.
5 transitive.orientation
procedure transitive_orientation(G);
F<-0;
\V\
if
> 1
then
Fir-
orient(V,0,0);
fi;
return
F;
transitive.orientation;
end
The transitive orientation T
—
(C, F)
can
computed
be
in linear time.
Otherwise, if the condition in line 7 is true then the subgraph Gc&{ v}
is no longer a cograph. Now we may conclude with Theorem 19 that
this graph contains a chordless path x\,... ,x\. By Lemma 20 the call
find_module(Vr, xi,... ,2:4)
a partition Part of V(A)
is
module.
a
for
This allows
Gy by Theorem
With Theorem 12
line
10, and
that
Gy(A)
determines the sets A
in submodules.
a
~
a
to find
us
an
=
A(XltX2), V(A)
Lemma 7 the set
By
and
V(A)
induced transitive orientation
GV(a) and G(V-V(A))w{x}T-y(A) °- -*v(A) ls given by A,
11 from orientations of
correct orientation
transitive orientation of
A consists of vertex
GV(A)
-
A
=
Gy(A)
Lemma 20 shows
~
--
disjoint components
GZl
W
Gz2
W
•
•
•
l±l
GZs
with
Part
=
{Z1,Z2,...,Z.}.
\V\ for 1 < i < s, orient(Z,,...) finds a
Gz, because of the induction assumption,
V{A))W{x}\
{zi,... ,£4} C V(A), we obtain |(V
Since
\Zt\
transitive orien¬
<
line 11-15.
tation of
<
-
our
induction
fore
orient(CK
tation
—
V(A))
T(y-v(A))i£{x}-
Gy
for
assumption
W
{
is
x
always
true for
},...) always
In lines 22-27
which is induced
by
x
we
n
G(v-v(A))v{x}
computes
find
a
a
-
1.
As
Hence
and there¬
transitive orien¬
transitive orientation
and which contains
both, TV{a) and
T(V-V(A))ti){x}arguments show that the recursion terminates, since we have
|V| for any recursive call orient(V,...). Therefore, our scheme
These
|V'|
<
2.6.
The
41
Algorithm
correctly computes
In the
first cost
can
be
Gv(A)
A.
~
split
into three
orien¬
an
{ Z\,... Zs } denotes the partition
let z%
\ZX\ and k
\V(A)\. A
=
,
Furthermore,
=
—
category arises from the subgraph Go The
ignore the
we
the set Part
following,
of vertices in
a graph G if such
running time.
transitive orientation of
a
tation exists. It remains to determine the
categories according
recursive calls inside
cost of find_module
to Lemma 20.
orient(V,...)
To that end
for the moment. We
distinguish the cost of initialization, for which we will give an upper
bound, the cost of finding the set V{A) and the cost of orienting all the
edges of A.
K\{V)
is the cost of
building
and
Gc<s{
is
cost of line 6 if
condition
"|C|
d
}
orienting the cograph Gc, that
a
cograph
is the
and the cost of line 34 if the
> 2" is true.
K2{V)
is the cost less than
K3(V)
is the cost
0(n)y
proportional
to
\V
-
V{A)\ \V(A)\
K±(V) represents the cost of find-module which
ther K2{V) nor K3(V) in which case
K4(V)=0{\®(V(A))-
is
(J
and
proportionnal
to nei¬
®(Z,)|).
1<1<S
orient(F, C, Tc) the induced subgraph Gc of G always forms
cograph. Throughout a call to orient(V, C, Tc) we increase the size of
C by adding vertices or we split C into different parts for recursive calls,
For the call
a
but
we never remove
again.
elements from C such that
they have
to be added
C is an element of V for
following holds: If v
a recursive call orient(V", C", Tc) then v is also an element of C". This
shows that line 6 is successfully executed at most once for a fixed vertex
v during all calls of orient.
By Theorem 21 one execution of line 6 is
bounded by 0(n). Hence all successful executions of line 6 together
Therefore the
take time
0(n2).
lines 34-35 and
Because of Lemma 22 this time bound also holds for
we
observe for the
Ki
'I where
n
does not
mean
number of vertices in the
=
sum
K\ of all Kx(V)
0(n2).
the number of vertices for this
original graph.
(2.28)
particular call, but the
Chapter
42
Now
first
K2(V)
consider
we
which contains several contributions. The
the lines 3-5 of the main
clearly given by
is
one
K2(V)
21 the next contribution to
orem
is not
cograph.
a
Transitive Orientation
2.
But this
happens
at most
Gcm{v}
orient(V,...),
for
once
The¬
By
line is true and with line 29
subsequent
because the condition in the
loop.
arises from line 6 if
loop 3-32 will not be executed anymore. In addition, Theorem 21 im¬
plies if "7ci±i{ v} undefined" then in line 6 a chordless path xi,... x4 is
computed. From this we infer that line 8 takes time 0(1). The call of
find_module contributes time 0(|V|) to K2(V), see Lemma 20. Clearly
,
lines 10 and 12
expensive
less
are
0(|V|).
than
lines 13 and 19. In order to compute the cotree
•
duplicate
•
cut all branches
the cotree
At last
Tc
we
deal with
we
Tc,
leading
into subtrees
containing
no
leaves v,v £ C
and
•
This
shrink all unary internal nodes.
0(|C|)
for
be done in time
can
Tc,
the call
occurs
change.
=
0(n).
but
proportional
we
do not attribute the cost of
we
orient(V,...)
In order to
sum
up
(recursive)
over
calls
Since this addition to
cost of
asymptotic
Because of this line 13 is free of
number of
K2{Z)
K2{Z)
0(n) does not
charge in orient(V,...).
orient(Z,...).
but to
at most once, the
Tc, that is in time
proceed in the same way as
the computation of Tcz to
to the size of
It remains line 13. Here
=
K2(V), we show by induction
or(n) of orient is bounded by
on n
(2.29)
or(n)<n-l.
Since the
case n
respectively,
no
< 1 is
in the main
caught
call of orient
that the claim is valid for all
occurs
1 < n' <
n',
routine,
claimed.
as
n.
that the
in lines 11 and
For
When
we
> 2
n
set k
—
we
21,
assume
Yli=i \Z,\
def
we
find for the number of calls
,
,
or{n)
lines
14,20
—
or(n
—
k +
1)
+
or{z\)
+
+
or(zg)
I H
<
n-k +
n
<
—
(zl-l)
k + k
n-1
—
s
+
---
+
(za-l)
The
2.6.
43
Algorithm
which proves the proposition.
Now the
sum
K2 of all
is easy to compute.
cost
K^V)
in the recursive calls
For any of these calls
orient(V')
orient(V')
have V
we
C V
which leads to
K2
=
0(or(n) 0{n)) (2=] 0{{n
-
1) 0{n))
•
0(n2)
<
(2.30)
The cost
K3(V)
of
edges
\V\
2,
>
we
is
generated by
the check of the
the vertices in V
-
V(A).
Since
may state
K3(V)
for any vertex
then V is
orient(V)
V(A), and
call
a
between the module
split
v
=
0(\(V-V(A))xV(A)\)
=
0{2-\(V-V(A))x(V(A)-{v})\)
V(A).
K3{V)
If cost of type
occur
in
a
call
(2.31)
orient(V),
into
orient((V
V{A))
-
W
{ u },...),
u
V(A)
and
oriental,...),...
The
outside
we
from
—
—
On the other hand, these
there.
So
orient(Za,...).
(V
V{A)) x (V(A)
{u}) are
V
as
C
V,
only edges from
orient(V",...),
edges
call of
,
orient^',...),
x
V
are
by
any
examined
cannot add to the cost of
K3
otherwise this call would not have occurred.
as
find that the sets
edges
not examined
V
(V
for all calls of orient which
—
V(A))
implies
x
(V(^4)
—
{u})
are
that the total cost of
edge disjoint
K$ is bounded
by
K3
The cost
K4(V)
for
=
0(\V
call of
a
find_module which is not part of
x
V\)
=
0(n2).
(2.32)
orient(V,...) is the remaining cost of
K2(V) and K3(V). Lemma 20 shows
that
K4(V)
where the set of
pairs P(V)
P{V)
=
is
=
0(\P(V)\),
given by
®(V(A))
-
(J
Ki<s
®{Zi).
(2.33)
44
Chapter
{A(XliX2))v (in
The set
containing
the
Transitive Orientation
2.
following Ay) denotes the implication class
edge (ari, x2) which is chosen by orient(V,...). If we now
the
consider the calls
orient(V,...)
with neither V' C V"
V"
nor
CV',we
scheme,
that V and V" have at most
the sets
®(V)
®(V")
and
orient(V",...)
and
can
have to be
say, based
vertex in
one
on our
recursion
Therefore
common.
edge disjoint which immediately
gives
P(V)
On the other hand
we
n
P{V")
9.
V"
C
have
either V C V"
Without loss of
=
generality,
V ^ V" by Lemma 9.
or
let V C V". Since
Then V is
a
V.
AyCiAv"
subset of
some
V(Av)
explicitly
<8>(V(Av))
(2.33) and P{V'),P(V") are again edge disjoint.
and the set
are
disjoint and
the
K4
K4
Theorem 23 For
putes
an
If
we
x
undirected
an
orientation T
orientation exists at all.
Proof:
is bounded
0(\V
=
=
V\)
graph
(V, F) of G,
This
goal
0,
is
Z% of
Thus all sets
by
0{n2).
=
G
(2.34)
(V,E) algorithm
=
which
achieved
The total cost of the call orient (V) is
substitute the bounds found in
it follows
P(V") in
P{V)
removed from
is
sum
=
submodule
transitive
is
in
0(n2)
5
com¬
if such
an
time.
given by the
(2.28),(2.30), (2.32)
sum
and
(2.34)
we
find the claimed result.
Ki + K2
2.7
+
K3
+
K4
=
Q{n2)
Equivalence
+
of
0(n2)
+
0(n2)
+
0(n2)
Recognition
=
Q(n2)
D
and Test
By applying algorithm 5 to an undirected graph we can reduce the
recognition of a comparability graph to a test for transitivity. In this
Equivalence of Recognition
2.7.
section
present
we
a
construction
and Test
45
by SPINRAD which
proves that the
may in turn be reduced to the
test for
recognition of a
transitivity
both
be
Since
reductions
can
performed in time
comparability graph.
considered
the
be
two
can
equivalent until either one
0(n2)
problems
can
be solved faster.
(V, E) is transitive SPINRAD defines
the undirected graph G'
(V',E'). For each vertex v 6 V we add
three vertices v1, v2 and v3 to V. Additionally we introduce two vertices
s,t G V. For each edge {vt,Vj) G E we have six edges in E', namely
(v],v2), (v2, v3) and (v2, v3) and the opposite of these edges because G'
is an undirected graph. Additionally for i
1,..., n the edges (s, v})
and (vf,t) are in E', also together with their opposite edges.
To test if
directed
a
graph
G
=
=
=
only if G' is a comparability graph.
Supposing that G is transitive we claim that the following orientation
V
{V',F') of G' is transitive.
Now G is transitive if and
=
F'
l,...,n}U{t,v?\i l,...,n}
U{ (vl,v2) | («„«,) G £} U { (v2,v3) | («„«,)
{(v},s)\i
=
=
(2.35)
=
E}
U{(v>,3)|(v„ «,)#}
Suppose T"
v2
vertices
transitive, then there
is not
V for which
(x',y'),(y',z')
a
vertex
must be
one
edges entering
Every edge which
v]
and x' must be
of the vertices
(uj,Vj), (vj, ve) G E.
have (vt,vi) G E and
T" is transitive.
graph
If
in
we assume
choose
Because
therefore
If
(x',z') $.
and
leaving them, y'
can
end in
one
y'
(v},v3)
of those vertices.
G
must be
G
F'
one
Similarly y'
we
must have
that G is transitive
F' by
G
must therefore start
(vj,v2), (v2,v3)
assume
we
x', y', z'
F'. Because only the
(2.35)
we
must
which proves that
This contradiction shows that G' is
(2.35)
we
are
can
that G' is
a
comparability
a
comparability graph, then
we
may arbi¬
which has to be in the transitive orientation. If
edge
edge (v\ ,s)
one
choose the
graph
uf.
must be three vertices
if G is transitive.
trarily
we
G
have
can
of those vertices.
from
F' and
G
F' then it is easy to
forced into F' if
\E\
see
that all the
> 0. Because G' is
show that G must be transitive
a
edges
comparability
by reversing
arguments. It is obvious that this construction takes
0(n2)
the above
time.
46
Chapter
Transitive Orientation
2.
Conclusions
2.8
We have
presented
algorithm
to solve the transitive orientation
prob¬
0{n2) time. Spinrad presented an algorithm with the
in [Spi85] based on his modular decomposition algorithm.
How¬
lem in
bound
ever, he did not
and modules.
an
point
out the connection between
In this
same
implication classes
implication classes
chapter
strongly connected and we have derived a tran¬
sitive orientation algorithm which does not depend on a predetermined
modular decomposition.
and modules
we
have shown that
in fact
are
We presented
an algorithm to reduce the comparability graph
recog¬
problem to a check for transitivity in 0(n2) time. In Section 2.7
we presented the proof of Spinrad which shows that such a reduction
is also possible in the opposite direction. Since both reductions can be
performed in 0(n2), comparability graph recognition and the test for
transitivity can be considered equivalent until either problem can be
nition
0(n2).
solved faster than
Our version of orient may be extended in such
modular
decomposition,
a
G-decomposition
or
G-Decomposition may be generated in 0(n2)
improving on Golumbic's 0(n m) bound.
We have shown that it is
decomposition
in order to
not
both
compute
that
a
generated.
graphs,
The
time for transitive
necessary to
a
manner
a
are
compute the modular
transitive orientation in
0(n2)
time.
If
we
want to
resulting
this problem
recognize
orientation for
in time
can
a
comparability graph
we
have to test the
transitivity. As outlined in the previous section
be reduced to the
recognition of comparability graphs
0(n2).
It is quite surprising that there has been little work to improve the
running time of the test for transitivity. In Chapter 4 we investigate
some possibilities for the test for transitivity. In [Spi85] Spinrad sug¬
gests to test an graph G
(V, E) for transitivity by computing its
transitive closure (V, E*) and comparing it to the original graph. If
both graphs are identical, then the graph is transitive. The computa¬
=
tion of the transitive closure is worst
of
a
boolean matrix
each other in time
case
multiplication (the
equivalent to the computation
problems can be reduced to
two
0{n2)).
Boolean matrix multiplication has several applications, the compu-
Conclusions
2.8.
tation of the transitive closure is
47
probably the most widely known. For
problem in its general form in Chapter 3 where
we present different approaches.
For some of the solutions we present
mathematical analyses, for the other algorithms we present our empiri¬
cal results. This also permits to compare the algorithms to each other
this
reason we
which
we
treat the
do in Section 3.5.
Chapter
3
Boolean Matrix
Multiplication
In this
chapter
matrices.
we
consider the
While it is
problem
easily possible
general multiplication of an n x
analyzed in this simplified form
obscure the complexity claims.
m
of
multiplying
two nxn boolean
problem
for the
k matrix it is
usually
to formulate the
with
an
m
x
because the additional
m
and k
only
approaches to this problem. First we discuss
algorithm which appeared in [ADKF70].
In our experiments we use this algorithm as a baseline for comparison.
Then we investigate several algorithms based on the combination of
two well known primitive algorithms. Surprisingly one of the simplest
algorithms, a self organizing step by step combination, provides the
most convincing results.
We also present an approach which solves
the problem recursively and can be combined with the Four Russian
algorithm.
We present different
our
version of the Four Russian
Our algorithms do not improve the worst
case running time for
Multiplication, but they perform well empirically. For
some algorithms we can provide an average case analysis, but the em¬
pirical analyses probably provide the most interesting results of this
chapter.
Boolean Matrix
48
49
Introduction
3.1.
Introduction
3.1
Let A
=
ai],bij
{at]), B
{0,1}.
(bl3)
=
be
boolean matrices, that is
n x n
We consider the
multiplication C
=
A
•
we
require
B which is
given by
n
ctJ
=
\J
(3.1)
atkAbk}.
k=i
Because
multiplication
important operation in
engineering,
intensively studied its
complexity. Strassen showed in [Str69] that the naive algorithm with
running time 0(n3) is not best possible. His bilinear algorithm has
a worst case time complexity of 0(n281).
Following the work of Pan
[Pan78] several algorithms with complexity 0(n2+a) were presented and
The smallest a to date is due to COP¬
a was gradually improved.
PERSMITH and Winograd [CW90].
Using a trilinear algorithm they
reached a worst case running time of 0(n23S).
general
matrix
However,
is
an
computer scientists have
science and
a algorithms of this kind have huge constants
implement. Even if we restrict the problem to its
simplest form, namely boolean matrix multiplication* the situation does
and
not
ger
are
for small
difficult to
improve. The Boolean Matrix Multiplication results from the inte¬
product of A and B by understanding all nonzero entries of C as
1.
In spite of this the restricted problem allows to come up with new
strategies. There is for example the Four Russian algorithm [ADKF70]
which claims
worst
a
lookup scheme.
complexity
case
For smaller
n
this is
a
of
0(n3/logn) using
useful
algorithm
which
a
table-
we
briefly
review in Section 3.2.
For the second
running
time of
variable. We
in Section 3.3 we analyze the average case
algorithm by considering the input as a random
approach
our
mainly
use
the standard model for random boolean
ma¬
trices. In this model the entries
atJ and bl3 of A and B are independent
random variables taking on the value 1 with probability p, 0 < p < 1,
and the value 0 with
properties
of
our
probability 1 —p. When we are interested in specific
algorithms we sometimes modify this model to collect
additional information.
"The methods for
case
general matrix multiplication still represent the fastest
solutions for boolean matrix multiplication.
worst
Chapter
50
Boolean Matrix
3.
Multiplication
probability model we present two simple algorithms which
good running times in different situations. We show how to com¬
bine these techniques to yield a new algorithm with an average case
running time of 0(n2 Inn).
For this
have
recursively breaks up
a large number of
ones which are found in many different steps.
By recursively breaking
up the problem we can avoid these multiple computations. However,
when the problem size shrinks the overhead of splitting the problem
In Section 3.4
the
problem.
present
we
This
approach
approach
an
further does not pay of anymore.
algorithm
to solve
In Section 3.5
show
comparison
algorithms
for
practical
algorithm
we
was
can
computation model in which it
many bit operations in
presented
common
one
considered
a
it is based
bit at
a
time
limited RAM
is
a
in a processor register in or¬
multiplication. Therefore the
[logn\ bits* with a single instruction.
n
boolean matrix
processor must be able to process
advantage
of size
[ADKF70],
than
possible to execute several, but not in¬
single instruction. This is an adequate
microprocessors. Arlazarov et al. assumed,
an n x n
In order to take
in
more
process
that it is necessary to store the number
n/[logn] stripes
certain size.
algorithm
Arlazarov et al.
finitely
der to compute
the Four Russian
purposes.
modern processor.
model for most
a
use
provide empirical analyzes of these algorithms. We
provide some simple means to evaluate the
the observation that
a
smaller than
charts and
The Four Russian
on
We therefore
The Four Russian
3.2
in
problems
we
which
could be useful if there is
n
x
split into
stripe k by B^ and
of this fact the matrix B is
[logn].
We denote
define
b^
This
implies
(k)
number bt
,
that
=
we
defined
bl}
can
with
store
j
=
row
(k- Tlogn])
i of
+ e.
stripe B^
in
a
single integer
as
flog n\
6(*)def
£
2/.6(fc)_
(32)
e=o
t
Throughout this chapter log always denotes the logarithm with base
logarithm.
denotes the natural
2 and In
The Four Russian
3.2.
This
if
we
preprocessing
can
generate all stripes
51
algorithm
be done in
at
once
compute the stripes successively
0(n2) using 0(n2/ [log n])
actually
which is
only need 0(ri)
we
space
If
not necessary.
we
space.
multiplication A B^ completely determines stripe C^ of the
row i of stripe C^ we have to compute
The
result. To compute
cw
bw
y
=
je{e\a,e
where
=
1}
the bitwise or of numbers operation which is an atomic in¬
todays microprocessors. This allows to perform the [logn]
operations in a single instruction. We can therefore compute
we use
struction in
one-bit
each
or
row
of the
of
C,
C(k\
process in
The
in time
0(n)
and it takes
In order to compute ctJ
we
0(n2)
compute each
time to
must decode c,
,
reversing the
(3.2).
time of the Four Russian
algorithm is composed of
encoding and decoding steps, as well as further preand postprocessing, can be performed in time 0(n2). At last we account
for the computation of the stripes C^. In the most primitive version
we have to investigate n positions a,i,...,am in order to determine
running
several parts. The
which sets have to be united to compute
constant
time,
Since there
therefore
we can
are n rows we
and since there
are
need
compute every
0(n2)
n/[logn\ stripes
C
'.
Every
row
of
C^
a row
union takes
in
0(n)
time.
time to compute each stripe
we can
C^
compute C in time
0(n3/riognj).
We
can
improve this algorithm by storing the
list. These lists allow
us
to
compute
a
stripe
ones
in time
in a,i,..., a,„ in
0(size
of the
a
list)
Using the standard input model we expect n p entries in each list.
This improves the number of unions we have to perform. The improved
algorithm has an expected running time of
•
0(n3-p/[log n"|)
(variant A).
store
time-memory trade-off
length 0(n2 p) in order to
This is
lists of total
a
in
some
way,
reach this
we
have to
running
time.
Alternatively we need space 0(n2/ [log n]) in order to store all the tables
B^ simultaneously. With all tables present we can compute the whole
multiplication during a single scan of matrix A which also results in an
52
Chapter
Boolean Matrix
3.
Multiplication
expected running time 0(n3 -p/flogn]) (variant B). In Section 3.5.4
we analyze the two variants empirically, in fact their running times are
pretty similar.
Note: A actual
probably
implementation
not limit itself to
a
of the Four Russian
[logn] improvement,
algorithm
it will
use
will
the full
width of the processor word to compute unions.
This improves the
running time for small n, but of course it does not scale. In fact the
complexity of the Four Russian algorithm is 0(n3) in this case. The
0(n3/[logn~|) running time claim can only be sustained if we assume
that the size of the processor word scales with the problem size. That
is we use an optimal implementation of our algorithm only for large
matrices and use a slower one for small problems. By this we can find
a slower rate of growth than if we apply the optimal strategy for the
whole range of problems.
The
today are much smaller than the 64
using current microprocessor technology.
of
the
the
Considering
microprocessor industry it is very likely
progress
that the bus size will forever be larger than log(n) if n is the size of
bit
our
problems
we can
we
can
process at
matrices. For this
algorithm
(where
will
as an
a
handle
time
reason we
0(n3/k) algorithm
k denotes the size of
use
it
as
experiments
a
baseline in
our
Combination
To find
practical
as
a
0(n3/ [log n]) algorithm
register). Nevertheless we
comparison of algorithms since in our
the constant factors
3.3
problem
a
propose to consider the Four Russian
instead of
a
processor
proved
to be very small.
Algorithms
solutions it is often useful to consider the
random variable.
In order to
input
of
a
get "random" matrices A
mainly use the standard model and assume that the entries
bl3 are independent random variables taking on the value 1 with
probability p, 0 < p < 1, and the value 0 with probability 1
p.
and B
we
atJ and
-
In the following sections we show how to combine two simple strate¬
gies to yield several algorithms with expected running time 0(n2 -logn)
regardless of the value of p. These algorithms are simple to implement
and useful in
bution.
practice if the input
matrices have
an
appropriate distri¬
Algorithms
Combination
3.3.
A Review of
3.3.1
53
Simple Algorithms
simple algorithms for boolean matrix multiplication.
an analysis of their expected running time which
will be used in later sections. Then we review a simple combination of
these algorithms as introduced by SCHNORR in [Sch92].
First
we
review two
We will also present
Look-up
The matrix
of
multiplication in (3.1)
may be considered
n2 matrix products of type (1, n)
result
multiply the
we
ctJ
(a,i
=
i-th
A
row
bi})
V
x
(al2
A
composition
position i, j in the
the j-th. column of B, that is
(n, 1).
of A with
b2])
the
V
•
as
For each
•
•
V
(a,„
(3.3)
bn]).
A
[0073] have shown that (3.3) can. be evaluated in
0{l/p). Because we consider boolean matrix multiplica¬
O'Neil and O'Neil
expected
tion
time
stop computing this
we can
vector
product
have found
once we
an
index k with
a-ik A
which
implies cn
1
=
bk]
the result.
as
(3.4) has probability p2
occurrence of (3.4) has a geometric
the event
number of evaluated
products
1/p2-
be reduced to
by
a
This value
can
the whole
0(n2),
With respect to
and the
waiting
can
input model
our
time for the first
distribution. Therefore the average
can
be
(3.3)
computed in
O'Neil and O'Neil
see
algorithm
(3.4)
1
in order to determine
list oriented storage of ^4* which
step in time
=
be executed in
[0073].
expected
time
a
is less than
preprocessing
For this
reason
0{n2/p).
Put-on
Santoro
C
as a
[San81]
describes another
superposition of
To compute this
we
n
matrix
simple method. Consider the result
multiplications of type (n, 1) x (1, n).
determine the set Ok of all pairs
a-ik A
tfor
every
i
in
(3.4)
we
use
a
list
bk3
=
(i, j)
with
1
L(i) containing
all
m
with alm
=
1
Chapter
54
for
a
fixed
C. Of
1 < k <
fc,
Then we unite the sets Ok by putting them
Ok is given by the Cartesian product
n.
every set
course
Boolean Matrix Multiplication
3.
Ok
=
Afc
on
Afc
x
with
Afc
A
{i|l<i<nAa,fc
=
l}
=
and
representation of Afc and Afc,
Afc
=
1 < k < n,
{j |
as
1 <
j
<
n
linear lists
A
bkj
can
=
1
}•
be pre-
computed in time 0(n2). In our input model Afc and Afc obviously have
expected size np. Because of this and the list oriented storage of Afc (Afc)
compute
we can
a
set
Ok in
average time
0(n2p2)
(3.6)
algorithm can be executed in expected time 0(n3p2+n2).
algorithm corresponds to the Santoro algorithm described in
[San81] for multiplying sparse matrices, its running time is good for
and the whole
This
small p.
The Schnorr
In
[Sch92]
algorithm
Schnorr introduced
Look-up based
a
simple combination of Put-on and
the observation that the
running time of the O'Neil
algorithm decreases for growing p while the running time of the SAN¬
n1//3 both algorithms have an aver¬
TORO algorithm increases. For p
of
which
time
is therefore the maximal expected
0(n7/3)
age running
of
combined
time
a
simple
running
algorithm which selects the better
for
algorithm
every p.
on
=
Schnorr treats each
n
Inn
ones
row
have been put
separately and performs Put-on steps until
(or reput)
on one row.
He then shows that
row is less than 1.
expected
remaining
the
result
for
therefore
be determined in
can
Using Look-up
0-positions
time
and
the
whole
runs in expected time
expected
0(n)
algorithm as a
the
number of
in that
zeros
0{n2 ln(n)).
•
In the
following
multiplication
SCHNORR
improve
section
at once.
algorithm
the average
we
will
use a
In Section 3.3.3
we
show how to
improve the
input distributions, although we
analysis for every input distribution.
for many
case
similar strategy for the whole
cannot
3.3.
Combination
55
Algorithms
Combination of the
3.3.2
simple algorithms
Look-up and Put-on we observe opposing running time behaviors.
expected running time of Look-up is small for p close to 1 and
increases with shrinking p. On the other hand, Put-on is fast for small
p and its average running time increases with growing p.
For
The
adapted combination of Look-up and
algorithm mentioned in the previous section.
In fact our algorithm runs in average running time 0(n2 Inn) regardless
of the value of p. For this reason we split both of our input matrices in
two parts. For a fixed h, 1 < h < n, matrix A is split in an n x h matrix
A( (left part) and an n x (n
h) matrix Ar (right part). Similarly B
is split into an ft x n matrix Bt (top part) and an (n
h) x n part Bb
(bottom part). Obviously, C is now given by
We want to
provide
a
more
Put-on than the ScHNORR
—
—
C
where C"
=
Ae
Bt and C"
=
C'V C"
=
Bb$.
Ar
This strategy is similar to the
to show
by Schnorr in [Sch92]
0(n2logn). In the following we
used
one
time of
average running
investigate some variants of this concept.
C", more exactly the union of the sets
an
We will
use
Put-on to compute
Oi,...,Ofc
and then
Look-up
for C". Because
C"
can
c't]
=
1 determines the result
for which d
have to compute
positions cft'
be computed in expected
=
0.
Using
Put-on
we
as
only
above
time
0(n2p2 h).
(3.7)
The second part of the
running time is bounded by the product of two
0
independent random variables, the number of pairs (i,j) with c^and the expected time to evaluate
in
C".
the
ones of each
Assuming
c['j
Put-on step are independent of each other the expected number of zeros
remaining in C is given by
=
n2-(l-p2)h.
Using 0(l/p)
the
expected
as an
time
upper bound for the
spent
to
computation of a c?-
(3.8)
as
in
(3.5)
compute C" is
0(j-(l-p2)h).
§ where V denotes the element-wise
logical
or
of the two matrices
(3.9)
56
Chapter
Together
0(n2)
with
T(h)
as
the average
choose
for various
0{n2
=
precomputations
n2-p2-h+
+
time of the whole
running
we
Multiplication
observe
-(l- p2)h)
—
P
suitable value for h. If
a
Boolean Matrix
3.
(3.10)
algorithm. Next
we
have to
set
we
then
h
is sufficient for
therefore
our
The nontrivial
+
case
hp d=
min
{
n,
h°{p) }
-4^
For p <
purpose.
only Put-on
0(n2
=
and
=
0(n2
+
>
n
(3.10)
will be executed and
n2-p2-h)
(3.12)
n3)
-
n
9,
we
have h
=
n,
reduces to
=
0{n2).
(3.13)
is
4=<p<iNow
(3.7)
is bounded
n2
because
ln(l
-p2
h
x)
+
=
< x
by
n2
-p2 ——^—^r
In(l-P2)
and for
(3.9)
we
<
-n2 lnp
<
n2
In
n
(314)
get
!L.(i_p2)n^i) =IL.exp(lnp)=n2
p
which
(3.15)
p
implies
0{n2+n2-p2
The choice of
analyze
h°(x)
and has
a
in
-h+
(3.11)
—
P
-
(l-p2)h)
=
(3.16)
results in
an
good running time, but
algorithm which is simple to
it is not the only reasonable
choice. We will discuss three different choices of
»'"»'where W(x)
=
0{n2\nn).
h(x). For'
_w(-\n(l-x2)}
y is the Lambert W
(3'17)
ln(l-^)
function, the solution oiyey
=
x
Combination
3.3.
Algorithms
expressions (3.7) and (3.9)
anced algorithm. For
are
57
approximately
the
inr~ln(1r*2h
ft2«"
expected running time, but
complicated analysis. If we choose
"aw
=
a
bal¬
(3-18)
mT^T
find the minimal
we
same", yielding
we
have
a
slightly
i^y
more
<3-19>
an average running time of 0(n2lnn). After h3(p)
expected number of remaining zeros is 1 and Look-up is
trivial. This choice corresponds to the approach of ScHNORR in [Sch92],
but it has theoretical and practical disadvantages, especially if the input
does not correspond to the standard input model.
then
we
also find
Put-on steps the
For constant p
the constant will
we
get
an
depend
on
n2-p2- h3(p)
for all
h3{p)
n).
plied only
On the
to
+
running
we
(l-p2)h3W
—
P
one
hand
large samples,
alternatives to the standard
=
0(n2), though
h3(p) we get
time of
choose
n(n2lnn)
h3(p)
Put-on steps
(i.e.
probabilistic arguments should be
on
the other hand
input model. For
we
some
if
ap¬
want to consider
models the assump¬
limited number of Put-on steps is
0(1) remaining
realistic. The self organizing strategy in the following section adapts
tion of
not
case
p. However if
which allow the execution of
cases
<
average
zeros
to this situation
Starting
problem
more
after
a
gracefully.
quickly reduces the remaining complexity of
use Look-up to complete the problem.
The combined strategy is more robust than Put-on and Look-up alone.
For a real implementation the best choice of h should be determined by
empirical tests, since the best choice depends on the real distribution of
the input and the relative cost of the instructions in the target computer
the
with Put-on
while it is better to
system.
II if A1
(p)
<n
Chapter
58
A Robust
3.3.3
In the above
Boolean Matrix
3.
Multiplication
Algorithm
function of p and
general p is unknown.
difficulty while
retaining the same average case behavior. Our strategy adapts better
to the input conditions than the approach used by Schnorr in [Sch92].
We achieve this by applying a more sophisticated condition for switching
between algorithms. Our algorithm preserves the 0(n2 Inn) average
case bound, but for many inputs it achieves better running times than
the SCHNORR-algorithm.
At first
chose has
we
In this section
we
we
present
a,
an
algorithm
observe that the
section may also be
for
applied
n.
In
which avoids this
algorithmic concept from the previous
single rows. That is the computation of
the sets
Rt
=
{ j 11
< j <
n
A
c,^
=
1}
for
i
=
1,...,
n.
Let
T1
=
then
{j|l< j<nAat]
Rz
is
=
1}
At
(J
A/.
Ta and A^
=
ning
j
< n A
bt]
=
1}
(3.20)
then
lnp
=
-
one
set
Rt
p2)
using Look-up for the remaining zeros. The expected
might be analyzed as in the previous section.
and
However
computation
we
of
do not know p in
Rt
in
algorithm
T,
=
can
(3-2D
TZT^hr,
ln(l
time
1 <
represented by linear lists,
0(n \ lnp|) by a union of
K
Ae
{j |
are
be determined in time
lists
=
given by
ii,
If the sets
and
general, therefore
we
reorganize
run¬
the
6. For
{*1,*2,*3,...}
the union
Rt
is
=
Atl UA,2UA4U...
computed step by step, but
the
add
operation
A(
to
Rt
(3.22)
Combination
3.3.
Algorithms
special
way.
thebe
thebe
Let
a
Let
is sometimes executed in
59
numbnumber of
Z
Zj
putting
on
A*, that
in the current
zeros
row
of the result before
is
ZJ^|{l,...,n}-(A/lU-UVJ|
and let X
be the number of
X,
Algorithm
~~(lj
(2)
(3)
(4)
(5)
(6)
(7)
(8)
(9)
(10)
(11)
(12)
(13)
(14)
(15)
6
Computation
to
ones
=
put
on
in the current
step, that is
\\t,\.
of Rt
Z<-{l,...,n};
forall t £
Tt do
if|A«|<|Z|
then
Z^Z-Af,
else
forall z£ Z do
if btz
=
1
then
delete
from
z
Z;
fi
od
fi
od
£,<-{!,...,n}-Z;
If
Z}=n- \Atl
then
we
replace A<
in
U
•
(3.22) by
•
•
U
A/,.,|
<
\Aei|
=
X}
the set
A«jn({l,..,n}-(A<1U-..UA{jJ)
which has the
Look-up-like
time of this
same
effect but
manner.
algorithm
Now
we
has the
can
be
computed
0(Z ) in a
expected running
preceding solution.
in time
have to show that the
same
bound
as our
Chapter
60
In the standard
variables with
a
pr[z,
Boolean Matrix
3.
Z3
input model,
X}
and
=
*]
=
Q
((l
•
-
random
independent
are
binomial distribution. Therefore
Multiplication
we
observe
py-y (!-(!- py-1)*-*
(3.23)
and
Vx[XJ=s}=(^j-ps.(l-p)n-s.
We
are
(3.24)
interested in
L^min^.Z,)
since the
running
operation (3.22)
time of
is
proportional
For any two random variables X, Z and any
< a X + (1
a) Z which implies
min(X, Z)
this
E[L3]
we
[0,1]
we
have
using
a
< a
^[X
=
<
E[X]
Z}]
+
we
(1
-
a) E[Z}.
find for the
expectation of L}
E[XJ}-Vr[X]<Z]}+E[Z]}--Pr[XJ>ZJ}
<
n-p-
=
Now
£
L}.
—
E[min(X, Z)\
Applying
a
to
Pr[X,
<
Z,]
able to bound the
are
+
(1
n
p)1'1 Pr[X,
-
expected running
>
time of
Z}\. (3.25)
algorithm
6.
Of course, for
T,
this
mean
value is
=
{£i,...,iu},
u<n
given by
n
E[L1}
We claim that this
sum
+
+
E[LU]
<£>[£,]•
satisfies
n
J]E[L,]<0(n-|lnp|)
The
proof
Y,E[L,]
j=i
of
<
(3.26)
is based
on
(3.25)
which leads to
£> -p Pr^ <Z3] + J2n- ^-P)3'1 Pr^
j=i
(3.26)
3=1
^
ZJ"
(3.27)
3.3.
Combination
In the next step
61
Algorithms
CHEBYSHEV-inequality
the
we use
random variable Y with
mean
E[Y],
value
which states for
variance
Var[Y]
a
and any
t >0
Pr[\Y
E[Y]\
-
t]
>
<
Var[Y]
(3.28)
'
t2
In order to bound
Pv{X3
we
<
Z3\
set
Y
Because
X3
and
Z3
E[Y]
are
=
=
X,-Zy
independent
E[X,]
E[Z3]
-
we
=
n
get
p
-
n
•
(1
-
p)'"1
(3.29)
and
Var[F]
Let
=
Var[^]
=
n
-p-
Var[Z,]
(1 -p) +n (1-py-1 (1
(3.30)
+
•
-
(1 -p)3'1).
now
j
then
we
For j
>
Pr[X
>
min(l
ln(p/2)
ln(l-p)
+
def
x
,n)
=
./
(3.31)
J
have
f
<
have
we
Z
]
=
E[Y]
Pr[y
<
and hence
> 0
0]
<
Pr[|Y
-
E[Y}\
>
E[Y}]
(3-w)
<
Var[y]
E[Y]<
(3.32)
(1-p)>-1-(1-Q.-p)>-1))
(n(p_(l_p)J-l))2
(p-(1-p)
+
v
v
>!
<
n
p
'
Chapter
62
In the
same
way
we
j
Multiplication
Boolean Matrix
3.
find that
<
min(l
+
\>n)^f
ln(2p)
(3.33)
Lln(l-P)j'
implies
(1-py-1
>2P
and further
n
•
(p (1
•
-
p)
(1
+
-
p)3~l •(!-(!- PV'1))
(nai-p^-p))
d-p)J-
<
Now
we
(3.34)
n-(l -p)^1
infer
/
£>-p.Pr[.Y,
3
=
<Z,]
=
1
Y.n-p-Pr^KZ,]
1
=
3
<1
^ n-p-PrlX^Zj]
+
<
-£
J=J.+i
—
and
j'
+ 6
n
p
<
n
<
^n-U-pr^PrlX,
p
n
(3.34) implies
/'
^VU-py^.PrlX^Z,]
]=i
3
=
>
Z,]
1
(l-P)J-l
V
+
z—*
n-O-pr^Pr^Z,]
-*
3=3"+ 1
.1
<„.(l_p)J
(3 33)
<
<
6-j
+2-n.
2
Replacing
this in
63
Algorithms
Combination
3.3.
(3.27)
get
we
n
5^E[LJ]<n-p-j' + 6-j" + 8-n
(3.26).
which shows
Theorem 24 For the standard
cation
can
be
computed
Proof: Directly
as
in
(3.13)
(3.35)
input model
a
boolean matrix
0(n2 Inn)
in average time
•
previous discussion, using the
from the
multipli¬
using algorithm
same
6.
argument
for small p.
might be applied to the original com¬
bination of Put-on and Look-up, however, considering the whole matrix
instead of a single row the preceding analysis cannot be extended in a
straightforward manner. To analyze the number of zeros in the matrix
Note that the
after
a
certain number of Put-on
the number of
binomially
complex.
zeros
in
a
now we
but there
would need
a
distribution for
product of two
analysis more
are
also
stances. For this
appropriate
for
advantage
(practical
reason we
some
definition
and
we
of
practical inputs adequately
for instance
in all circum¬
propose another model which may be
more
applications.
an
index
alk
Similar to
input
our
mathematical treatment,
observe
if there is
graph theoretical
between its
simple
a
theoretical) disadvantages,
Cij
only
probability model for
have used the standard
this model does not describe
if and
we
This number is the
distributed random variables which makes the
matrices. This has the
By
steps
single step.
Another Model
3.3.4
Until
method
same
endpoints i,j
=
k,l
1
i
—
< k
A
<n, such that
bkj
notation
if it satisfies
—
we
(3.36)
I.
call
(3.36).
a
sequence
Further
we
i,k,j
a
path
say that two
paths are different if their endpoints are not the same. Finally
(i, j) is covered by a path P if i and j are the endpoints of P.
a
pair
64
Chapter
Boolean Matrix
3.
Multiplication
briefly review our results from Section 3.3.2. The central
analysis was: How many paths have been considered after
k Put-on steps and how many pairs (i, j) are not endpoints of any of
these paths? Similar to the approach taken by Schnorr in [Sch92] our
algorithmic concept can be reduced to:
Let's
point of
now
our
1. Consider
2.
a
Check the
certain number of
of uncovered
a
uncovered
remaining
algorithm
pairs
For this
we
paths
and mark all the covered
pairs with Look-up
pairs.
.
suggest the following model. Let C(t) be the
after
considering
t
paths
then
\C(t)\
is described
set
by
discrete time death process with time t.
In order to
simplify the analysis
we assume
that the
paths
random variables. This is
are
inde¬
for instance
a pessimistic assumption,
ignores the fact that all paths in a Put-on step are different and there¬
fore not independent, but negatively correlated. Therefore \C(t)\ will
actually be less during the algorithm than in our analysis.
pendent
it
At last
we assume
pt]. Clearly the ptJ 's
that each
must
sum
path covers a pair (i, j) with probability
to unity, that is
H
We
can
consider n2
describe these
urns
Ptj
=
L
assumptions by the following urn model. We
to the pairs (i, j), 1 < i,j < n. For each
corresponding
algorithm we assign a ball to a randomly chosen urn. Now we
problem since we are concerned with the number of
urns containing at least one ball (occupied urns) after a certain number
of balls have been assigned. Therefore with \C(t)\ we are interested in
path
in
have
an
our
occupancy
the distribution of the number of
Problems of this kind
lems
or
coupon collector
107-121 and
155-162]
I
well-known
problems. They
and
ptJ
we
are
empty
[KSC78,
—
—,
pages
are
as
are
sequential occupancy prob¬
the subject of [JK77, pages
119-152].
forl<i,j<n,
At first
we assume
(3.37)
general case later. Let Ptii be the probability that
uncovered after checking t paths, then we have
will consider the
pairs
urns.
Po,„*
=
1
65
Algorithms
Combination
3.3.
and
Pm
(i
=
-
-t)
nz
-p«-i^
^ir -p<-m+i
+
(3-38)
nz
where
means
see
(3.38)
that
path reduces the
Using induction on n it is
that the t-th
probability
the transition
of uncovered pairs from I to I
—
1.
number
easy to
has the solution**
n-e-i
{* «} IK*-*)
fc=0
Pt,e
Further the
(3.39)
=
generating function
ft(z)^Xy-p«,<
t=0
satisfies the recursion
9t(z)
which
implies
gt-i{z)
1
value of
E[|C(t
1)|](1
=
-
z
—
+—^- -g't-i(z)
expected
for the
E[\C(t)\)
=
-
\C(t)\ (using E[|C(t)|]
±)
=
n2(l
-
=
g't(l))
±Y.
71
lb
For t
=
n2 In n this shows that
E[|C(t)|]
and for that
reason
=
n2(l
-
^)"2ln" n2(J)lnn
«
the second step of
our
algorithm
0(n)
=
can
be executed in
time**
0(n2).
**
where
{£}
denotes the
Stirling
numbers of the second
kind
[GKP89]
^Note
that
Look-up
takes at most
0(n)
time for
a
single pair.
as
defined in
66
Chapter
Using
Put-on it takes
which therefore has
0(1)
Boolean Matrix
3.
time to find
running
one
of the
Multiplication
paths
in the first step
time
0(n2 log n)
which
In
clearly dominates
the total cost of the
[KSC78], Kolchin,
this result for
algorithm.
Sevastyanov and Chistyakow
arbitrary values
generalize
of
Pushow that the
They
noted
by /Lio(r))
is
expected
given by
number of
fio(r)
Var-Mr)]
r
Put-on steps
(de¬
given by
is
n
=
after
f(l-p,;)r.
E[/io(r)]=
The variance of
zeros
n
I>"^)r- £
J2
+
0-
-
p*i
-
(1
-
PlJY(I
-
pke)T
p«)'•
(«,j)*(M)
Prom this
we can
using the second
we
derive
moment method
[ASE92]
defined in
as
and
obviously
have
Pr[/i0(r)
These estimates
gorithm
other
3.4
in the
one
>
0]
<
E[0o(r)].
rough impression of the behavior of our al¬
generalized case. If one probability tends to 0 then the
provide
a
tends to 1.
A Recursive Solution
In this section
multiplication.
we
describe
At first
a
we
recursive
approach
to solve boolean matrix
introduce the three
layer representation of
A Recursive Solution
3.4.
multiplication
boolean matrix
We then present the basic
67
which is used
by
the recursive
in Section 3.4.2.
strategy
approach.
As with other
algorithms (e.g. Quicksort) it is not efficient to conduct the
recursion up to the end. At some point it is faster to stop the recursion
and to apply a simpler method to complete the task. For boolean matrix
multiplication it seems natural to use a variant of the Four Russian
algorithm. We briefly discuss this in Section 3.4.4.
recursive
The Three
3.4.1
Layer Representation
The three layer representation Gab
(Va-b, Ea-b) of a boolean
A B is a graph with
multiplication C
=
matrix
—
Vab
=
(3.40)
{ui,... ,un,mi,... ,mn,di,... ,dn}
V
'
'
V
<
v
v
v
d^U
*?M
d=fD
and
EAB
=
{{d%,mj)\atj
=
l}\j{ (m„ u3) | btJ
=
1}.
(3.41)
The subsets
layer
of
there is
U,
M and D of V
a
b-
called the up, middle and down
In this
The Basic
3.4.2
are
representation we observe ctJ
path of length 2 from d, to u3 in Gab-
Ga
=
1 if and
only
if
Strategy
Using the three layer representation it is easy to describe Put-on and
Look-up. For the Put-on algorithm from Section 3.3.1 we can consider
the result matrix C as the superposition of n matrix multiplication of
type (n x 1) (1 x n). Using the three layer representation we can describe
the i—th multiplication by the ones put on the result. These are given
by adj~(rat) x adj+(mt). The ones in this set correspond exactly to
the paths through vertex mt in the middle layer. In Figure 3.1 we
rearranged the rows of A and C such that all the vertices in adj~(mi)
•
occur
at the
adj+(mi)
upper left
top and the columns of B and C such that the
occur
to the left.
All the
ones
in the result
occur
ones
in
in the
part of C. The left part of Figure 3.1 illustrates the result
matrix after the first step, the
right shows the situation in the three
layer representation. All the two-paths through the first vertex of the
68
Chapter
0
Figure
3.
Boolean Matrix Multiplication
0
first step of a recursive boolean matrix multiplication.
after the first step on the left; the three layer rep¬
resentation on the right. Edges occur between the vertex in the middle
layer and all the vertices in the left part of the top and bottom layer.
3.1:
The
The result matrix C
1
Ri
R2
Figure
3.2:
the
vertical
left,
Two
possibilities to split the problem, horizontal split
split on the right hand side.
on
69
A Recursive Solution
3.4.
layer run through the gray part of the right picture. As shown
Figure 3.2 we now have two possibilities to split the remainder of the
result recursively. We can split the remaining zeros in the result either
horizontally or vertically. These strategies are symmetric to each other,
but they introduce an asymmetry into the algorithm. The parts of the
matrix to be computed by subsequent calls quickly become narrow in
influence
one dimension. Because it is not clear how such asymmetries
the running time we implemented a more symmetric algorithm. This
variant alternates between the horizontal and the vertical split strategy
middle
in
performance
after each step. The
of this
original strategy, it seems that
lot of time to actually split the matrix
than the
a
algorithm proved to be
the symmetric strategy
this
shown in
takes
For
up to the finest level.
results for the vertical
only present our
Figure 3.2 on the right.
reason we
worse
split strategy
as
Figure 3.3: Three layer representations of the reduced multiplications
using the vertical split strateqy. We remove the edges in the gray part
of the right picture of Figure 3.1. To compute R\ we only consider the
edges in the gray parts on the left, for i?2 those on the right.
As in Put-on
through
we
set all the
positions ctJ
the first vertex mi in the middle
to 1
for which there is
layer.
All these
a
path
positions
can
split the
remaining zeros of C into two parts according to the left matrix in Figure
We can now compute the two parts R\ and i?2 independently.
3.2.
To represent these matrix multiplications we again use the three layer
be omitted in further
computation because they
will stay 1. We
representation. For both matrix multiplications we remove some of the
edges from the original structure as shown in Figure 3.3.
vertices and
To
compute Ri
we
use
the three
layer representation (Di,Mi,Ui)
Chapter
70
ifL/
Multiplication
bmmrec(D, M, U)
7
Algorithm
Boolean Matrix
3.
0VM
=
=
0V£>
0 then
=
return;
fl;
select
m
forall
Qj
£ M and remove
(i,j)
6
adj~(m)
x
it;
adj+(m)
do
1?
=
od;
remove
Mi
t/1
=
=
edges
the
from
remove
the
edges
edges
restore the
=
to
adj+(m)
and
adj- (m);
-
between M and
(removing ml G M
bmmrec(i^, Mx,^);
D2
m
{m};
C/-adj+(m);
M
D
remove
-
adj+(m);
adj
between M and
+
(m')
=
0);
adj+(m);
adj_(m);
the
edges
(removing
remove
for which
the
m!
edges
(removing m'
between M and
G M for which
adj~(m);
adj_(m')
0);
adj+(m);
adj+(m') 0);
between M and U
M for which
=
—
=
bmmrec(Z>2, Mi,adj+(m));
restore the structures of
D, M,
U and the
edges
in
between;
for which
find
we
D1
Of
71
A Recursive Solution
3.4.
we
course
Mi= M -{mi}
D
=
also have to
rithm 7
recursively.
remove
Using
removed from U and M.
and
all the
they
D
=
-
M2
=
M
-
sets
are
The
running
given
time
in
adj+(mi).
algorithm
analysis of
to the vertices
we can
call
the three
using
defined
{mi}
determine the second recursion which
version of this is
-
edges leading
compute the matrix R2
We
adj~(mi)
U
=
the reduced structure
representation {D2,M2,U2). These
D2
U1
algo¬
layer
as
U2
and
=
adj+(rai),
computes R2. A pseudocode
7.
this
algorithm turned
difficult because the recursive calls exhibit
an
input
out to be
quite
structure which
original call. The upper layer quickly becomes
layer only decreases slowly and for the lower layer
there are calls with large and small sets. Therefore we cannot use a
standard recursive equation to describe the running time.
is different from the
the middle
smaller,
algorithm 7 was motivated by the desire to avoid the
Look-up and Put-on at the same time. The Put-on algo¬
rithm is fast for sparse matrices, but if the input matrices are dense a
lot of positions will be set to 1 numerous times. The Look-up-algorithm
does not have this problem, once a position has been set to one it will not
be considered again. It is, however, inefficient for sparse input matrices
or, more generally, for multiplications in which a lot of positions stay 0.
The
design
of
inefficiencies of
For each
position which
this and if there
are
0(n)
is 0 in the result
time is
spent
positions the algorithm
many such
to determine
will take
a
lot
of time.
The recursive
After
setting
a
algorithm
position
avoids these two
problems
as
far
as
possible.
to 1 it is eliminated from further consideration.
positions are 0 the algorithm combines as many po¬
possible. However, if the structure of the output is of fractal
nature it is still possible to spend 0(n) for a lot of rectangles which
contain only a single position.
To determine that
sitions
3.4.3
as
Implementation
We have to be careful when
0(n3)
space
we
Issues
implement algorithm
requirement (in the
worst
case)
we
7. In order to avoid
must avoid to copy all
72
Chapter
3.
Boolean Matrix
Multiplication
the
edges of a layer during a call of bmmrec. Therefore we insert and
edges frequently. To perform delete operations quickly we have
use doubly linked lists. This implies a rather high memory overhead,
delete
to
if
even
we can
maintain
Also note that
not have
overall
an
have to
we
0(n2)
remove
two-paths passing through
space
complexity.
the vertices
them. If
we
m
E
M which do
do not, these vertices
accumulate and would have to be deleted for all the
remaining
the last step of the recursion. The removals in lines
(12), (17)
will
actually take place during the execution of
a complete scan of M.
the
zeros
and
preceding
in
(19)
lines in
order to avoid
Even
though algorithm 7 looks pretty simple, many list operations
computation of the three layer representations. The
implementation of this algorithm is therefore considerably more difficult
than the algorithms in the preceding sections.
are
involved in the
Optimization
3.4.4
The
of the vertical
a
the horizontal dimension of the parts of the
repeated application
significant reduction of
result
we
still need to consider. At
form the recursion to
algorithm.
sort.
split
the
We observe the
Once the
problem
size
some
splitting
point
rule
quickly leads
it will cost
more
than to solve it with
to
to per¬
problem
simpler
phenomenon when analyzing Quick¬
drops below a certain constant (probably
a
same
depending
implementation) we can sort faster using a simple
than
sorting algorithm
by further applying Quicksort recursively.
on
the
multiplication it seems natural to do the same.
simple algorithm is a variant of the Four Rus¬
sian algorithm presented in Section 3.2. Because the columns in a small
multiplication do not occur consecutively according to the initial num¬
bering, we need a slightly more complex, table based encoding and
decoding procedure. This optimization completes the algorithm by a
single scan of the data structure built so far. The algorithm itself there¬
fore takes at least as much time as the Four Russian optimization in the
end, this seems to be a reasonable trade off.
For boolean matrix
An obvious choice
a
following section we present empirical analyses which
algorithms and provide analyses for different settings.
In the
our
as
compare
73
Empirical Analysis
3.5.
Empirical Analysis
3.5
provide different kinds of bounds for the algorithms in the pre¬
simple version of the Four Russian algorithm we
can give coinciding upper and lower bounds for the worst case. Bounds
of this kind can only be improved by a constant factor, this is the
strongest result possible. For our recursive algorithm in Section 3.4 we
can only provide a rough worst case bound. Although the running time
will hardly be achieved this is not very convincing. To provide an unbi¬
ased comparison of these algorithms we present an empirical analysis.
We
can
ceding
sections. For the
After
experiences with empirical analysis
we compare the running times of our algorithms on a real time basis
in Section 3.5.3. In subsequent sections we analyze the behavior of
individual algorithms in more detail.
some
general
comments
on
General Issues
3.5.1
While in other sciences it is not
always simple to measure things directly,
usually simple in computer science. Experiments are
comparatively easy to conduct, we can implement an algorithm and
measure whatever we are interested in. In spite of this conceptual sim¬
measurements
plicity
are
it is sometimes difficult to determine the mechanistic models of
performance
based
on
the results
McGEOCH points out in
as
In part this is because size matters
a
[McG96].
lot for the results extracted from
experiments. McGeoch describes several examples where experimen¬
tal results had to be revised
once larger examples could be computed
processing power. In order to avoid this problem we
always included the largest samples possible in our simulations. Our re¬
sults usually display clear tendencies, such that we may be reasonably
sure that they also apply to larger problems.
due to increased
In this thesis
we use
experiments
want to determine average
for two purposes. On the
one
hand
the
empirically,
running
results
of
different
experimental
algorithms.
The experimentally determined average case running times underscore
the average case results of the previous section for our combination
algorithm, but they also show that the recursive algorithm does not live
we
other hand
up to
our
we
time
on
compare the
expectations.
We used
the most
case
(user-)time
to compare programs
significant operations.
This allows
as
an
opposed
to
counting
unbiased comparison
74
Chapter
3.
Boolean Matrix
Multiplication
running time
upper bound
30
*-
-
/
lower bound
"
/
25
-
20
-
15
-
-
/'
10
"
-
''
-'*
5
.._.*~*'
—+'
-*"•"
500
Running
3.4:
time
1500
1000
size
Figure
*
2000
of the matrix
plotted with error-bars,
upper and lower
bounds.
because the most significant operation is not the same for all the al¬
gorithms. Moreover in modern processors, with caching, pipelining,
branch prediction and the like, even a single operation does not always
take the
same
amount of time.
By choosing time as the basis for comparison we avoid these prob¬
lems, but of course we also get new ones. We ran all our experiments on
the
to
same
get
a
computer (a SUN Ultral with 64 MByte of memory) in order
fair
comparison.
implementation
absolute level of
A
the results
running
general problem
On
a
might
different machine
look
times would
or
with
a
different
different in form and the
slightly
certainly differ considerably.
with
experiments is how to present the results.
an algorithm in computer science involves
statements with 0(...) notation. This implies that constants are not
considered in such statements, but they describe the behavior of the
running time depending on the size of the input. A series of experi¬
The usual way to describe
ments allows
ings
us
in various
to make similar claims.
graphical forms, designed
We chose to present
to
emphasize
the
our
point
find¬
we are
interested in.
We tried two
approaches
to
derive claims about the behavior of
75
Empirical Analysis
3.5.
1
oc-uu
1 5e-06
1 4e-06
2
1 3e06
"I
1 2e06
H
i
i
1 le-06
i=
c\*l
0
500
Figure
3.5:
Running
with error-bars
the
(upper
(average) running
1500
1000
size
time normalized
and lower bounds
time in
2000
of the matrix
by r?, empirical
obvious)
0(.. .)-terms.
f(n) to
coefficients for candidate functions
First
we
bound all
data
plotted
determined the
running
times
plots as the one shown in
Figure 3.4 which looks quite promising. All the data-points are located
obtained in
our
experiments.
between two lines which
top
nor
the bottom
are
curve
This led to
pretty close
is determined
to each other.
Neither the
by the running
time of the
largest inputs and it is very tempting to accept the
asymptotic behavior of the measured algorithm.
function
f(n)
as
the
changes if we apply our second method to analyze the
computing the coefficients necessary for f(n) to
bound all the data-points we plot the coefficients which would suffice
for a specific data-point t8(n). In order to do this we compute
The situation
data. Instead of
same
(3.42)
U(n)/f(n)
for all the
the
same
which
then
plot
these normalized
f(n) as in Figure
/(n) grows slower
same
clearly suggests that
our algorithm because after
almost linearly for large n.
time of
grow
data-points i, (n) and
data and the
an
3.4
we
points. For
Figure 3.5
actual running
obtain
than the
initial decrease the coefficients
Chapter
76
Boolean Matrix
3.
Multiplication
All the measured
running times remain within the maximum and
bound, but it is highly probable that this is due to the fact
that our experiments have been run for "small" inputs only. Such effects
are hardly noticeable in graphics as in Figure 3.4 and we will therefore
prefer normalized graphics as in Figure 3.5 whenever we want to describe
the behavior of an algorithm, together with the corresponding normal¬
izing function. This approach led to convincing results in [BGK+95]
and we favored it over the log
log —plots presented in [McG96] as it
reveals the underlying structure more directly.
minimum
—
We chose to draw all the
plots
is, instead of simply plotting
that
In
matter)
Figure
also
we
in this section
the average
plot the
running
large
n.
The
larger
errors on
easily explained by the discretization
used in our examples had a resolution of
These techniques
an
algorithm.
We
experiments. If
can use
we
want to
verify
coefficients
are
(3.42)
or
one we
empirical running
refute
theoretical
running
non-increasing for large
a
hypothesis
We
apply
the results.
plot
our
If the
hypothesis,
Alternatively we can try to
the algorithm behaves differ¬
n we
and show that
time
based
hypothesis then the
times is fixed.
have to refute it.
we
of the timer, the
to all the data and
probably
compute larger examples
ently.
otherwise
a
running
figure
the left of this
0.01 seconds.
them to accept
function used to normalize the
division process in
error
be used to describe the
can
that
coefficient for
minimum and maximum value achieved.
are
on
(or
3.5 the error-bars indicate that the variance of the
time is very small for
of
using error-bars,
time
will accept
our
running time be¬
havior of an algorithm. Given a reasonable estimate we can strengthen
the hypothesis as long as the data support it. However, it may be dan¬
gerous to stress the limit and strengthen the hypothesis by too much.
The input size is always bounded and the hypothesis may only be sup¬
ported up to the size we have simulated.
We
can
apply
The process
a
similar
technique
usually provides
actually guarantee
malizing function f(n)
our problem domain. It
=
bound the
produces
possible, at least
which
as
running
a
In
correctness.
nk with
is
quite
time of
an
to determine the
bound, even if
examples we usually
reasonable
our
2 < k <
for
large
cannot
3, but this is determined by
easy to vary the value of k in order to
algorithm.
Our
normalized coefficients that
which grows faster than the
we
use a nor¬
goal
are
as
is to find
close to
a
an
f(n)
constant
might be acceptable to find a bound
running time of the algorithm, resulting in
n.
It
3.5.
Empirical Analysis
77
Recursive
algorithm
Four Russian
combination
variant A
variant B
0.2
0.6
0 4
portion of
ones in
0.8
the input
Figure 3.6: Running time of the algorithms for a boolean matrix multi¬
plication of two 1000 x 1000 input matrices and varying number of ones
in the
a
(Variants
algorithm.)
input.
Russian
curve
A and B
which tends towards 0.
are
optimized
However,
it is
versions
hardly
a
of
the Four
good
idea to
accept a bound which results in an increasing curve for large n. Such
a behavior would at least require further investigation in order to be
Usually
acceptable.
the normalized
curve
should not increase at the
end.
Claims derived in this way are based on empirical evidence, however
they can easily be refuted by showing that for larger n the performance
claims do not hold anymore. We still consider the
it
provides
a
approach useful, since
Usually we can simulate
probable line of development.
practical algorithms up to a level where statistical effects do not have
a large influence anymore.
However, some of our results show that
asymptotic behavior may start later than expected.
In
our
case, the behavior of
single point
algorithm
3.6
we
Matrix
an
algorithm for growing
n
is not the
of interest. We would also like to know if the behavior of
is different
depending
on
the
have drawn the running time of most
Multiplication
for
varying
an
density of the input. In Figure
our
number of
algorithms for Boolean
We multiplied two
ones.
78
Chapter
Boolean Matrix
3.
random boolean matrices of size 1000
bility
of
linearly.
As in
1000 and increased the
proba¬
3.5 the recursive
algorithm can not
and
takes
of
lot
than
either
the
other algorithms.
time
a
more
compete
The optimized versions of the Four Russian algorithm have an increas¬
ing running time for a growing number of ones and our combination
algorithm and the simple version of the Four Russian algorithm have
almost constant running times. The combination algorithm has a re¬
markable peak for small probabilities around the point where the switch
from Put-on to Look-up is likely to occur near the end of the algorithm.
For larger matrix sizes this peak occurs for even smaller percentage of
ones
Figure
x
Multiplication
ones.
The basic
shape
of
Figure
3.6 remains the
same
The percentage at which the combination
for all
input
sizes.
becomes faster than
algorithm
optimized versions of the Four Russian algorithm decreases slightly
for larger matrices, but there is little change otherwise. We therefore
chose to run most of the following experiments for a constant probability
as the probability has little impact on the running time (only a constant
factor). The recursive algorithm is an exception to this rule, but we
usually omit it because it is too slow. Most of our experiments were
run for p
0.2, the optimized versions of the Four Russian algorithm
the
=
are
still faster than the combination at this
point.
problem arises from the determination of the input data
experiments. Because we are not able to measure the running
for all the problem instances we are interested in, we have to
Another
for
our
time
choose
a
subset of instances to
measure.
In this thesis
we
do
so
by
randomly selecting inputs for our algorithms. Generally a selection of
inputs implies that the results are only valid if the real input has similar
characteristics as the randomly chosen inputs for which we perform the
measurements.
simply accepting this dependency we want to provide
data to quantify it. To achieve this we define models with limited ran¬
domness. We can then conduct experiments to establish a degree of
randomness for which our algorithms perform well. When we select an
algorithm to solve a practical problem we should take this into account.
Depending on the distribution of the actual data we have to choose
different algorithms.
Instead of
determining average
usually quite complicated, it is not always pos¬
claims analytically. By analyzing such models em-
Because the mathematical models involved in
case
running
times
sible to derive such
are
79
Empirical Analysis
3.5.
workings of algorithms even
if we do not understand their behavior completely. We consider this a
reasonable goal and suggest that these qualities of empirical analyses
pirically
we
can
investigated
are
derive
about the
further.
Experimental Setup
3.5.2
We conducted
our
processor and 64
2.5,
insights
our
compiler
programs
experiments
MByte
were
on
a
SUN Ultral with
main memory.
one
The workstation
written in C++ and
compiled
167 MHz
ran
Solaris
with the g++
version 2.7.2.
We used bitwise storage to store boolean and adjacency matrices
mostly singly linked lists to represent sets. Where-we need a com¬
and
array-list storage of sets we point this out explicitly. We chose
running times directly in order to allow an unbiased com¬
kinds of algorithms, even if these algorithms have
of
different
parison
different significant operations which differ in actual cost. In order to
reduce the effect of different levels of implementation quality we reused
data structures throughout the algorithms wherever possible.
bined
to compare
We
usually present
our
results in
graphical form. Alternatively
we
running time figures as CHERKASSKY et al. did
in [CGR94].
While tables provide more exact results we decided to
put more emphasis on the "big picture". The reader should be able to
"see" the point we try to make by reading the caption and looking at
might present
the
tables of
graphics.
frequently used plots display the minimal, average and
running time for varying number of vertices and a fixed per¬
of
edges. Depending on the kind of comparison we are inter¬
centage
The
in
ested
we sometimes chose a different graphical representation.
reflect
the
real
time
user time reported in the diagrams does not always
The most
maximal
elapsed directly, on several occasions we used more memory than was
physically present in our machine and the real time elapsed was much
larger due to paging. However, this could have been rectified by adding
more memory to the machine.
Throughout all our graphics you will
notice pretty little variance in the running times, at least for the large
instances. Variance for the small instances is chiefly dominated by the
resolution of the timer employed, it was limited to 0.01 seconds.
Chapter
80
Comparison
3.5.3
of
Boolean Matrix
3.
Multiplication
Algorithms
140
recursive
optimized
120
recursive
basic fourRussian
algorithm
algorithm
algorithm
combination
optimized fourRussian algorithm
100
~
1
o
80
K
I
60
«
c
£
c
40
20
*
«t...
500
2000
1500
1000
width of matrix
Figure 3.7: Comparison of the boolean
rithms for random input matrices with p
=
In
Figure
3.7
we
have
plotted
the
running
multiplication algo¬
matrix
0.2 constant.
times of
boolean matrix multiplication. The input matrices
our
were
algorithms for
independently
chosen at random; every position is one with probability p and 0 with
probability 1
p. We have run 100 experiments for each input size we
considered. The plots in Figure 3.7 contain the average, minimum and
maximum value for each problem size which shows that the variance of
the running time is negligible for all but the recursive algorithms.
—
plots
The
ishing
in
that the
good
Figure 3.7 contain some surprising results. It is aston¬
optimized version of the Four Russian algorithm per¬
as
larger
p for which the optimized version of the Four Russian
as our
is slower while
our
amount of time
as
then the
optimized
combination
algorithm. This
forms
combination
for p
=
changes for
algorithm
algorithm takes practically the same
0.2. On the other hand if
Four Russian
algorithm
combination algorithm. We present
time of the combination
situation
algorithm
a
is
likely
detailed
in Section
algorithm in Section 3.5.4. We present
an algorithm in Section 3.5.7.
our
we
have
a
smaller p
to be faster than the
analysis
3.5.5,
of the
running
the Four Russian
conclusions about
choosing
3.5.
It is not too
surprising
cation have very slow
that both variants of the recursive
running
structures to be efficient in
them
81.
Empirical Analysis
briefly
in Section
a
3.5.6, but will
The Four Russian
3.5.4
multipli¬
They simply use too many datapractical setting. We therefore analyze
times.
not consider them any further.
Algorithm
5e-08
4 5e-08
?
4e-08
N
§
3 5e-08
c
u
I
3e-08
c
c
I
2 5e-08
2e-08
1.5e-08
1000
500
0
size
2000
1500
of the matrix
Figure 3.8: Running time of the Four Russian algorithm
by n3 for varying n for random input matrices with p=0.2
normalized
Figure 3.8 we have drawn the running time of the most simple im¬
plementation of the Four Russian algorithm. We conducted 100 matrix
multiplications for each data-point we measured. The plot shows the
In
minimum,
malized
running for the 100 experiments nor¬
running times of the simple version of the
average and maximum
by n3. For large
Four Russian
n
the
algorithm differ insignificantly,
the variance is therefore
very small.
large n we tend
to accept 0(n3) as an empirical bound for the running time of this
algorithm. The decrease is barely noticeable and already for n29 the
coefficients increase. The bound is actually obvious from the implemen¬
Even
tation of
though
our
the coefficients decrease
algorithm,
but this
slightly
algorithm just
for
serves as a
baseline for
82
Chapter
further comparisons and
we
Boolean Matrix
3.
Multiplication
therefore include its empirical data
as
well.
*t.jc-u/
variant
A
variant
B
4e-07
a
3 5e-07
^
3e-07
2 5e-07
h
i
2e-07
a
1
sQ n-7
r
.
0
500
,_
1000
size
2000
1500
of the matrix
Figure
3.9:
Russian
algorithm normalized by n25 for random input
p
=
Running
times
of
optimized
the
variants
of
the Four
matrices with
0.2.
Both
our
very similar.
optimized versions of the Four Russian algorithm perform
However, the average case results are somewhat surprising.
0(n3) running times with smaller constants than
Figure 3.8, but the experiments do not confirm this hypothesis. Of
course the algorithm does not perform worse, but from the plot in Figure
3.9 we derive that the algorithm actually runs in 0(n2-5) which is the
normalizing function for this plot. The results for variant A and variant
B are almost the same. This implies that the difference between storing
the first matrix in list form and storing the second matrix as a translated
table is negligible. If memory is not a concern one can choose either
variant, otherwise it is probably best to choose the compressed form of
the input matrices in the first place and no preprocessing is necessary
for variant B, which we prefer for this reason.
We expected to find
in
For p
=
0.2
observe
we
by Figure 3.9.
running time increases
firmed
time of
0(n26).
an
When
as
This is
average
we
running
time of
0(n2-n)
as
con¬
increase p then the exponent of the
well. For p
surprising
=
0.4
we
find
anyway since
an
we
average
running
would expect
a
83
Empirical Analysis
3.5.
8 2e-06
I
8e-06
-
7 8e-06
t
-
7 6e-06
-
7 4e-06
-
7 2e-06
-
,.
"
7e-06
1
-
6 8e-06
-
6 6e-06
ft
-
<
f
i
6 4e-06
0
1000
500
1500
2000
width of matnx
3.10: Running time of the combination algorithm for random
0.2, normalized by n2.
input matrices with p
Figure
=
running
time of
We will
see
tively large
diminish if
0(n3)
with
originates from
a
compara¬
by the preprocessing step. The effect will
compute larger problems, although this does not become
base cost incurred
we
clear from the
in
plot
Figure
Combination
3.5.5
very small constant if p remains constant.
a
in Section 3.5.7 that this effect
Throughout
this section
3.9.
Algorithms
concentrate
we
on
our
robust version of the
We consider it most inter¬
combination as presented in Section 3.3.3.
esting for practical applications because of its self organizing character¬
istics.
For constant p
0(n2)
runs
because it
in
0(n2)
experiments
we
expect
ought
our
combination
to be faster than the
time for constant p.
on
random
input
As in the
algorithm to run in time
Look-up algorithm which
previous sections we ran
matrices with p
=
0.2. This led to the
plot in Figure 3.10 where we have drawn the running time normalized
by n2. The plot confirms our hypothesis, for constant p we may therefore
accept
0{n2)
as an
average
case
bound.
Chapter
84
Boolean Matrix
3.
B>
I
e=0 4
i-
e=0 3
«
e=0 45
«
i
I
1,1'
T
7 5e-06
mahzed
7e-06
(non
!!;
{(!
I
1
i
i
Multiplication
i
I
6 5e-06
time
6e-06
d
-
unn
,b
5 5e-06
T
.
"""
5e-06
I
I
l-BH
a
S3
I
§
H3H
*
4 5e-06
0
500
1000
Figure 3.11: Running time of the
by n2 for random matrices with p
combination
^,
=
However,
in
run
we
e
=
algorithm
normalized
0.3,0.4 and 0.45.
also showed in Section 3.3 that the
0(n2 Inn)
the results from
2000
1500
of the matrix
size
even
if
we
choose p
with p
experiments
=
—
p(n).
n~°
In
45,p
algorithm should
Figure 3.11 we present
=
n_0
4
and p
—
n~°
3
presented in Figure 3.11 and they show another surprise. The nor¬
malizing function in this plot was n2 and the plot shows that for all the
probabilities this bound describes the running time pretty well. The
n~° 4, it actually grows slightly faster
topmost curve is the one for p
are
=
than n2. The actual increase
proportional to n2log(/o^(n))
0(n2 log(n)) suggested by our analysis. It
seems that our algorithm actually performs better than we expected,
although we cannot prove this mathematically.
which is
a
matrix.
ones
to be
lot slower than
The running time of
strongly
seems
combination
our
probability
However, our analysis depends
on
in the
the
we
input
matrices have
algorithm
a
on
the
to consider alternative models for the
two
randomness
we
allow.
For b
=
depend
input
assumption that the
uniform distribution.
interesting
simple models to generate biased random
the probability p we introduce the bias-factor b
is
does not
used to determine the random
0
we
Therefore it
input.
data.
We chose
In addition to
to indicate the level of
have the unbiased situation
we
Empirical Analysis
3.5.
85
400
bias 0 99
bias 0 98
350
bias 0 95
bias 0 9
bias 0 7
300
bias 0 5
250
200
150
100
50
J_i
I
I
0
500
1500
1000
size
2000
of the matrix
Figure 3.12: Running time of the combination algorithm for a mul¬
0.2 and a biased matrix B
tiplication of a random matrix A with p
=
with varying bias levels bi.
considered
produces
our
before,
combination
which all the
completely nonrandom input which
for our algorithm. In the case of
worst input consists of a matrix B in
1 indicates
=
a
possible result
algorithm the
placed in the
ones are
other columns
gradually
b
the worst
are
0.
from the
We will
use
completely
the
only
algorithm
the number of
•
p
ones
in
random with
p columns while all the
our
matrices
in it
cases
the matrix A remains random
really influences the running
time of
in this scenario.
For both models
n
ones
n
random matrix B to the deterministic
worst case outlined above. In both
since
same
the bias-factor to vary
a
row.
we
In
wanted to preserve the property that
our
probability
p
first model
as
we
before. For
we
determine the first
row
I > 1
we
expect
row
at
determine the
probability for a one at position a^ based on the number of ones in
positions an, 1 < i < l and the bias factor bi. The probabilities are
computed throughout the initialization as
Er=l E"=l
ars
n
86
Chapter
Boolean Matrix
3.
Multiplication
0 0001
bias 0 99
9e-05
bias 0 98
bias 0 95
8e-05
bias 0 9
7e-05
bias 0 5
bias 0 7
^
'«
N
'w
6e-05
B
o
c
5e-05
Ull
4e-05
c
c
run
3e-05
§
$
2e-05
.!
I
*
1
-i*
le-05
%
i
0
0
500
1000
size
1500
2000
of the matrix
Figure 3.13: Running time of the combination algorithm for a mul¬
0.2 and a biased matrix B
tiplication of a random matrix A with p
with varying bias levels bi, normalized by n2.
=
The bias-factor therefore indicates the part of the
distributed
according
to the
ones
in the
rows
probability that
not very sensitive to the increase of the bias factor.
we
still get
larger
a
time behavior of
running
constant.
The
time grows fast up to
and the
curves
a
in
Figure
0(n2) though
was
=
with
point the
similar to the unbiased
slightly
running
a
3.12 indicate that the
certain level. After this
is
algorithm
0.9
Up to bi
above. Our
flatten
curves
case.
algorithm runs
Figure 3.13 we
plotted the running time normalized by n2 for the same data as in
Figure 3.12. The plot clearly indicates that the running time grows in
proportion to n3 up to a certain level, but then it behaves rather like
0(n2). This basic behavior applies to all bias-levels though the 0(n2)
behavior is reached later for bi sa 1. A large bias-level prolongs the
Put-on phase of our algorithm. Our analysis in Section 3.3.2 indicates
that this phase is more expensive than the Look-up phase. It is obvious
that our algorithm as a whole will take more time if its Put-on phase is
longer because the time spent during the Look-up phase remains almost
In
have
constant.
At bias-levels close to 1 there may not
between the two
However
will take
and the
phases.
place eventually
once we
reach
a
even
certain
be
n
a
switch
the switch
algorithm will again complete
in
0(n2)
3.5.
Empirical Analysis
87
5 5e-05
bias 0 95
5e-05
bias
bias
bias
bias
I
*
4 5e-05
-
0 9
0.7
0.5
0.3
4e-05
3 5e-05
3e-05
2 5e-05
-
2e-05
i'
1 5e-05
i
m
m
*
*
«
D
m
A
*
s
le-05
fi5
A
A
X
5e-06
500
0
1000
size
1500
2000
of the matrix
Figure 3.14: Running time of the combination algorithm for a mul¬
0.2 and a biased matrix B
tiplication of a random matrix A with p
—
with
varying
bias levels
time, though with
b2,
much
a
normalized
larger
If the bias-level grows with
algorithm which runs
trivially true for t>i
=
more
detail
as
we
we
consider
distribute the
matrix B into
a
we
are
will not
an
a
rest.
However, this is
biases close to 1 in
A
deterministically.
We divide
The left part consists of
position
in the left
part
\n p]
a^ shall
probability
n
p
n
position
execute the Put-on
investigate
more
right part.
b2
Pi
a
basically
alternative biased random model. This
probabilities
left and
will
we
time for constant p.
obvious.
columns, the right part of the
be 1 with
constant.
n
0(n3)
1 and
the results
Instead of this
time
in
by n2.
in the
right part
ar
with
probability
n-p-(l-b2)
n
(1
-
b2,
-p
p)
p-(l-b2)
1
—
p
Using this more deterministic random model we generated the plots in
Figure 3.14. The situation for an individual bias looks similar to the one
88
Chapter
Boolean Matrix
3.
Multiplication
le-06
It
9e-07
regular
version
optimized
version
8e-07
7e-07
6e-07
5e-07
4e-07
3e-07
2e-07
le-07
*E,.
0
500
Figure
tions of
in
random
3.13.
=
However,
substantially
much time
for bi
as
The
0.9.
=
Recursive
running
this kind of bias-level affects the
than bi. For
doubles and remains in
3.5.6
2000
of the matrix
Running time of the recursive algorithms for multiplica¬
0.2, normalized by n3.
input matrices with p
3.15:
Figure
more
1500
1000
size
times of
a
Up
b2
=
to these bias
running
algorithm takes
levels the running
0.7 the
time
almost
time
as
only
reasonable range.
Algorithm
algorithm
7 and its
optimized version have been
Figure 3.15. The graphic shows
that both the algorithms run in 0(n3) empirically. The plots show the
coefficients for n3 and both are pretty horizontal, though the running
time for the non-optimized version was excessive and we therefore only
disappointing
as
becomes obvious in
simulated instances up to n
700. The difference in the coefficients be¬
tween the optimized and the nonoptimized version are huge, more than
=
an
magnitude, but even the optimized version is not faster than
simple version of the Four Russian algorithm. The empirical
also leave little hope that this might change dramatically for
order of
the
most
results
larger
n.
3.5.
89
Empirical Analysis
3.5.7
Choosing
an
algorithm
—r-
4e-05
optimized
Four Russian
*-»
algorithm
•-+
combination
2e-05
le-05
8e-06
s
-
•
\;
!
I..
6e-06
i
X
I
•
•
4e-06
f'
.•••
-
2e-06
3000
2000
1000
4000
5000
width of matrix
Figure
Direct comparison
3.16:
rithms, random input
ized by n2.
of
matrices with p
the running time
=
0.2 and
no
bias
of the best algo¬
factor, normal¬
empirical results for the boolean matrix
multiplication we offer a guide for choosing an algorithm in practice.
Our results indicate that there are basically two algorithms from which
to choose. In the comparison in Figure 3.4 the curves of our combination
algorithm and the optimized version of the Four Russian algorithm are
almost congruent. However, the running time characteristics of these
algorithms presented in Sections 3.5.4 and 3.5.5 differ considerably.
To summarize
our
discussion of
plotted a direct comparison of these two algorithms for
0.2 normalized by n2 in Figure 3.16. The second curve in this figure
p
indicates, that our combination algorithm really runs in n2 for random
inputs. The plot for the Four Russian algorithm in fact looks like a linear
function which does not pass through 0. We can therefore explain why
we found a running time of 0(n2 5) in Section 3.5.4. This result would
not have been acceptable anymore if we had run simulations for larger
inputs. While simulating larger instances we would steadily have to raise
the exponent, but the actual 0(n3) appears most obvious in a plot as
We have
=
in
Figure
3.16.
We
were
lead to accept the lower bounds because the
Chapter
90
Boolean Matrix
3.
Multiplication
running time has a large offset incurred by the preprocessing.
5
appropriate constant the n2 curve runs tangential to the
actual running time for the maximum size of matrices simulated. This
lead to a graphic which we erroneously took as evidence of the lower
running time bound. To account for this observation we suggest to start
an empirical analysis with a plot normalized by the expected running
time of the pre- and postprocessing.
actual
With
an
Our simple divide procedure does not always reflect the running time
of the
algorithm appropriately. The running time of the Four Russian
algorithm actually is in 0(n3), but the corresponding constant is pretty
small. The preprocessing takes time 0(n2), but the corresponding con¬
stant is rather large. Both algorithms rely on preprocessing which is
responsible for the observation that neither
series of coefficients ap¬
directly by
0 for small inputs. This is not revealed
proaches
Usually the
ning time, but as in
process.
amount of the total
the division
largest component in the run¬
preprocessing part took a significant
process reacts to the
our case
the
running time
we were
lead to accept
a
running time
obviously incorrect. This could be avoided by ana¬
lyzing the algorithms separate from their preprocessing. We could then
try to determine the asymptotic behavior of an algorithm empirically,
however, by doing so we would neglect a significant part of the running
behavior which is
time.
To determine which
directly.
algorithm
algorithm
to choose
As
Russian
is the best choice up to
we can see
in
will be slower than the combination
Russian
will be
algorithm
even
faster for
is
more
we
n
rely
may
Figure 3.16,
ical data
for p
about 2000.
algorithm
for
larger
empir¬
0.2 the Four
However, it
n.
The Four
sensitive to the absolute value of p,
better for smaller p, but the combination
larger
on our
=
algorithm
so
it
will be
p.
Another factor to consider is the bias-level inherent to the data, espe¬
cially
matrix B in
our
formulations. The Four Russian
sensitive to biased random
on
p. For the combination
hardly depends on
the bias-level, that
columns with
where
we
only
may
is
is
the absolute value of p, but it is
very little
assume
the combination
runs equally
data,
algorithm the situation
is it takes
a
strategy.
high however, then
a
lot of time if there is
ones.
algorithm is not
only depends
well and
it
In
practice there
quite different.
quite sensitive
a large number
will be many
It
to
of
cases
reasonable level of randomness which favors
If the
probability
the Four Russian
of
a
algorithm
biased
input
matrix
is the better
choice,
3.6.
91
Conclusions
especially for
sparse matrices.
rely on rea¬
same
presented
experiments
assumptions or run
in this section to determine the optimal choice. We qualitatively present
the situation for large matrices and small biases in Figure 3.16. The ba¬
sic picture will remain for other situations. The crossing will occur for
smaller matrices for larger p and for larger matrices for high biases or
For
practical input
distributions
we
will either have to
kind of
the
sonable
we
smaller p.
Conclusions
3.6
chapter we studied algorithms to perform Boolean Matrix Multi¬
plication. We were mainly interested in simple and practical solutions.
We presented different variants of three kinds of algorithms. An ap¬
proach based on the Four Russian algorithm, our combination strategy
and a recursive approach.
In this
algorithms have many properties which we cannot ana¬
lyze mathematically, we also presented empirical analyses. Some of the
graphics we presented simply confirmed the theoretical results presented
earlier, but we also found quite surprising behavior. Some questions
arise from these analyses, namely if it is possible to find a better theo¬
retical analysis for our combination algorithm for p
p(n). Our results
in this chapter suggest that it could be possible to find an 0(n2) average
time algorithm for the standard input model.
Since these
=
The methods
they
revealed
gorithms.
a
we
used for
It should be
empirical analysis
interesting
domain because it allows to
analyze
to
were
running
develop
techniques
more
effects which
bounds for
While it makes
sense
are
too
but
simple,
time of
our
al¬
in this
complex
analysis.
algorithms empirically, using 0(...) analysis, one
loose focus for the absolute running time in seconds.
mathematical
also not
our
lot about the structure of the
for
a
to determine average time
should
analysis indeed shows that the 0(n3) Four Russian algorithm
has sufficiently small constants to be competitive to our 0(n2) combi¬
nation algorithm for n up to 2000. Since it is quite probable that in
practice we will either have very small p or a rather biased matrix this
observation will also hold for even larger n. This also sheds some light
on the more complex algorithms usually cited for boolean matrix mul¬
tiplication. Algorithms such as the STRASSEN-algorithm in [Str69] and
Our
Chapter
92
the Coppersmith and
worst
case
0(...)
running
terms.
3.
Boolean Matrix
WiNOGRAD-algorithm
in
Multiplication
[CW90]
have
a
better
algorithm,
algorithms have much larger constants.
simple combination algorithm is only com¬
time than the Four Russian
at least in
However these
We observed that
even our
petitive for rather large n and pretty large p. It is therefore not very
probable that the more complex algorithms will be competitive at all
for reasonable problem sizes and input distributions.
Chapter
4
Transitivity
The Test for
4.1
In
The Problem
Chapter
2
we
an
gave
overview of the research done in the field of
presented our contribution to it. In this
chapter we focus on the second step of the algorithm to recognize compa¬
rability graphs. The orientation resulting from the transitive orientation
algorithm is guaranteed to be transitive if such an orientation is possible
which would imply that the graph is a comparability graph. However,
we still have to test if the orientation computed by algorithm 5 is in¬
deed transitive in order to recognize comparability graphs. Since the
introduction of transitive orientation in [Spi85] the test for transitivity
has been the domintating part in the comparability graph recognition
algorithm. In spite of this it received comparatively little treatment in
transitive orientation and also
the literature.
To test if
an
orientation T
equation (1.1).
every ordered triple of
The most
=
(V, F)
simple approach
vertices a,
b,
c
using
In
an
we
have to
verify
to achieve this is to test for
6 V that
(a,b)eFA(b,c)F
This characterization
is transitive
=*
directly implies
an
(a,c)
F.
0(n3) algorithm
for the test
the matrix representation of the transitive orientation.
[Spi85]
orientation
Spinrad
as
a
proposed
test for
to
compute the transitive closure of
transitivity.
93
This
can
be reduced to the
94
Chapter
Transitivity
The Test for
4.
computation of a boolean matrix multiplication which has a worst case
running time of 0(n2'zs) using the algorithm presented in [CW90].
However, the implementation
of this
algorithm
is very
complicated
and the running time involves huge constant factors. For this
does not
to be
reason
it
very practical solution. In this chapter we present
practical solutions for realistic problem sizes. We are not only interested
in a good asymptotic running time, but we also desire comparatively
small constants. Because worst cases rarely occur in practice, we focus
seem
a
average time behavior and
on
consider
some
rather
In Section 4.2
-
in order to
get small
constants
we
-
simple algorithms.
briefly
performed by
multiplication.
point out some
additional algorithms to test a graph for transitivity in Section 4.3 and
provide an empirical analysis of these approaches in Section 4.4.
reduction to
4.2
a
we
discuss how this test
boolean matrix
can
be
We then
Reduction to Boolean Matrix
Multipli¬
cation
SPINRAD introduced the test for transitivity
as
an
important part of
comparability recognition
[Spi85].
the most time consuming part in this process. Spinrad
to the computation of a boolean matrix multiplication* of
Since then the test has remained
in
reduced it
two
n
x
n
matrices.
To test if
For
a
graph
a
G
graph
=
is transitive
(V,E)
_
13
we
first compute its
adjacency
matrix.
this is the matrix A with
f1
if and
10
otherwise.
only
if
(i,j)
G E
and
u
i)
algorithm 5 a matrix representation of the graph is required and
therefore its computation is free of charge. We can test if G is transitive
A A. If there is a pair
by computing the boolean matrix product 5
For
=
(i,j)
of indices
with
o,j=0A
then the
graph
G is not transitive.
s,j
=
(4.2)
1
If sZJ
=
1, then there
must be an
index fc for which
atk
*
Defined
as
C
=
A
B with ctJ
=
=
1 A akj
\Jk alk
A
—
1.
bkj,
see
chapter
3 for details.
This
implies (i, k)
there is
matrix is
—
transitivity.
adjacency matrix of a transitive graph. We
transitive if its corresponding graph is transitive.
an
Because matrix A
tation of
0 implies (i, j) ^ E
E. Because at]
In the following the term transitive
(k, j)
£ E and
violation of
a
matrix denotes
a
95
Simple Algorithms
4.3.
corresponds
adjacency
to the
matrix of
reason, every
sufficient to show that
Obviously
the
same
no
such
orien¬
For this
it is also
pair exists.
simple algorithm for boolean matrix multiplication has
as our simple procedure to test for transi¬
a
0(n3) running time
tivity. However,
by performing
malize all the
This
an
1 and an
1 can be true.
graph only one of atJ
possible violation of transitivity implies (4.2) and
a
=
=
also say
multiplication can also be computed
multiplication. We then have to nor¬
boolean matrix
regular
nonzero
matrix
matrix
get the
entries in the result to 1 to
allows to make
approach
ing regular
a
a
use
correct result.
of the advances made in comput¬
multiplications. Surprisingly these- techniques still
asymptotically fastest worst case algorithms to compute
products. The best algorithm to date is due to Cop¬
and Winograd[CW90], it has a worst case complexity of
represent the
boolean matrix
persmith
0{n23S).
Unfortunately,
fast
algorithms
involve
huge
4.3
constants and
are
Simple Algorithms
In this section
we
present simple algorithms specifically designed
algorithms exploit
transitivity.
problem to improve performance. Actually,
test for
our
they
regular matrix multiplication are
implement. Their running times
fast only for very large inputs.
for
difficult to understand and hard to
These
present have
show that
4.3.1
a
refine in
case
The Basic Path
In this section
time of
running
algorithms perform
worst
some
the
we
0(n3),
much better
special
all the
but
on
to
structure of
algorithms we
experiments
our
average.
Algorithm
introduce the basic
subsequent
sections.
algorithmic concepts which we
we develop a slightly different
checked more efficiently. Instead
At first
representation of (1.1) which can be
of testing (1.1) for all triples (a, b, c) 6
(a, b)
E A
V
(b, c)
we ensure
e E
that
(4.3)
Chapter
96
Algorithm
(1)
(2)
(3)
(4)
(5)
(6)
(7)
(8)
isTransitive(G)
8
The Test for
4.
Transitivity
(path method)
forall b£V do
forall
a
Gadj~(6)
forall
if
c
G
do
adj+(6)
(a, c)<£E
do
then return
FALSE;
od
od
od
TRUE;
return
and therefore
(a, c)
adj-(j)d=
G E must be tested. To do so we determine the sets
{i\(i,j)EE}
adj+(j) ^ {k \ (j,fc)
and
G
E}.
usually assume a list representation of these sets when stating run¬
ning times. Using the matrix representation of the orientation the list
We
representation
which
(a, c)
be
can
computed
in
0{n2)
time. Now the set of
pairs for
by
G E must hold is determined
(Jadj-(&)xadj+(6).
(4-4)
bV
To test
graph
a
for
transitivity
we
have to
verify
that
(a, c)
G E
for all
certainly
pairs
(4.4) (see algorithm 8).
n3 tripples fullfilling 4.3 as in the simple algorithm outlined before. But
of vertices in
because
There
transitive orientation of
a
complete graph
a
n—1
less than
are
has
q
E.,.(„-,)
,
n
.
=
—
n
——
pairs satisfying (4.3) this algorithm improves the worst
time only by a constant factor if we test all the pairs.
In this section
Usually
try
running
Exploiting Transitivity
4.3.2
we
case
we
the basic
to avoid
introduce
an
algorithm
which is based
on
algorithm
8.
lot of redundant checks which
algorithm performs
the transitivity of
by exploiting
a
the C-relation.
97
Simple Algorithms
4.3.
Algorithm
(1)
(2)
(3)
(4)
(5)
(6)
(7)
(8)
(BFS method)
isTransitive(G)
9
forall
G V do
a
6eadj+(a) do
forall
G adj+(i) do
forall
c
(a, c) $
if
E then return
FALSE;
od
od
od
return
TRUE;
Algorithmic Concept
The
in Section 4.3.1
algorithm
search
(BFS)
checks
as
like
algorithm 8, only
in
time remains the same, but
the
transitivity
Va G V
:
V6 G
be formulated in
9
a
improve algorithm
have to verify if
we can
we
adj+(a)
adj+(6)
:
breadth-first-
obviously performs
different order. The worst
a
Actually
of C.
can
Algorithm
manner.
C
9
the
same
running
by exploiting
adj+(a).
case
(4.5)
Most of the time it is wasteful to test this condition for every vertex
adj+(a).
b G
Assume three vertices
Since v,
w
G
adj+(w)
adj+(u)
and
later, because
w
G
G E.
would test if
we
C
(u,v), (u,w), (v,w)
with
u,v,w&V
adj+(u)
adj+(u;)
A
adj+(u),
if
adj+(iu)
C
C
adj+(u)
adj+(t;).
The test
adj+(u>)
C
adj+(u)
is redundant because
adj+H Cadj+(u)
implies
it. In the
following
we
A
adj+(w)
develop
an
C
adj+(u)
algorithm
which avoids these
redundant tests.
The basic structure of
The
only change
occurs
our
in the
algorithm is derived from algorithm 9.
loop (2)-(7) where we no longer need
98
Chapter
The Test for
4.
perform the innermost loop for all vertices b
perform the test for all vertices in a set B which
to
fly. Initially
set B
we
adj+(a)
=
and then
we
vertices for which the test does not have to be
For the first vertex
All the vertices
them from B since
whether
the
adj+(c)
remaining
b\
adj+(&i).
C
(1)
(2)
(3)
(4)
(5)
(6)
(7)
(8)
(9)
(10)
(11)
always
we
have to
must be in
will check later
we
We
pseudo-code
for this
isTransitive(G)
10
Instead
compute
we
and
we
can
have verified
choose
new
a
remove
we
the
on
those
perform the actual
adj+(a)
iteratively
adj+(a).
gradually remove
performed.
(or maybe
vertices in B and continue to
empty. We present the
Algorithm
G B
adj+(&i)
G
c
Transitivity
test.
remove
already)
vertex from
vertices until B is
approach
in
algorithm
10.
(extend-method)
forall aeV do
£^adj+(a);
while B
^ 0
do
choose b £ B and
forall
remove
c<Eadj+(&)
it;
do
(a, c)iE then return FALSE;
else B<-B-{c};
if
od
od
od
return
Until
TRUE;
did not
now we
tices and the
edges.
assume
anything
about the order of the
While the order in which vertices
ver¬
processed in
the algorithm
are
the first
loop is not very important, the running time of
depends crucially on the order of vertices in B. If we process these ver¬
tices in order of increasing degree we cannot expect a big improvement
in running time. If for a vertex v
B there is a vertex u
adj+(u) for
which |adj+(u)| > |adj+(v)| then the graph can not be transitive and
we
have finished anyways. If there is
move
any vertex from B in line
degrees have
been
(7)
no
such vertex then
we
cannot
re¬
because all the vertices with smaller
processed already
and therefore
are
not
present in B
anymore.
This observation suggests
tices in order of
a
better
decreasing degree,
then
strategy. If
we can
we
process the
probably
remove a
ver¬
lot of
99
Simple Algorithms
4.3.
Actually in a transitive graph an ordering of the ver¬
tices by decreasing degree corresponds to a topological order. If ord(u)
denotes the index of v in the topological order of G
(V, E), then
vertices from B.
=
ord(a)
\/(a,b)E:
<
ord(6).
following we only consider the case where the vertices of B are
topologically. The sequence of decreasing degrees is just a spe¬
cial topological order of a transitive graph. To compute such an order
we can use the topsort-procedure given in algorithm 13 (see Appendix
A.3). During the computation of a topological order we can also de¬
termine if the orientation contains a cycle. Obviously a graph which is
not acyclic cannot be transitive. By sorting the adjacency lists of all
vertices according to a topological order with algorithm 14 we have
In the
ordered
Vu,
w
£
adj+(u)
ord(u)
:
adj+(t;)
All the vertices q
largest degree
may
case
remove
a
occurs
ord(w)
«•
must be in
first. Once
we
v
preceeds
already)
in
w
adj+(u).
adj+(u), but the vertex with
adj+(v) C adj+(u) we
have tested
lot of vertices from B. Other tests will
it has not been verified
proves
<
that
adj+(g)
C
verify (in
adj+(t;)
this
which still
transitivity.
Usually this will save considerable time, at least on average. In the
following section we present a graph for which algorithm 10 takes 0{n3)
time and in Section 4.4.2 we present experiments which suggest a much
better average case performance.
Implementation
Running
and
In order to achieve
to pay attention to
an
Time
optimal running
some
algorithm
implementation.
time for
details in the
10
we
need
To execute
loop (5)-(8) efficiently, that is in time 0(|adj+(6)|), we need an
adjacency list representation of the input. However, to execute line (6)
efficiently, that is in 0(1), we also need an adjacency matrix. Even
though the dual storage of the input seems wasteful, it improves the
performance.
the
a list implementation, it contains
scanned, and we need to remove the first
perform deletes at random places. To per¬
The purpose of the set B suggests
all vertices that must still be
element.
form
However, we also
both, delete first and delete random,
in
O(l)
time
we
would need
Chapter
100
The Test for
4.
Transitivity
Figure 4.1: A graph for which algorithm 10 takes time 0(n3). Vertices
All
in the first set are connected to all vertices in the other two sets.
edges are directed according to the edges indicated.
a
combined
matrix
the
list-array representation. However,
representation
advantage
negligible
in
comparison
if at all
For this
it takes
to
0{n)
because
we are
given
a
to set up the data structure and
a
simple
array
a
simple
array
representation would be
existing.
reason
we
selected
implementation. We now have to scan
only perform the inner loop if the current
our
representation for
B in
the whole array once, but
vertex is still
we
present in B.
Next
we are concerned with the order in which to sort the adjacency
Using the adjacency list representation we can determine a topo¬
logical order in linear time using algorithm 13. To order the adjacency
lists of our input graph according to the topological order we use algo¬
list.
rithm 14 which also
runs
in linear time.
So all the
preprocessing steps
performed in linear time or time 0(n2) if we have to compute the
list representation prior to the execution of the algorithm. Until now we
have not considered the cost of loop (5)-(8). This loop can take no more
than 0(n) time. The first loop is always executed n times and therefore
the running time depends most crucially on the number of executions
of the loop (3)-(9). In Figure 4.1 we show a graph in which line (6)
can
be
must be executed at least
n/3
n3/27
times.
vertices in the set B for which the
For each execution the
n3/27
is
a
loop (5)-(8)
lower bound for the worst
n/3 vertices
loop (3)-(9) must
For
takes time
case
n/3
running
there remain
be executed.
which shows that
time. The
following
theorem summarizes these observations.
Theorem 25
transitive.
Algorithm 10 tests in 0(n3) time if an input graph
are graphs for which this bound is reached.
There
is
4.3.
101
Simple Algorithms
Proof: Since
each of the three
loops
the first part of the theorem follows
immediately from the preceding
Although this
a
lot of
cases
result
seems
can
be executed at most
trivially.
n
times
The second part follows
discussion.
O
disappointing
for the worst
case
there
for which this bound is not achieved. We did not find
a
are
way
algorithm analytically.
probability model
for random transitive inputs. In Section 4.4.2 we therefore analyze the
behavior of this algorithm empirically. The input model used for this
analysis involves the computation of the transitive closure which is a
deterministic process. The inputs are therefore not strictly random
which prevents the application of the usual approaches for average case
analysis.
to determine the
It
proved
expected running
time of this
to be too difficult to establish
a
reasonable
A Recursive Solution
4.3.3
In this section
transitivity test by a Boolean Matrix Mul¬
tiplication
However, the specific structure of
the problem allows a more efficient recursive approach than in the case
of Boolean Matrix Multiplication in Chapter 3.
as
we
solve the
outlined in section 4.2.
Algorithmic Concept
In order to do this
matrix A of G
=
we
(V, E)
as
defined in
S
and this is the condition
transitive there is
implies
that there
Instead of
tinue until
putations
we
d^f A2
are
are
A of the
to test.
In
a
graph
0 for which sl}
{k,j) E where (i,
=
which is not
1 holds.
j) g
multiplication
This
E.
we
only
To avoid redundant
con¬
com¬
have found al}
1 we proceed
in
Section
The gen¬
3.4.
presented
we
similar to the
adjacency
graph satisfies
(4.6)
is violated.
positions for which
A
C A
whole matrix
(4.6)
=
A transitive
=
edges (i, k),
find that
(4.1).
going
position a%]
computing the
we
at
recursively,
a
A2
consider the square
=
approach
partitioning is the same as in Figure 3.2, we choose a pivot vertex
v and split the initial matrix multiplication into three smaller
multipli¬
cations according to their relationship to v. The general partitioning of
eral
the result matrix is the
same as
in
Figure
3.2.
Chapter
102
While the
general concept
The Test for
4.
Transitivity
algorithm is similar to the recursive
Multiplication we use a less complicated
data structure for the test. Each part of the test is described by the sets
hor and vert which restrict the positions in the result matrix S and the
set through for which the two-paths have not been tested yet. Again we
assume that the rows and columns of the input and result matrices have
been rearranged in order to simplify Figure 3.2. Now we split the result
matrix as outlined on the left of Figure 3.2. In a recursion of depth k
we split the vertices into the sets
of this
version of the Boolean Matrix
9i{v)
=
{J
vert\ak]
^
=
1}
and
g0{v)
=
1}
and
ho(v)
=
{j
e vert
{i
6 hor
\ak]
=
0}
in vertical and
hi(v)
=
{i
E hor
\
atk
in horizontal direction.
according
to the
determined
The result is therefore
right graphic
Figure
in
For A to be transitive all
some
regions, gi(v)
ones, but
we
necessary
alk
=
}
regions
region is
into three
The left upper
3.2.
0
positions
x
h0(v)
hx(v).
in this
and
captured by
50(v)
no
must be one.
region
V
x
we
For the
still have to check
path through
vertex
the three parameters of
v.
procedure
11. We still need the matrix to test if all the
algorithm
are
x
know that there is
This situation is
rec.test in
split
|
by
9i(v)
other two
—
present. The sets
actually
part of the multiplication.
S'
=
{
vert and
hor,
through
ones
define
stJ
I
i £ hor
Aj£
vert
}
computed by multiplying two submatrices of A. The submatrix A\
defined by the sets hor and through as the positions atk of A with
is
i 6 hor
Accordingly
the
and
fc
is
through.
positions ak] with
k
define the submatrix
through
and
j
vert
Ai
A2 is computed
smaller
pieces. The algo¬
Unfortunately,
A2. The multiplication S'
11 which divides it into
using algorithm
quickly
rithm finishes
a
The submatrix
even
if the result has almost
=
n2
ones.
4.3.
Simple Algorithms
Algorithm
(1)
(2)
(3)
(4)
(5)
(6)
(7)
(8)
(9)
(10)
(11)
(12)
(13)
(14)
(15)
(16)
(17)
(18)
(19)
(20)
(21)
(22)
(23)
(24)
(25)
(26)
(27)
if
103
rec_test(v4, vert, hor, through)
11
\hor\
=
0
or
\vert\
=
0
or
\through\
=
0 then
TRUE;
return
fi
choose k from
through;
forall i £ vert do
if alk
—
1 then
append
i to
verti;
i to
verto;
else
append
fi
od
forall
£ hor do
j
if a.k}
=
1 then
append
i to
hori;
i to
horo;
else
append
fi
od
forall i
verti do
forall
horx do
j
if al3
=
0 then return
FALSE;
od
od
if not
rec_test(A, verti, horo, through
return
—
{
k
})
then
FALSE;
fi;
return
rec_test(yl, verti, hor0
l±l
hori, through
-
{
k
})
Chapter
104
the square of
(n2 +n)/2
improve
matrix of
Transitivity
graph contains at least
simple implementation
algorithm will only
if
finds
time
it
a violation of
significantly
running
quickly
an
zeros
the
adjacency
The Test for
4.
and
transitive
a
of the
a
transitivity.
To test
an
matrix A for
adjacency
transitivity
we
call rec_test with
parameters
rec_test(j4,V,V,V).
Implementation
analysis
Our
and
of the
Running
Time
running time of algorithm
ture of its recursion tree.
11 is based
on
A vertex in this tree represents
the struc¬
procedure
submultiplication as introduced in the previous sec¬
tion. We can derive the running time directly from the following Lemma
about the time it takes to execute procedure rec.test.
call to compute
a
Outside
Lemma 26
of
the
loop (19)-(23)
rec-test(A, hor, vert, through)
Proof:
a
takes time
a
call
0(\hor\ \vert\ \through\
Procedure rectest either terminates in line
(2)
or
in line
+
(21)
1).
or
it calls two further instances of itself with modified parameters. In the
the
first
case
case
it takes
difficult and
First
line
(27)
we
procedure obviously
no more
we
•
case
is
more
proceed inductively.
consider the
case
that
one
is empty and the second call
of the
covers
the
the induction
sets in the first call in
the
same
part of the result
been removed from the set
\vert\ (\through\
0(\hor\
by
and in the second
time. The third
original call. Since one vertex has
through this call can be completed in time
as
0(1)
takes time
0(|/ior| |veri|)
than
assumption. During the
—
1)
+
1)
current call
we
have
spent
time
0{\hor\
+
\vert\
The empty call contributes another
\hor\
+
\vert\
leads to the desired bound. We
trivial.
(4.7)
1).
O(l) which, keeping
< 2
can
+
•
\vert\,
(4.8)
similarly
if the second call is
\hor\
argue
in mind that
Simple Algorithms
4.3.
Finally we have
(27) are nontrivial.
105
to consider the
that both calls in lines
case
The induction
the recursive calls. The first recursive call is bounded
0(\hor\ \vertj \ (\through\
while the second call is bounded
0(\hor\
(4.8)
Because of
result follows
Using
and
1)
+
1)
1)
+
1)
by
\vert0\ (\through\
-
(19)-(23) we spend the same time
obviously \vert\
\verto\ + \verti\
Lemma 26
Proof: Lemma
(19)-(23).
a
takes time
26 proves that
For this
once
recursive calls.
This is also
as
(4.7).
in
the desired
state:
can now
The test for transitivity
rec-test(A, V, V, V)
only
=
again.
Theorem 27
checked
and
by
Outside of lines
time.
lines
-
(24)
upper bounds for
assumption yields
no more
loop
since these
we
a
matrix A
using
than
(21)
running
0(n3)
a
call
time is spent outside
guarantee that each
can
positions
Therefore line
bound for the
of
0(n3).
are
not covered
in A is
by subsequent
0(n2)
is executed at most
time of
one
loop (19)-(23)
times.
which proves
the theorem.
Remark: This worst
case
which divides the result into
transitive matrix at least
construct
good
even
cases
0(n2)
parts which
(n2 +n)/2 positions
matrix which divides these
a
division is
bound is achieved for
for
probable
algorithm
for transitive
11. We will
zeros
an
remain
into
zero
0{n2)
matrices, they
improve
adjacency matrix
Because in
are zero.
on
it is
simple
a
to
spots. Such
a
therefore not
are
this in section 4.3.4.
Most of
to be
algorithm 11 is straightforward to implement. Some care has
applied for the construction of the sets hor\, hor0, verti and verto.
Because the order of vertices is not
list
ear
representation. We
between
subsequent
important
can even
calls to rec.test.
here
original
fore
we
the
we
lists before
use
running
a
lin¬
reordered
We construct the lists
hor\ and
we
also have to rebuild
returning. We also reuse the list through, there¬
returning. If we would copy those lists
0(n3) memory cells in the worst case without improving
have to rebuild it before
would
choose
are
hor0 by destroying the list hor. Because of this
the
we can
allow that the lists
time.
106
Chapter
4.3.4
Reducing
The Test for
4.
Transitivity
the Number of Zeros
The remark in section 4.3.3 indicates how to
algorithm. As
pointed
can determine a topological order of a
graph using algorithm 13. During this process we detect all graphs with
cycles which cannot be transitive. By sorting the adjacency lists of an
acyclic graph according to the topological order with algorithm 14 we
can arrange the adjacency matrix such that it is an
upper triangular
matrix with all zero elements below the diagonal. With such a special¬
ized adjacency matrix we can restrict the part of the matrix we consider
improve
our
out in section 4.3.2 we
at any
In
point
our
in the
algorithm.
rearranged adjacency
atk
and therefore
a
lot of
this reordered matrix
for paths
through
a
—
do not have to be considered at all. In
restrict the
vertex at
(4-9)
i < k
implies
1
positions
we can
matrix
position
in which
area
k. We
are
we
looking
have to look
for
pairs
of
positions
ajfc
and because of
=
1 and akj
1
(4.9)
i < k and
must hold. For this
area
=
reason an
index k
j
>
k
(4-10)
uniquely determines a rectangular
transitivity through the
restriction in algorithm 12 which
of S in which there may be violations of
vertex with index k. We
is based
on
algorithm
exploit
this
11.
The basic structure of the algorithm remains the same. We first
split the border lists, then we check the positions that must be one and
finally we call the procedure recursively.
However the
newly
structured matrix allows to
improve algorithm 11
possible middle vertices we
passing
the
be
used.
next
vertex
to
only pass
Only larger vertices have to be
considered because all adjacency lists are sorted according to the topo¬
logical order. To fully exploit the topological order we have to process
vertices accordingly and cannot choose them arbitrarily anymore. The
part of the result considered is given by hor x vert. This area is also
restricted by the third parameter k according to (4.10). In order to
in various ways. Instead of
a
list of
107
Simple Algorithms
4.3.
make full
of the
use
topological
order
start with vertex 1
we
parameter, the initial call therefore looks
as
fourth
as
follows
redrec_test(^, 0, V, 1, TRUE).
We still have to
positions
explain
in the result
of the calls.
This is most
the lowest recursion.
the last parameter. To
cover
all the relevant
have to extend the vertical range for
we
easily
some
k to the set verto of
by adding
procedure
done
The last parameter of
redrec.test is
a
purpose to indicate the lowest call. It is set at the
flag with the unique
beginning but will be false
call in line (21). Together
that all necessary
In line
than
or
reached
(12)
in all calls which
with line
positions
we remove
are
(26)
covered
by
through a recursive
calling sequence ensures
occur
this
some
call.
all the vertices from hor which
smaller
are
equal to k + 1. The column k + 2 is the smallest which
in subsequent calls. If the condition in line (9) is false
times in
a
row
can
be
several
there may be several vertices in hor which have to be
removed in this step.
Implementation
Algorithm
we
12 is closer to
implement
reuse
implementation
an
unchanged
as
from
than
input
to
we
we
do not have to
we
have to take
running
of k in
recursion,
algorithm
is
we
11.
Again,
do not
require
output. As in algorithm 11
hori,horo,verti
and
have to pay attention to the
be put back into
hor, but
position they get inserted. Similarly
verto- Because we only append k to verto
at which
care
care
at the tail of the
rest of the
(27) we
(12). They have to
rebuild hor in line
vertices removed in line
algorithm
linear lists and
the elements of hor and vert to form
vert0. When
The
Time
the sets hor and vert
the order to remain
we
Running
and
we
do not have to
straightforward
time of
algorithm
in the result
to
reverse
this
change.
The
implement.
12 in the worst
case
depends
on
the
zeros
as for algorithm
we have
designed the algorithm to reduce the number of zeros considered it will
generally perform better than algorithm 11. Since it is still possible to
have 0(n2) zeros in the result, the running time may still reach 0(n3)
though it will be much better on average.
number of
As with the
the average
our
case
11. However since
previous algorithm we have not been able
running time analytically. In Section 4.4.3
empirical results which look quite promising.
to
analyze
we
present
Chapter
108
Algorithm
if
The Test for
4.
Transitivity
redrecJ.est(A, vert, hor, k, lowest)
12
\hor\
=
0
\vert
or
=
0|
k >
or
n
then
TRUE;
return
fi
forall i G vert do
if a,k
else
1 then
=
append
append
i to
vert\\
i to verto;
fi
od
if
| vert11
forall
> 0 then
/ior do
j
if Ofcj
=
1 then
append
elsif i < k + 1 then
else
append
i to
i to
remove
Ziori;
i from
/ior;
Zioro;
fi
od
forall i S vert\ do
forall
j
if a8_,
e hor i do
=
0 then return
FALSE;
fi
od
od
if not
redrec_test(J4, vert\, horo,k
FALSE;
+
1, FALSE) then
return
fi
fi
if lowest then add A; to verto; fi
if
redrec_test(^4, verto, hor,
restore hor and
return
TRUE;
else return
fi
weri;
FALSE;
k
4-1, lowest) then
109
Empirical Analysis
4.4.
Empirical Analysis
4.4
General Issues
4.4.1
In addition to the issues
presented
in Section 3.5.1
we
face
some new
problems when analyzing the test for transitivity empirically. If we test
a random matrix for transitivity the results will be very optimistic be¬
cause all our algorithms stop once they find a violation of transitivity.
Because random matrices are usually not transitive, this can be deter¬
rapidly. We would therefore measure the preprocessing time
running time of the actual algorithm. The simplest algo¬
rithm would probably turn out to be fastest, because it performs least
preprocessing, but quickly finds one of many violations of transitivity
mined very
instead of the
in unrestricted random matrices.
If
we
test
sitive with
a
a
matrix for
to be transitive in the end.
measurements for transitive
perform
To
acyclic matrix,
matrices
dom
as
acyclic
would
are
lot of
a
we
prefer
to
perform
need random transitive
we
harder to obtain than unrestricted random
test it for
transitivity
and
only
a ran¬
the transitive
use
input for the actual experiment. Because only very few ran¬
matrices are actually transitive, this generation procedure
obviously
take several
only counting
longer than the actual experiment. It would
algorithm to generate a single input instance
running an experiment on random acyclic graphs and
take much
runs
which amounts to
of the
the "bad cases".
In order to
generate random transitive input matrices
matrix
we
compute its transitive closure which by definition is the
different
After
generating
a
random
sitive matrix with the least number of ones, that contains all the
original
matrices
ever
over
This
the
as
matrix. This does not
actually
every transitive matrix is its
it favors matrices which
restrict the
own
effi¬
acyclic
ciently
chose
a
approach.
more
we
of the
our
matrices.
truly unbiased generation procedure would generate
matrices. A
dom
reason
this kind of measurements
matrices which
input
it to be tran¬
usually expect
executed until it finds the matrix
For this
input
we
Therefore there will be
probability.
algorithm has to be
where the
cases
transitivity
reasonable
tran¬
ones
possible input
transitive closure.
How¬
generated by many original matrices
matrices generated by only one (e.g. transitively oriented trees).
slightly biased generation procedure should not be a problem for
more
are
qualitative parts of our study because
it does not
seem
to favor
Chapter
110
particular algorithm
any
Another aspect has
Transitivity
another.
over
more
The Test for
4.
direct influences
size of the
on our
simulations. For
matrix the number of
original
edges in the tran¬
threshold
behavior. Even if
increasingly sharp
the original random acyclic matrix has only 5% of all possible ones, the
transitive closure matrix will be almost complete. Also the number of
ones in the transitive matrix does not scale linearly with the number of
increasing
sitive closure shows
ones
in the
an
original random
For these
matrix.
precisely
multiplication using
proposed procedure.
That is, we cannot generally predict the expected number of ones in
a transitive matrix given the number of ones in the random acyclic
In order to get meaningful simulation results we generated
matrix.
random acyclic matrices with slowly increasing probability. By taking
as
cannot determine
reasons we
input matrix
an
for the boolean matrix
the transitive closure of these matrices
matrices which spans
We
sure
now run our
the values
we
a
at
distribution of transitive
input
not
evenly.
matrices and
technique
we can
transitive
input
matrix
in Section 3.5.5.
as
mea¬
To evaluate the behavior of
a
certain
percentage of
of the actual data. For
an
in
ones
example
we
are
1
algorithm for growing n. Using
provide meaningful analyses of algorithms which
a
sensitive to the number of
4.4.2
a
although
input matrices for which roughly 50% of the positions
select the
to describe the behavior of
are
get
for all of these
interested in.
algorithm for different input sizes
the input we can now use extracts
this
we
whole range of ones,
algorithms
are
as
the
matrices
we
Topological
certain
ones
in the
input.
Because
we
require
also cannot vary the distribution inside the
Order
Algorithm
performs quite well for our distribution of input matri¬
It shows
our analysis with the graphics in Figure 4.2.
the absolute running time of algorithm 10 in seconds drawn against the
number of ones in the matrix. For each size of the input matrices we
conducted 300 experiments. We generated the input data by construct¬
ing a random acyclic matrix and computing the transitive closure. The
probability of ones in the random acyclic matrix increased linearly from
0 to 0.05. As we can see in the graphic this resulted in a nonuniform
Algorithm
ces.
10
We start
distribution of the actual
rapidly
and many of the
input data.
input
The number of
ones
increases
matrices have close to the maximum
4.4.
111.
Empirical Analysis
50
40
e
I
30
E
10
0
800000
16e+06
2 4e+06
number of
Figure
4.2:
ones in
3 2e+06
4e+06
the input
Running time of algorithm
of ones in the input
10 normalized
by n2 for
in¬
creasing number
number of
In fact the number of
ones.
did not increase
monotonically,
number of
before
ones
The upper
We
clearly
x
we
ones
in the actual
sorted the data
input data
according to the
generating the plot.
curve was
ity checks in 3000
but
3000
generated using the running times of transitiv¬
matrices, the lower with 2000 x 2000 matrices.
that the
ones.
The two
slice of the data to get
running
time increases with
a growing num¬
similar, although they are
located at different running time levels. Because of this dependency on
the probability of ones in the actual input, we have to consider a small
can see
ber of
a
meaningful comparison of different input
In order to generate the
slices from
our
look pretty
curves
graphics
dataset to get
a
in
Figure
comparison for
4.3
a
we
sizes.
extracted 10%
similar percentage of
plotted three portions in the same graphic and the different
easily distinguished. However, on every level we find a be¬
haviour which is very close to an 0(n2) running time. This corresponds
to the expected running time of the transitive closure algorithm by
Goralcikova and Koubek as pointed out in [CS94]. The correspondence
is not surprising as algorithm 10 is closely related to the computation
of the transitive closure using said algorithm.
ones.
We
levels
are
Chapter
112
4.
The Test for
Transitivity
6e-06
1000
size
Figure
1500
2000
2500
3000
of the input matrix
Running time of algorithm 10 for increasing input size
n2.
Matrices have about 80%, 50% and 30% of the maxi¬
by
4.3:
normalized
of ones decreasing from top to bottom. (5% of
acyclic matrix did not produce more than 80% of
matrices for small cases.)
mal number
ones
in
the random
ones
in
transitive
Empirical Analysis
4.4.
Figure
In
4.3
we
also
see
113
that the
running
time increases with the
percentage of
This behaviour is consis¬
ones set in the input matrix.
input sizes, but we also see that the effect is by far not
as considerable as for the simple versions of the boolean matrix mul¬
tiplication. The Put-on-algorithm runs in 0(n3 p2), its running time
therefore depends heavily on the number of ones in the input. The test
of transitivity runs roughly in 0(n2), its running time varies only by
This factor is
a factor of about 2 depending on the number of ones.
almost independent of the size of the input matrix.
tent for all
Figure 4.3 closely we still find a slight increase in the
growing n. In fact the data corresponds more accu¬
rately to a running time of 0(n2 log(log(n))), but since the number of
datapoints for larger matrices decreases steadily (because of our nonlin¬
ear input distribution) it is not clear if this claim can be sustained for
larger n.
If
we
examine
coefficients with
4.4.3
Recursive
Algorithm
le+06
2e+06
number of
Figure
4.4:
ing number
Running
of ones in
time
of algorithm
the input.
3e+06
ones in
12
4e+06
input
for large
matrices and vary¬
114
Chapter
4.
The Test for
Transitivity
The input data for analyzing algorithm 12 was generated in the same
as in the previous section. Again we ran 300 experiments for each
way
input
size
matrices which
on
were
transitive closures of random
acyclic
matrices.
We start
analysis with the same kind of graphics as in the pre¬
Obviously algorithm 12 performs quite different from
our
vious section.
algorithm 10.
input matrix
It takes most time when there
are
very few
and takes less time for matrices with
more
ones
ones.
in the
This
behavior is somewhat
surprising: we expected to find the maximum
possible ones in a transitive matrix are
present. We have not been able to explain this finding satisfactorily.
Maybe our expectations where simply wrong, but it would also be pos¬
sible that this behavior is connected to our way of generating the input
running
data.
time if about 50% of all
Because
we
have to compute the transitive closure of
a
random
acyclic matrix before using the matrix as input we actually do not get
uniformly distributed random input data. However since we did not find
another efficient way to generate
one
of these
possibilities
is true
input data
or
we
could
not determine
if
if this is the actual behavior of the
algorithm.
7e-06
p=0 3
p=0.5
p=0 8
6e-06
1
I
4e-06
I
3e-06
i
!
i
i
$
•
2e-06
le-06
500
1000
1500
size or
Figure
4.5:
normalized
Running
by n2
time
of
2000
2500
3000
the matrix
the recursive
algorithm for
various
n
Empirical Analysis
4.4.
115
The graphics in Figure 4.5 shows the behavior of the running time
algorithm 12 for varying n. Again we chose to draw the normalized
running time to show the behavior of the algorithm for large n. While the
running time behaves a bit unpredictable up to a matrix size of about
1500, it seems to flatten for larger matrices. For the three probabilities
displayed in Figure 4.5 the algorithm meets the presumed n2 bound for
the distribution of inputs we provided. Again it becomes clear that the
running time decreases with an increasing number of ones in the input.
of
The distinction between the different
clear
in the
as
previous section, algorithm
to the number of
ones
in the
algorithm
some applications.
12 is the most
input
as
curves
in the
graphic
12 is therefore not
algorithm
10. The
predictable which may be
a
as
is not
as
sensitive
running
time of
desireable property
in
Comparing Algorithms
4.4.4
Chapter 3 we use a baseline algorithm to which we compare our
algorithms. For the test for transitivity we chose the transitive closure
algorithm by GORALCl'KOVA and Koubek as the baseline algorithm.
Algorithm 15 computes the transitive closure of an acyclic graph and it
is obvious how to derive a test for transitivity from this. The transitive
closure of a graph is the smallest transitive graph containing the input as
a subgraph. If it is equal to the graph itself then the graph is transitive.
To test a transitive matrix for transitivity we simply interpret it as the
adjacency matrix of a transitive graph, compute the transitive closure
As in
and compare it to the
input*.
The
of the
comparison step is
graphs we want to
according
avoid the
to the
same
linear in the number of vertices and
compare.
ordering and
We have to sort the
compare the lists if
comparison of adjacency matrices which takes
edges
edge lists
we
0(n2)
want to
time.
Algorithm 12 takes longer than algorithm 10, but the behavior of the
algorithms is quite different. While the running time of algorithm 10
increases with the number of ones in the input the running time of
algorithm 12 actually decreases. However, in both cases the curves are
flatter than for the simple algorithms we used for the boolean matrix
multiplication or for the transitive closure algorithm.
two
t
Actually it is enough to compare the number of edges as all edges
graph must be present in the transitive closure by definition.
from the
input
Chapter
116
4.
Transitivity
The Test for
45
recursive
algorithm
(oporder algorithm
40
transitive closure
35
30
25
20
15
10
5
0
number of
ones in
2e+06
1.5e+06
le+06
500000
the input
Comparative graphic displaying the running time of algo¬
for a matrix of size 2000 and varying number of ones
The
the input.
plot for the transitive closure is given for comparison.
Figure
4.6:
rithms 10 and 12
in
running times of the three algo¬
increasing number of ones. Obvi¬
ously the three algorithms have very different running time character¬
istics. For this comparison we used the natural input format of each
algorithm. Algorithms 10 and 12 mainly operate on matrices, and we
In
Figure
4.6
we
have drawn the
rithms for matrices of size 2000 and
provided matrices as input. The transitive closure algorithm operates
graphs and we provided transitive graphs as input. First we note
that the transitive closure algorithm takes almost no time to preprocess
while the other algorithms obviously need some 0(n2) preprocessing.
This advantage would decrease if the transitive closure algorithm had
on
to start from
matrix
a
as
input from which it had
to
compute the input
graph.
The
running time of the
transitive closure
algorithm,
comparison, grows almost linearly with the number of
transitive
graphs
this
approach
our
ones.
baseline for
For sparse
is therefore the fastest way to test for
transitivity.
ing
Algorithm
10 also
number of
ones
displays an increasing running time for an increas¬
input, although the effect is not as pronounced
in the
117
Empirical Analysis
4.4.
le-05
algorithm
toporder algorithm
recursive
9e-06
transitive
closure
8e-06
7e-06
11 Hi
6e-06
i
5e-06
4e-06
3e-06
(Mi
2e-06
le-06
0
1000
500
Figure 4.7: Running time of the
indicating average, minimum and
with about 20%
as
2000
1500
size
of the
2500
3000
matrix
three
normalized
algorithms
maximum time
for input
by n2,
matrices
ones.
algorithm. The difference between the mini¬
running time is less than a factor of 2. Therefore
for the transitive closure
mum
this
and the maximum
algorithm
more
ones
than
a
is faster than the transitive closure
quarter of all possible
at which
algorithm
trix size of 300 the
of ones, in the
it
in the
10 becomes faster
crossing
graphic
ones
occurs
if there
are
slowly
decreases. For
a ma¬
at almost half the maximum number
at less than
occurs
algorithm
input. The percentage of
one
third of all the
possible
edges.
running time which quickly increases
to a maximum for very few ones in the input, but decreases steadily
after this point. The running time even drops slightly below the running
time of algorithm 10 for large matrices. Again the percentage at which
this crossing occurs decreases for larger matrices. However, for small
matrices this crossing does not occur at all.
For
algorithm
12
we
observe
a
plots in Figure 4.7 show how the running times of the three
algorithms behave for increasing matrix sizes and 20% of the ones set
All three algorithms display an 0(n2) running
in the input matrix.
The
time.
For
a
low percentage of
ones
in the
input the
transitive closure
Chapter
118
4.
The Test for
Transitivity
le-05
transitive closure
9e-06
algorithm
toporder algorithm
recursive
8e-06
Hill
7e-06
6e-06
"!1
5e-06
I
i
1
4e-06
3e-06
2e-06
le-06
-
0
0
1000
500
1500
size
Figure 4.8: Running time of the
indicating average, minimum and
with about 70%
2000
2500
three
algorithms normalized by n2,
for input matrices
maximum time
ones.
algorithm proves to be best as suggested by Figure
changes considerably in Figure 4.8 where we have
times for
algorithm
input
3000
of the matrix
matrices with 70% of
takes much
ones
set.
4.7. This situation
drawn the
running
The transitive closure
algorithms 10
Algorithm 10 performs
best in this situation, although it seems that its running time increases
slightly faster than the running time of algorithm 12 and the curves
will cross eventually.
The difference however is not very large, but
algorithm 10 is probably the best overall algorithm we investigated in
this chapter.
and 12 take almost
The
larger
more
time for these
much time
as
actual number of
again
ones
of
that this
ones
algorithm
in the
the transitive closure
vertices due to memory constraints.
while
inputs
before.
variation of the transitive closure
4.7 and 4.8 indicates
only simulate
as
is
algorithm
more
input. Also
algorithm
in
note that
up to
Figures
sensitive to the
we
inputs with
could
2500
119
Empirical Analysis
4.4.
Additional Considerations
4.4.5
During our experiments with the
interesting observations which are
time of our algorithms. We briefly
Implementation
Our recursive
cases
this is
leaves
a
we
made
to the
some
running
summarize them in this section.
lot of
for
uncommon
implementation details unspec¬
algorithm descriptions. As in many
true for the data structures to be used.
especially
implemented
not
details
algorithm
ified which is not
transitivity
directly related
test for
We
using different data struc¬
tures for the sets vert and hor. One implementation used a singly linked
list with only a head-pointer, another used a doubly linked circular list
and the third used a singly linked list with head- and tail-pointer.
several versions of
algorithm
12
A single step of our recursion basically splits two lists, does some
tests, performs the recursive calls and concatenates the lists again. The
splitting
singly
faster
A
ting
simple iteration, all implementations should
The splitting operation as such favors the
list while the concatenation can be implemented much
doubly linked list or a list with tail-pointer.
uses
process
therefore be
equally
linked
using
a
a
fast.
splitting operation
an
element
for
from/into
a
doubly linked list requires deleting/inser¬
two circular chains which takes at least twice
many operations as the simple singly linked list case. To maintain the
tail-pointer correctly we only need to add an additional if-statement.
as
Doubly
linked circular lists
can
be concatenated
using
a
operations while for singly linked lists without tail pointer
few
pointer
at least one
If a tail-pointer is available,
as a whole.
implemented with few pointer operations.
of the lists must be traversed
this
operation
can
Considering
also be
these two forces the
singly linked list with tail-pointer
However, the actual implementation demon¬
strated that the running times hardly differ at all, at least if we guaran¬
tee that we always traverse the smaller list when concatenating simple
singly linked lists. We cannot apply the same principle for splitting
doubly linked lists because it is impossible to tell in advance which one
should be the clear winner.
of the two sets will be smaller.
As expected the
better than the
was
implementation using singly linked lists performed
using doubly linked lists. However the difference
than expected once both algorithms reached the same
one
much smaller
Chapter
120
level of
that it
optimization.
linked list
seems
operations
When
destroys
of
an
are
in
though
the
simple
once
the basic
one, then the
slower than the
effort should not be
singly
operations
singly linked list version
doubly linked list version.
the larger number of procedure calls,
much larger. In the doubly linked list
a new
version every element must
and in the
doubly
the
the data structure is harder to
operation for simple lists, which
concatenate
both lists to build
raw
turned out
place.
we use a
We attributed this behavior to
as
optimization process it
optimal program using
easier to choose the best
algorithm performs
our
Transitivity
almost
Even
representation.
maintain it
the
During
easier to write
was
The Test for
4.
now
be inserted into two chains in each step
linked version the concatenate
operation inserts each
element into another chain.
The
but
algorithms finally performed within a few percents of each other,
able to economize considerably more during the optimiza¬
we were
All three data structures
tion step.
hand and
been
they performed
more
investigate
specific property
"Improving"
light
similar
ply
gorithm,
of
of
our
our
one
to solve the task at
well. It would therefore have
data structure and
the alternative structures.
recursive
the baseline
findings
techniques
adequate
are
equally
economical to stick with
process than to
In the
almost
algorithm
and cannot be
this is
a
generalized.
algorithm
from Section 3.5.5 it
seems
improve the running time of
to
optimize the
However,
natural to ap¬
our
baseline al¬
Throughout the Goralcikova and
KOUBEK transitive closure algorithm we have to perform a lot of union
operations. Similar to the boolean matrix multiplication algorithms in
Section 3.3 we can optimize these unions by selecting one of two strate¬
gies.
the transitive closure.
Consider the union U
a
combined
e
if
e
lists
G U and 0
(for
we can
set S
if
we
perform
on
they
S
UUS and suppose
otherwise. The
need
only
ones
the list of
we
represent the
set U
by
The array contains 1 at
and
position
kept in two separate
Using this representation
zeros are
ones).
the union either
the array
are
<-
array-list representation.
or
by putting all the elements of the new
by checking for all the zeros (non-elements of U)
elements of S and add the
which strategy to
use
we
list of U to the number of
simply
ones
new
elements to U. To decide
compare the number of
in S. This
approach
zeros
in the
is feasible because
4.4.
121^
Empirical Analysis
300
checking zeros
optimized unions
original
250
transitive
closure
200
150
100
50
0
number of
2e+06
15e+06
le+06
500000
0
edges
Figure 4.9: Running time of the three variants of the transitive
algorithm for transitive input graphs with 2000 vertices.
the elements of U
possible
known in
are
and therefore
we can
closure
advance, only the values 1,...,
allocate
a
n
are
suitable array in advance.
to apply this approach
implemented two approaches
concentrating on different optimizations. First we developed a test for
transitivity which follows the lines of the transitive closure algorithm.
Instead of actually computing a union we can test if one of the zeros in
the original matrix would become one by the union we currently per¬
form. This would immediately prove that the graph is not transitive.
However, by not computing the actual union we may lose some of the
optimization built into algorithm 15. Because we only test this condi¬
tion for the zeros which would prove a violation of transitivity, we may
perform more unions than necessary.
However,
it
was
not
entirely straightforward
to the transitive closure
algorithm.
We
Second we computed the correct unions as pointed out by select¬
ing the faster strategy. However, we do not want to lose the excellent
running time of the transitive closure algorithm for sparse graphs. In
order to avoid an Q(n2) preprocessing time we have to make sure that
the list of zeros is only computed when necessary, that is only when
there
are
less
zeros
in the closure set than
ones
to
put
on.
With all
122
Chapter
these constraints and
the
running
new
time would
4.
The Test for
data structures it
was
actually improve using
Transitivity
not obvious whether
this
strategy.
In
Figure 4.9 we have drawn the running times of these approaches
for graphs with 2000 vertices. The results are quite disappointing, nei¬
ther the first nor the second strategy displays improved running time.
While the second algorithm is only slightly slower than the original the
first algorithm reaches the same running time if there are few edges,
but spends much more time for dense graphs. For this reason we stick
to the original version of the transitive closure as the baseline for com¬
parison. Obviously the optimizations which proved very effective for
boolean matrix multiplication fail to improve the running time of the
test for transitivity for transitive input graphs.
For such graphs the
result contains as many ones as the input and the number of zeros de¬
creases rather slowly. Even for our most dense graphs there still remain
more zeros than for the boolean matrix multiplication and we cannot
expect the same improvement in running time. Because we have to
introduce new data structures we can even explain why the running
time increases. By introducing these data structures later during the
algorithm (i.e. by optimizing less) the running time could probably be
improved by a small margin, but it seemed not worthy to investigate
this any further
as
the difference is
certainly
very small.
Chapter
5
Results and Outlook
In this thesis
Our
a simplified theory of transitive orientation.
possible through a combination of the theories
have shown
we
simplifications
were
of Golumbic and Spinrad. We showed that Spinrad's modules and
imply each other. Their combination
simplified concepts and allowed us to directly derive a 0(n2)
algorithm for transitive orientation.
Golumbic's implication classes
lead to
investigated algorithms for boolean matrix multipli¬
particular we were able to show that some simple algorithms
have excellent performance in the average case. We also investigated a
more complicated recursive algorithm which had a lot of promise be¬
cause it combines two simpler algorithms while simultaneously avoiding
the worst cases of either algorithm. However, an empirical comparison
revealed that these favorable properties come at a price. The algorithm
has a considerable setup cost and cannot compete with simpler com¬
We have then
cation. In
algorithms with more obvious worst cases. We compared our
algorithms empirically and provided some guidelines to evaluate algo¬
rithms for practical applications.
bination
In
an
practice
uneven
or
we
also face biased
not random-like distribution of
differently to such conditions.
algorithm is not influenced by the
react
input data, that
While
our
ones.
is matrices with
Our
optimized
algorithms
Four Russian
distribution of ones, but
by
their
number, the opposite is true for the combination algorithm.
This algorithm is quite sensitive to the distribution of ones, but it runs
equally fast on dense and on sparse input matrices. We modified our
absolute
123
Chapter
124
Results and Outlook
5.
input model in order to investigate this sensitivity. Our experiments
showed that, the combination algorithm still runs fast if there is at
least
randomness in the data.
some
The experiments also revealed that
For most kinds of
pessimistic.
ran
faster than
expected.
input
might
It
our
average
data
our
possible
be
case
results
to
improve
are
still
algorithm
analysis
combination
the
to reflect this.
In
Chapter
4
we
in the
standard solution involves
turn
can
(the latest
in [MS97])
approaches
we
do not know of
algorithms
the
to test for
as our
special
If
we
While there have
0(n2)
orientation faster than
an
a
test for
multiplication
input is structured such that
algorithms for
find
almost
our
rather
runs
faster
We found
case.
methods for boolean matrix
our
Therefore
boolean matrix
structure of the
would test
transitivity which
in the worst
we designed special
poorly.
These
algorithms apply similar con¬
transitivity.
multiplication perform
cepts
compute
multiplication.
of which is McConnell and Spinrad's linear time version
than the boolean matrix
that the
the transitive closure which in
computing
to
of
recognition
be reduced to boolean matrix
been several
transitivity. This is the
comparability graphs. The
the test for
investigated
expensive step
most
input
algorithms
violation of
multiplication,
but
they
take
into account.
on
random
input matrices
transitivity very fast.
we
would
We therefore
always
performed experiments on transitive inputs for which the algorithms
always have to be performed in full. This could be called an 'average
worst case' analysis. Still our experiments showed promising results, the
algorithms ran in 0(n2) most of the time. This is encouraging, even
though we have not been able to determine the average case running
a
mainly originates in the lack of a suitable
input model for random transitive graphs. Our approach, which was
based on the transitive closure of random acyclic graphs, quickly pro¬
duces transitive input graphs, however, we do not know much about the
resulting distribution of transitive graphs. A meaningful average case
analysis of the test for transitivity would require a well founded input
model for transitive graphs.
time
mathematically.
This
might also try to determine
comparability graph recognition. To
One
the average
do
so
case
random transitive orientations. We consider this to be
cult than
on
an
input
application.
the concrete
graphs
only make
model for transitive
It will
running
he would need
as
a
even more
it is bound to
sense
time of
model for
to
try
diffi¬
depend
to find
a
125
comparability graph if there is a reasonable probability to find one.
Comparability graphs hardly ever occur at random and therefore the
input distribution will not correspond to any of the standard models
for random graphs. This increases the difficulty to construct a model
of transitive orientations which corresponds to the application. How¬
be
ever, our empirical results suggest that comparability graphs can
recognized
in reasonable time in most
cases.
Appendix
A
An introduction to
graph
theory
A.l
Basics
graph G
(V, E) is an ordered tuple of
{ 1,..., n } the set of vertices and
A directed
call V
=
=
E C ®V
=f
V
V
x
-
{ (v, v) |
the set of
the
literature,
or
are
sometimes called
of
edges. In
points and edges
a
graph does
There
are
sometimes
loops
several kinds of
rely
G~l
not allow
or
vertices
v
are
two finite sets.
e V
We
}
sometimes called nodes
arcs or
lines. This definition
parallel edges.
graphs
we
can
derive of
a
graph
G. We
on
=
{V,E~l)
G
=
G
=
E-1
with
(V,E)
with
E
=
(V,E)
with
E
=
=
{(u,v)\(v,u)eE}
{(u,v)\ («,v) £ E}
E\jE-\
G_1 is called the reversal of G, G is the complement of G and G is
the
symmetric closure of G.
if the set E is
symmetric,
A
i.e.
graph G
if E
=
=
(V, E)
E~l
or
equivalently
Sometimes it is convenient to consider the edges of
as an
unordered set
{ u, v }
instead of two ordered
126
is called undirected
an
E
undirected
=
E.
graph
pairs (u, v), (v, u).
Graph Representations
A.2.
When
edges. A
lines for
from vertex
the
a
u
graph
a
to vertex
vertex
we
subgraph G'
use
points
of G
edges
=
to denote vertices and
by
is denoted
edges
leading
usually drop
an arrow
will
we
opposite directions.
in
adjacency
{v eV\(u,v)
=
(V, E')
=
two
define the
adj(u)
A
will
For undirected
v.
drawing
V
u
we
edge (u, v)
directed
instead of
arrow
For
draw
we
127
{V, E)
u as
E}.
e
is
set of
a
graph
for which V CV
andE' CEDV' xV.
For
the
set B C V
a
graph
define the induced
we
which has all the
edges
EB
For
a
set S C E
we
{v
|
V(S)
with
A
=
£ V
path of length k
=
between
subgraph Gb
(B,Eb)
vertices in B, that is
=
EDBx B.
spanned subgraph G(S)
endpoint of an edge in 5 }.
define the
is
v
is
a
a
path
=
(V(S), S)
sequence ult..., u* of vertices with
(ui,u2),(u2,u3),...,(un-1,un)
A circle is
as
ui,...,Uk
with ui
=
e E.
u^. We
usually
consider
circles in undirected graphs. If we use the term circle in a directed
graph we refer to the corresponding graph G. In a directed graph we
usually talk about cycles which is a circle with a direction associated to
every edge.
A.2
The
Graph Representations
algorithms
cency list
in this thesis either
representation of
a
use an
graph.
adjacency
In this section
matrix
we
or an
adja¬
introduce these
representations and briefly discuss their advantages and disadvantages.
A.2.1
We
V
=
use
Adjacency
annxn
{ 1,...,
n
fl
}
Matrix
boolean matrix A to store
vertices. To store the
<=>
(i,j)eE
edges
a
we
graph G
define
=
(V, E)
with
Appendix
128
This
representation
It
•
Directed and undirected
space
Edge insertion,
the number of
edges.
graphs can be represented; adjacency
graphs are symmetric, that is al}
a3l.
matrices of undirected
•
graph theory
follows:
as
regardless of
•
requires
An introduction to
be characterized
can
0(n2)
A.
=
deletion and
lookup
can
all be
performed
in time
0(1).
0(n)
•
It takes
•
It would be
•
time to traverse
possible
to
adj+(i).
represent loops by the entries al}
By allowing integers as entries we could extend the representa¬
tion to include parallel edges. However, to account for this fact
algorithms would
have to be modified.
Generally we prefer the adjacency matrix representation if we often
have to lookup adjacency or non-adjacency in a graph. If we often need
access to the adjacency set of a graph this representation is not well
suited.
For sparse
graphs
the
0(n2)
space
requirement
is sometimes
prohibitive.
A.2.2
Lists
Adjacency
V we store the list of vertices adjacent to u. De¬
u
pending on the operations we need for adj+(w) we can implement these
lists as singly or doubly linked dynamical or even as array based static
lists. The list £, corresponds to vertex i and an edge (i, j) £ E implies
For each vertex
j
6
t%. This representation
requires 0(n
m)
can
•
It
•
Directed and undirected
rected
or as
•
Edge
edge
graphs
+
can
be
be characterized
as
follows:
space.
graphs can be represented; edges in undi¬
represented as two entries in different lists
records present in two different lists.
insertion
is not
can
be
performed
in
present in E. Otherwise
a
O(l)
if it is know that the
lookup has
to be
performed
first.
•
Edge
deletion and
timeO(|adj+(i)|).
lookup of
an
edge (i,j)
can
be
performed
in
Basic
A.3.
Algorithms
•
An
•
It would be
adjacency
usually
The
even
adjacency
list
list
129
adj+(i)
can
0(|adj+(i)|).
be traversed in time
easily possible to model loops
modifying algorithms.
and
parallel edges,
without
representation
It is also
is
preferable
choice if
graphs
for sparse
need
to
con¬
to
mainly
An
of
class
adjacency
edges.
important
for
which
the
list
we
ex¬
are
algorithms
prefer
representation
adjacency
ploration algorithms, for example BFS, DFS, Minimal Spanning Tree
or Shortest Path algorithms.
serve
memory.
whole
If
a
good
we
lists and not individual
we
need
a
performs slowly,
0(n) edges.
A.3
adjacency
test for
except if
Basic
we
or non
adjacency this representation
graphs with no more than
have very sparse
Algorithms
appendix we present some basic graph algorithms
building blocks to describe algorithms.
In this
as
A.3.1
Topological
The topsort
G
=
access
contains
topological order,
a
we use
Sort
procedure in algorithm 13
(V, E)
which
cycle. If G
is
that is it generates
returns FALSE if the
acyclic
a
input graph
then topsort computes
mapping ord(a;)
:
V
->
a
N for
which
V(«, v)
If G is
an
topological
has
such order.
A.3.2
=>
ord(u)
<
arbitrary graph the topsort procedure
correct
no
G E
Sort
The
ord(v).
returns TRUE if ord is
order and FALSE if G contains
a
cycle
a
and therefore
Edges
sort.edges procedure in algorithm 14 reorders the adjacency lists of
graph G
(V, E) according to a function ord-1 (n) : {l,...,n} -*V.
The vertex ord- (1) must be put first, ord-1(n) last into the adjacency
lists in which they are present. The algorithm works by inverting the
a
graph
—
twice.
130
Appendix
Algorithm
(1)
(2)
(3)
(4)
(5)
(6)
(7)
(8)
(9)
(10)
(11)
(12)
(13)
(14)
(15)
(16)
(17)
(18)
(19)
(5)
(6)
(7)
(8)
(9)
(10)
graph theory
(v)
=
|adj (v)\
for all
v
£
V;
^<-l;
S
<r-{v£ V\f-(v) =0};
± 0
while S
choose
s
ord(s)
«-
forall
v
do
S
arbitrarily
and
£;
adj+(s)
G
do
y~(v) by 1;
0 then
7~(u)
5^5U{«};
reduce
if
=
fi
od
£+ 1;
<—
od
if I >
n
then
return
TRUE;
else
return
FALSE;
fi
14
for i
sort_edges(G, ord-1)
<—
1 to
n
do
ord_1(i);
forall
adj+(u)
v <-
u
append
v
to
do
adj'+(u);
od
adj+(u)
«-
0;
od
for i from 1 to
n
do
ord_1(i);
u e adj'+(u) do
append u to adj+(u);
v «-
forall
(11)
(12)
(13)
An introduction to
topsort(G)
13
compute 7
Algorithm
(1)
(2)
(3)
(4)
A.
od
od
remove
it from
5;
A.3.
A.3.3
In
15
we
Algorithm
input graph
trans.closure-procedure
G
=
returns the transitive
(V, E).
trans_closure(G)
15
for h
Algorithm
present the transitive closure algorithm by GORALCI-
and Koubek. The
closure of the
(1)
(2)
(3)
(4)
(5)
(6)
(7)
(8)
(9)
(10)
131
Transitive Closure
algorithm
kova
Algorithms
Basic
«— n
downto 1 do
adi*(h)<-{h};adjr(h)<-Qi
adj(/i)
ifj^adj'W
forall j
do
//
in
increasing
then
adj*(/i)^adj*(/i)Uadj*(j);
adjr(/»)<-adjr(JOu{j};
fl;
od;
od;
order
Appendix
B
Notation
B.l
G
Graph theory
{V, E)
=
A
of
(u, v)
graph consisting of a
edges E C ®V d= V
An
edge
is
a
A~l
The
=
(V, E~l)
A
G
The
V
meaning
{V, E)
reverse
of
reverse
of
a
set of
Gb
=
V(A)
{B,Eb)
v
set
}.
to be di¬
u
and
=
a
edges ACE;
{(x,y)\(y,x)eA}
graph.
The reflexive closure of
A
a
6 V
that it starts in
The reflexive closure of A: A
—
{ («, v) \
-
v.
A-1
G'1
x
pair of vertices, it is said
rected from utov,
ends in
set of vertices V and
graph
a
=
A\J A~x
graph.
is called undirected if G
The
graph
induced
with
EB
{ (u, v)
=
The set of vertices
V(A)
=
by
£ E
a
|
u,
v
e B
spanned by
{veV\3uV
132
=
G.
set of vertices B C V
}
A C E defined
:
(u,v)
A}
as
B.l.
Graph theory
A2
133
The square of
set of
a
edges, defined
{{x,z)\3yeV : (x,y)
adj+(u)
The set of outvertices of
adj+(u)
=
{w
The number of
adj_(v)
The set of invertices of
adj~(u)
A/\{y,z)e A}.
£
in
a
edges leaving
=
directed
V\3(v,w)
£
7+(^)
v
v
in
E}
directed
{u£ V\3(u,v)
The number of
edges entering
v;
adj(u)
The
set of
v
vertex
a
e
graph:
|adj+(w)|
v;
a
7~(v)
adjacency
graph
as
6
graph:
E}.
|adj~(^)j
e V in
an
undi¬
rected
adj*(u)
The
reflexive,
transitive closure of v, that is the
from the vertex
set of vertices reachable
G*
=
(V, E*)
The
reflexive, transitive closure
graph
G
=
Vv,w
Gr
=
(V, Er)
(V, E)
e
V
defined
(v,w)
:
£
of the directed
by
E*
<&w
adj*(t;)
The transitive reduction of the directed
G
=
(V,E)
the smallest
(Gr)*
adjr(v)
includ¬
v
the vertex itself.
ing
=
graph
subgraph of G with
possible number of edges such that
defined
as
a
G*.
The transitive reduction of
a
vertex
v
£
V,
that
is
adjr(u)
ord
:
V
->
V
A
=
{weV\(v,w)£Er}.
topological ordering, that
the vertices V
=
1,...,
n
Vv,wV:(v,w)eE
is
a
permutation
such that
=*>
ord(w)
<
ord(w).
of
Appendix
134
Notation
Probability Theory
B.2
Pr[X
B.
=
i\
The
probability
that
a
random variable X takes
value I.
E[X]
The
Var[X]
The variance of the random variable X.
expectation of the random variable
X.
Bibliography
[ADKF70]
Arlazarov, E. A. Dinic, M. A. Kronrod, and I. A.
Faradzev, On economical construction of the transitive closure
of an oriented graph, Soviet Math. Dokl 11 (1970), 1209-1210.
[Ard76]
V. L.
J.C.
Arditti, Graphes
dres,
l'Universite de
[ASE92] Noga Alon,
comparabilite
et dimension des
Montreal, 1976,
Joel H.
Spencer,
method,
Optimization, Wiley,
Mathematiques
or-
de
Note de recherches CRM 607.
and Paul
Erdos, The probabilis¬
Interscience Series in Discrete Mathematics and
tic
[BGK+95]
de
Tech. report, Centre de Recherches
1992.
Richard S.
Barr, Bruce L. Golden, James P Kelly, MauriResende, and William R. Stewart jr., Designing and
reporting on computational experiments with heuristic meth¬
ods, Journal of Heuristics 1 (1995), 9-32.
cio G.C.
[CGR94]
Cherkassky, Andrew V. Goldberg, and Tomasz
Radzik,
paths algorithms: Theory and experimental
evaluation, Proceedings of the Fifth ACM-SIAM Symposium
Boris
V.
Shortest
on
Discrete
phia, 1994,
[CLS81]
New York and Philadel¬
pp. 516-525.
D. G. Corneil, H. Lerchs,
plement reducible graphs,
(1981),
[CPS85]
Algorithms, ACM-SIAM,
and L. Stewart
Discrete
Burlingham, Com¬
Applied Mathematics 3
163-174.
D. G.
Corneil, Y. Perl, and L. K. Stewart, A linear recognition
algorithm for cographs, SIAM J. Comp. 14 (1985), 926-934.
135
Bibliography
136
[CS94]
Crippa
Davide
graphs:
Zurich, Dept.
[CW90]
and Klaus
Simon, q-distributions
Transitive closure and
of
Don
Coppersmith
tion
via
(1990),
reduction,
Computer Science,
and Shmuel
random
in
Tech. report, ETH
1994.
Winograd, Matrix multiplica¬
Symbolic Computation 9
arithmetic progressions, J.
251-280.
[DGT97]
P. Dell'Olmo, M. Grazia Speranza, and Zs. Tuza, Compara¬
bility graph augmentation for some multiprocessor scheduling
problems, Discrete Applied Mathematics 72 (1997), 71-84.
[Gal67]
Tibor
Gallai,
Acad. Sci.
[GH62]
A.
Graphen,
Transitiv onentierbare
Hungar.
18
(1967),
Ghouila-Houri, Caracterisation des graphes
dont
on
peut orienter les arets de
d'une relation
Acta Math.
25-66.
maniere a
d'ordre., C.R. Acad.
non
onentes
obtenir le
Sci. Paris 254
graphe
(1962),
1370-1371.
[GH64]
Paul C. Gilmore and Alan J.
comparability graphs
16
29
and
of
Hofman, A characterization of
interval
(1964), 539-548,
(A) (1962). MR31 #87.
abstract in Int
graphs,
Congr.
Canad. J. Math.
Math
(Stockholm),
[GKP89]
Ronald Lewis Graham, Donald Ervin Knuth, and Oren
Patashnik, Concrete mathematics, Addison-Wesley, 1989.
[Gol77a]
Martin Charles
matroid.,
[Gol77b]
Golumbic, Comparability graphs
Theory B 22 (1977), 68-90.
and
a
new
J. Combin.
Golumbic, The complexity of comparability
graph recognition and coloring., Computing 18 (1977), 199-
Martin Charles
208.
[Gol80]
[HM79]
Golumbic, Algorithmic graph theory and
Press, Inc., 1250 Sixth Avenue,
Diego California, 1980.
Martin Charles
per¬
fect graphs,
San
Academic
M. Habib and M. C.
for undirected graphs,
201-207.
Maurer, On the
Discrete
Applied
x-jom
decomposition
Mathematics 1
(1979),
137
[JK77]
Kotz, Urn models and their
Norman L. Johnson and Samuel
application, Wiley series in probability and mathematical
statistics, John Wiley & Sons, 1977.
[KSC78]
Valentin
Fedorovich
Kolchin,
Boris
Aleksandrovich
ast'yanov,
locations, Scripta
[McG96]
series in
Sev-
Random al¬
Chistyakov,
mathematics, Wiley, 1978.
and Vladimir Pavlovich
Catherine C. McGeoch, Toward
an
experimental method for
on Computing 8
algorithm simulation, INFORMS Journal
(1996),
[MS97]
1, 1-15.
no.
Ross M. McConnell and
Jeremy P. Spinrad, Linear-time
tran¬
orientation, Proceedings of the Eighth Annual ACMSIAM Symposium on Discrete Algorithms (New Orleans,
Louisiana), vol. 8, ACM/SIAM, January 1997, pp. 19-25.
sitive
[0073]
O'Neil, A fast expected-time algorithm
multiplication and transitive closure, Inf.
(1973), no. 2, 132-138.
P. E. O'Neil and E. J.
for
boolean matrix
Control 22
[Pan78]
Victor Y.
Pan, Strassen's algorithm is not optimal, Proc. 19th
Symp. Foundations of Computer Science, IEEE,
Ann. IEEE
1978, pp.166-176.
[PLE71]
A.
Pnueli,
graphs
23
[San81]
and
(1971),
Nicola
A.
Lempel, and S. Even,
Santoro,
0(n2) multiplication methods for sparse
matrices, Congressus Numerantium, vol. 31,
Four
1981, Proc. 10th Conf.
[Sch92]
C.
P.
ald
zur
[Spi82]
on
Numerical Mathematics and Com¬
pp. 241-251.
Schnorr,
and/or-product
60.
of
Can. J. Match
1, 160-175.
no.
and dense boolean
puting,
Transitive orientation
identification of permutation graphs,
Computation of
the
boolean matrix-vector,
o(m + nlnn), Festschrift zum
Geburtstag von Guenter Hotz (Johannes Buchmann, HarGanzinger, and Wolfgang J. Paul, eds.), Teubner-Texte
Informatik,
in average time
no.
1, B.G.Teubner, 1992, pp. 359-362.
Jeremy Paul Spinrad, Two dimensional partial orders, Ph.D.
thesis, Princeton University, October 1982.
138
[Spi85]
[Str69]
Bibliography
Jeremy
graphs,
V.
Paul
Spinrad,
Comp.
SIAM J.
Strassen, Gaussian
Mathematik 13
On
14
comparability and permutation
(1985),
658-670.
elimination is not
(1969),
354-356.
optimal,
Numerische
Curriculum vitae
Name:
Paul Trunz
Born:
28th of
Citizen:
Niederhelfenschwil
Education:
1974-1980
Primarschule
1980-1982
Sekundarschule
1982-1986
Kantonsschule
1986-1991
ETH
1991-1997
Teaching and research assistant for Com¬
puter Science, ETH Zurich
Experience:
May 1967
since 1997
(SG)
Degersheim
Degersheim
Wattwil, Matura Typ C
Zurich, Dipl. Informatik-Ing. ETH
Software
139
engineer
at IFA Informatik AG
© Copyright 2025 Paperzz