<s>
In	O
graph	O
theory	O
and	O
computer	B-General_Concept
science	I-General_Concept
,	O
an	O
adjacency	B-Algorithm
matrix	I-Algorithm
is	O
a	O
square	B-Algorithm
matrix	I-Algorithm
used	O
to	O
represent	O
a	O
finite	O
graph	O
.	O
</s>
<s>
The	O
elements	O
of	O
the	O
matrix	B-Architecture
indicate	O
whether	O
pairs	O
of	O
vertices	O
are	O
adjacent	O
or	O
not	O
in	O
the	O
graph	O
.	O
</s>
<s>
In	O
the	O
special	O
case	O
of	O
a	O
finite	O
simple	O
graph	O
,	O
the	O
adjacency	B-Algorithm
matrix	I-Algorithm
is	O
a	O
(	O
0	O
,	O
1	O
)	O
-matrix	O
with	O
zeros	O
on	O
its	O
diagonal	O
.	O
</s>
<s>
all	O
of	O
its	O
edges	O
are	O
bidirectional	O
)	O
,	O
the	O
adjacency	B-Algorithm
matrix	I-Algorithm
is	O
symmetric	B-Algorithm
.	O
</s>
<s>
The	O
relationship	O
between	O
a	O
graph	O
and	O
the	O
eigenvalues	O
and	O
eigenvectors	O
of	O
its	O
adjacency	B-Algorithm
matrix	I-Algorithm
is	O
studied	O
in	O
spectral	O
graph	O
theory	O
.	O
</s>
<s>
The	O
adjacency	B-Algorithm
matrix	I-Algorithm
of	O
a	O
graph	O
should	O
be	O
distinguished	O
from	O
its	O
incidence	B-Algorithm
matrix	I-Algorithm
,	O
a	O
different	O
matrix	B-Algorithm
representation	I-Algorithm
whose	O
elements	O
indicate	O
whether	O
vertex	O
–	O
edge	O
pairs	O
are	O
incident	O
or	O
not	O
,	O
and	O
its	O
degree	B-Algorithm
matrix	I-Algorithm
,	O
which	O
contains	O
information	O
about	O
the	O
degree	O
of	O
each	O
vertex	O
.	O
</s>
<s>
For	O
a	O
simple	O
graph	O
with	O
vertex	O
set	O
,	O
the	O
adjacency	B-Algorithm
matrix	I-Algorithm
is	O
a	O
square	O
matrix	B-Architecture
such	O
that	O
its	O
element	O
is	O
one	O
when	O
there	O
is	O
an	O
edge	O
from	O
vertex	O
to	O
vertex	O
,	O
and	O
zero	O
when	O
there	O
is	O
no	O
edge	O
.	O
</s>
<s>
The	O
diagonal	O
elements	O
of	O
the	O
matrix	B-Architecture
are	O
all	O
zero	O
,	O
since	O
edges	O
from	O
a	O
vertex	O
to	O
itself	O
(	O
loops	O
)	O
are	O
not	O
allowed	O
in	O
simple	O
graphs	O
.	O
</s>
<s>
The	O
same	O
concept	O
can	O
be	O
extended	O
to	O
multigraphs	B-Language
and	O
graphs	O
with	O
loops	O
by	O
storing	O
the	O
number	O
of	O
edges	O
between	O
each	O
two	O
vertices	O
in	O
the	O
corresponding	O
matrix	B-Architecture
element	O
,	O
and	O
by	O
allowing	O
nonzero	O
diagonal	O
elements	O
.	O
</s>
<s>
where	O
is	O
an	O
matrix	B-Architecture
,	O
and	O
and	O
represent	O
the	O
and	O
zero	B-Algorithm
matrices	I-Algorithm
.	O
</s>
<s>
In	O
this	O
case	O
,	O
the	O
smaller	O
matrix	B-Architecture
uniquely	O
represents	O
the	O
graph	O
,	O
and	O
the	O
remaining	O
parts	O
of	O
can	O
be	O
discarded	O
as	O
redundant	O
.	O
</s>
<s>
is	O
sometimes	O
called	O
the	O
biadjacency	O
matrix	B-Architecture
.	O
</s>
<s>
The	O
biadjacency	O
matrix	B-Architecture
is	O
the	O
0	O
–	O
1	O
matrix	B-Architecture
in	O
which	O
if	O
and	O
only	O
if	O
.	O
</s>
<s>
If	O
is	O
a	O
bipartite	O
multigraph	B-Language
or	O
weighted	O
graph	O
,	O
then	O
the	O
elements	O
are	O
taken	O
to	O
be	O
the	O
number	O
of	O
edges	O
between	O
the	O
vertices	O
or	O
the	O
weight	O
of	O
the	O
edge	O
,	O
respectively	O
.	O
</s>
<s>
The	O
Seidel	O
adjacency	B-Algorithm
matrix	I-Algorithm
is	O
a	O
-adjacency	O
matrix	O
.	O
</s>
<s>
This	O
matrix	B-Architecture
is	O
used	O
in	O
studying	O
strongly	O
regular	O
graphs	O
and	O
two-graphs	O
.	O
</s>
<s>
The	O
distance	O
matrix	B-Architecture
has	O
in	O
position	O
the	O
distance	O
between	O
vertices	O
and	O
.	O
</s>
<s>
The	O
distance	O
matrix	B-Architecture
resembles	O
a	O
high	O
power	O
of	O
the	O
adjacency	B-Algorithm
matrix	I-Algorithm
,	O
but	O
instead	O
of	O
telling	O
only	O
whether	O
or	O
not	O
two	O
vertices	O
are	O
connected	O
(	O
i.e.	O
,	O
the	O
connection	O
matrix	B-Architecture
,	O
which	O
contains	O
boolean	O
values	O
)	O
,	O
it	O
gives	O
the	O
exact	O
distance	O
between	O
them	O
.	O
</s>
<s>
The	O
convention	O
followed	O
here	O
(	O
for	O
undirected	O
graphs	O
)	O
is	O
that	O
each	O
edge	O
adds	O
1	O
to	O
the	O
appropriate	O
cell	O
in	O
the	O
matrix	B-Architecture
,	O
and	O
each	O
loop	O
adds	O
2	O
.	O
</s>
<s>
This	O
allows	O
the	O
degree	O
of	O
a	O
vertex	O
to	O
be	O
easily	O
found	O
by	O
taking	O
the	O
sum	O
of	O
the	O
values	O
in	O
either	O
its	O
respective	O
row	O
or	O
column	O
in	O
the	O
adjacency	B-Algorithm
matrix	I-Algorithm
.	O
</s>
<s>
The	O
adjacency	B-Algorithm
matrix	I-Algorithm
of	O
a	O
directed	O
graph	O
can	O
be	O
asymmetric	O
.	O
</s>
<s>
As	O
the	O
graph	O
is	O
directed	O
,	O
the	O
matrix	B-Architecture
is	O
not	O
necessarily	O
symmetric	B-Algorithm
.	O
</s>
<s>
The	O
adjacency	B-Algorithm
matrix	I-Algorithm
of	O
a	O
complete	O
graph	O
contains	O
all	O
ones	O
except	O
along	O
the	O
diagonal	O
where	O
there	O
are	O
only	O
zeros	O
.	O
</s>
<s>
The	O
adjacency	B-Algorithm
matrix	I-Algorithm
of	O
an	O
empty	O
graph	O
is	O
a	O
zero	B-Algorithm
matrix	I-Algorithm
.	O
</s>
<s>
The	O
adjacency	B-Algorithm
matrix	I-Algorithm
of	O
an	O
undirected	O
simple	O
graph	O
is	O
symmetric	B-Algorithm
,	O
and	O
therefore	O
has	O
a	O
complete	O
set	O
of	O
real	O
eigenvalues	O
and	O
an	O
orthogonal	O
eigenvector	O
basis	O
.	O
</s>
<s>
In	O
particular	O
,	O
and	O
are	O
similar	B-Algorithm
and	O
therefore	O
have	O
the	O
same	O
minimal	O
polynomial	O
,	O
characteristic	O
polynomial	O
,	O
eigenvalues	O
,	O
determinant	O
and	O
trace	O
.	O
</s>
<s>
Such	O
linear	B-Architecture
operators	I-Architecture
are	O
said	O
to	O
be	O
isospectral	O
.	O
</s>
<s>
If	O
is	O
the	O
adjacency	B-Algorithm
matrix	I-Algorithm
of	O
the	O
directed	O
or	O
undirected	O
graph	O
,	O
then	O
the	O
matrix	B-Architecture
(	O
i.e.	O
,	O
the	O
matrix	B-Architecture
product	O
of	O
copies	O
of	O
)	O
has	O
an	O
interesting	O
interpretation	O
:	O
the	O
element	O
gives	O
the	O
number	O
of	O
(	O
directed	O
or	O
undirected	O
)	O
walks	O
of	O
length	O
from	O
vertex	O
to	O
vertex	O
.	O
</s>
<s>
The	O
adjacency	B-Algorithm
matrix	I-Algorithm
can	O
be	O
used	O
to	O
determine	O
whether	O
or	O
not	O
the	O
graph	O
is	O
connected	O
.	O
</s>
<s>
The	O
adjacency	B-Algorithm
matrix	I-Algorithm
may	O
be	O
used	O
as	O
a	O
data	B-General_Concept
structure	I-General_Concept
for	O
the	O
representation	B-Application
of	I-Application
graphs	I-Application
in	O
computer	O
programs	O
for	O
manipulating	O
graphs	O
.	O
</s>
<s>
The	O
main	O
alternative	O
data	B-General_Concept
structure	I-General_Concept
,	O
also	O
in	O
use	O
for	O
this	O
application	O
,	O
is	O
the	O
adjacency	B-Data_Structure
list	I-Data_Structure
.	O
</s>
<s>
The	O
space	O
needed	O
to	O
represent	O
an	O
adjacency	B-Algorithm
matrix	I-Algorithm
and	O
the	O
time	O
needed	O
to	O
perform	O
operations	O
on	O
them	O
is	O
dependent	O
on	O
the	O
matrix	B-Algorithm
representation	I-Algorithm
chosen	O
for	O
the	O
underlying	O
matrix	B-Architecture
.	O
</s>
<s>
Sparse	B-Algorithm
matrix	I-Algorithm
representations	I-Algorithm
only	O
store	O
non-zero	O
matrix	O
entries	O
and	O
implicitly	O
represents	O
the	O
zero	O
entries	O
.	O
</s>
<s>
They	O
can	O
for	O
example	O
be	O
used	O
to	O
represent	O
sparse	O
graphs	O
without	O
incurring	O
the	O
space	O
overhead	O
from	O
storing	O
the	O
many	O
zero	O
entries	O
in	O
the	O
adjacency	B-Algorithm
matrix	I-Algorithm
of	O
the	O
sparse	O
graph	O
.	O
</s>
<s>
In	O
the	O
following	O
section	O
the	O
adjacency	B-Algorithm
matrix	I-Algorithm
is	O
assumed	O
to	O
be	O
represented	O
by	O
an	O
array	B-Data_Structure
data	I-Data_Structure
structure	I-Data_Structure
so	O
that	O
zero	O
and	O
non-zero	O
entries	O
in	O
a	O
matrix	B-Architecture
are	O
all	O
directly	O
represented	O
in	O
storage	O
.	O
</s>
<s>
Because	O
each	O
entry	O
in	O
the	O
adjacency	B-Algorithm
matrix	I-Algorithm
requires	O
only	O
one	O
bit	O
,	O
it	O
can	O
be	O
represented	O
in	O
a	O
very	O
compact	O
way	O
,	O
occupying	O
only	O
|V|2	O
/	O
8	O
bytes	O
to	O
represent	O
a	O
directed	O
graph	O
,	O
or	O
(	O
by	O
using	O
a	O
packed	O
triangular	O
format	O
and	O
only	O
storing	O
the	O
lower	O
triangular	O
part	O
of	O
the	O
matrix	B-Architecture
)	O
approximately	O
|V|2	O
/	O
16	O
bytes	O
to	O
represent	O
an	O
undirected	O
graph	O
.	O
</s>
<s>
For	O
storing	O
graphs	O
in	O
text	B-General_Concept
files	I-General_Concept
,	O
fewer	O
bits	O
per	O
byte	O
can	O
be	O
used	O
to	O
ensure	O
that	O
all	O
bytes	O
are	O
text	O
characters	O
,	O
for	O
instance	O
by	O
using	O
a	O
Base64	B-Protocol
representation	O
.	O
</s>
<s>
Besides	O
avoiding	O
wasted	O
space	O
,	O
this	O
compactness	O
encourages	O
locality	B-General_Concept
of	I-General_Concept
reference	I-General_Concept
.	O
</s>
<s>
However	O
,	O
for	O
a	O
large	O
sparse	O
graph	O
,	O
adjacency	B-Data_Structure
lists	I-Data_Structure
require	O
less	O
storage	O
space	O
,	O
because	O
they	O
do	O
not	O
waste	O
any	O
space	O
to	O
represent	O
edges	O
that	O
are	O
not	O
present	O
.	O
</s>
<s>
An	O
alternative	O
form	O
of	O
adjacency	B-Algorithm
matrix	I-Algorithm
(	O
which	O
,	O
however	O
,	O
requires	O
a	O
larger	O
amount	O
of	O
space	O
)	O
replaces	O
the	O
numbers	O
in	O
each	O
element	O
of	O
the	O
matrix	B-Architecture
with	O
pointers	O
to	O
edge	O
objects	O
(	O
when	O
edges	O
are	O
present	O
)	O
or	O
null	O
pointers	O
(	O
when	O
there	O
is	O
no	O
edge	O
)	O
.	O
</s>
<s>
It	O
is	O
also	O
possible	O
to	O
store	O
edge	O
weights	O
directly	O
in	O
the	O
elements	O
of	O
an	O
adjacency	B-Algorithm
matrix	I-Algorithm
.	O
</s>
<s>
Besides	O
the	O
space	O
tradeoff	O
,	O
the	O
different	O
data	B-General_Concept
structures	I-General_Concept
also	O
facilitate	O
different	O
operations	O
.	O
</s>
<s>
Finding	O
all	O
vertices	O
adjacent	O
to	O
a	O
given	O
vertex	O
in	O
an	O
adjacency	B-Data_Structure
list	I-Data_Structure
is	O
as	O
simple	O
as	O
reading	O
the	O
list	O
,	O
and	O
takes	O
time	O
proportional	O
to	O
the	O
number	O
of	O
neighbors	O
.	O
</s>
<s>
With	O
an	O
adjacency	B-Algorithm
matrix	I-Algorithm
,	O
an	O
entire	O
row	O
must	O
instead	O
be	O
scanned	O
,	O
which	O
takes	O
a	O
larger	O
amount	O
of	O
time	O
,	O
proportional	O
to	O
the	O
number	O
of	O
vertices	O
in	O
the	O
whole	O
graph	O
.	O
</s>
<s>
On	O
the	O
other	O
hand	O
,	O
testing	O
whether	O
there	O
is	O
an	O
edge	O
between	O
two	O
given	O
vertices	O
can	O
be	O
determined	O
at	O
once	O
with	O
an	O
adjacency	B-Algorithm
matrix	I-Algorithm
,	O
while	O
requiring	O
time	O
proportional	O
to	O
the	O
minimum	O
degree	O
of	O
the	O
two	O
vertices	O
with	O
the	O
adjacency	B-Data_Structure
list	I-Data_Structure
.	O
</s>
