Академический Документы
Профессиональный Документы
Культура Документы
GRAPHS
Edge list
Adjacency lists
Adjacency matrix
E
NW 35
DL 247
BOS
AA 49
LAX
DFW
JFK
MIA
ORD
TW 45
SFO
35
BOS
ORD
A
LAX
DFW
AA 49
AA
47
DL 2
38
1
A
AA 903
UA
DL 33
SFO
0
2
1
UA 8
77
JFK
523
MIA
AA 411
Edge List
The edge list structure simply stores the vertices and
the edges into unsorted sequences.
Easy to implement.
Finding the edges incident on a given vertex is
inefficient since it requires examining the entire
edge sequence
E
NW 35
DL 247
BOS
AA 49
LAX
DFW
JFK
MIA
ORD
TW 45
SFO
Time
O(1)
O(1)
O(n)
O(m)
O(n+m)
O(1)
O(m)
O(1)
O(m)
Adjacency List
(traditional)
adjacency list of a vertex v:
sequence of vertices adjacent to v
represent the graph by the adjacency lists of all the
vertices
a
b
c
e
d
a
Space = (N +
deg(v)) = (N + M)
Adjacency List
(modern)
The adjacency list structure extends the edge list
structure by adding incidence containers to each
vertex.
NW 35
DL 247
BOS
in
out
AA 49
LAX
DFW
JFK
in
in
in
out
out
out
MIA
in
out
ORD
in
out
NW 35
AA 49 UA 120
AA1387 DL335
NW 35 AA1387
DL 247 AA523
UA 120 UA 877
DL 247
AA 411
UA 877 AA 49
AA 903
AA 903 AA 411
DL 335
AA 523
TW 45
TW 45
SFO
in
out
TW 45
Time
O(1)
O(1)
O(n)
O(m)
O(n+m)
O(1)
O(deg(v))
O(min(deg(u),
deg(v)))
insertVertex, insertEdge, insertDirected- O(1)
Edge, removeEdge, makeUndirected,
reverseDirection,
removeVertex(v)
O(deg(v))
Data Structures for Graphs
Adjacency Matrix
(traditional)
a
b
a
b
c
d
e
c
d
F
T
T
T
F
T
F
F
F
T
T
F
F
T
T
T
F
T
F
T
F
T
T
T
F
Adjacency Matrix
(modern)
The adjacency matrix structures augments the edge
list structure with a matrix where each row and
column corresponds to a vertex.
0
NW
35
DL
247
AA
49
DL
335
AA
1387
AA
903
TW
45
UA
120
AA
523
AA
411
UA
877
Time
O(1)
O(1)
O(n)
O(m)
O(n+m)
O(1)
O(n)
O(1)
O(1)
O(n2)
10