Professional Documents
Culture Documents
CSE 373
Data Structures
What are graphs?
• Yes, this is a graph….
edge
326
415 142
410 370
341
413 417
378
421
Nodes = courses
Directed edge = prerequisite 401
S
S
E
E
Nodes = rooms
Edge = door or passage
x1=q+y*z + -
x2=y*z-q
Naive:
q * * q
x1 x2
common
subexpression + -
eliminated:
q * q
Nodes = symbols/operators y z
Edges = relationships
11/26/20 CSE 373 AU 05 -- Graph Terminol 11
ogy
Precedence
S1 a=0;
6
S2 b=1;
S3 c=a+1
5
S4 d=b+a;
S5 e=d+1;
S6 e=c+d;
Nodes = statements
Edges = precedence requirements 1 2
L.A.
Sydney Nodes = computers
Edges = transmission rates
11/26/20 CSE 373 AU 05 -- Graph Terminol 13
ogy
The Internet
UW
Nodes = cities
Edges = # vehicles on
connecting highway
Football
Player
CSE
Nerd
K_5 K_3,3
11/26/20 CSE 373 AU 05 -- Graph Terminol 23
ogy
Sparsely Connected Graph
• n vertices
• worst n/2 edges between two vertices
• n edges total
000 010
100 110
11/26/20 CSE 373 AU 05 -- Graph Terminol 26
ogy
In Between (Hypercube)
1010 1110
- 16 nodes
- worst 4 edges
1011 1111 btwn two nodes
-32 total edges
0010
0110 S: (16,8,16)
0111
D: (16,1,120)
0011
0100 S: (32,16,32)
0000
1000 1100 H: (32,5,80)
D: (32,1,496)
0001 0101
S: (64,32,64)
H: (64,6,192)
1001 D: (64,1,2016)
1101
11/26/20 CSE 373 AU 05 -- Graph Terminol 27
ogy
Statistical Mechanics
B
C
A
F
D E
11/26/20 CSE 373 AU 05 -- Graph Terminol 34
ogy
Directed vs Undirected
Graphs
• If the order of edge pairs (v1, v2) matters, the graph is
directed (also called a digraph): (v1, v2) (v2, v1)
v1 v2
• If the order of edge pairs (v1, v2) does not matter, the
graph is called an undirected graph: in this case, (v1,
v2) = (v2, v1)
v1 v2
A
F
D E Degree = 0
Degree = 3
B
C
A
F
D E In-degree = 0
In-degree = 2 Out-degree = 0
Out-degree = 1
1 if [v, w] is in E
E 0 0 1 1 0 0
M(v, w) =
0 otherwise F 0 0 0 0 0 0
Space = |V|2
11/26/20 CSE 373 AU 05 -- Graph Terminol 42
ogy
Adjacency Matrix for a
Digraph
A B C D E F
B
C A 0 1 0 1 0 0
A
B 0 0 1 0 0 0
F
C 0 0 0 1 1 0
D E
D 0 0 0 0 1 0
1 if (v, w) is in E
E 0 0 0 0 0 0
M(v, w) =
0 otherwise F 0 0 0 0 0 0
Space = |V|2
11/26/20 CSE 373 AU 05 -- Graph Terminol 43
ogy
Adjacency List
For each v in V, L(v) = list of w such that [v, w] is in E
a b
A B list of
B D
neighbors
C
A B A C
F C B D E
D E D A C E
E C D
F
Space = a |V| + 2 b |E|
11/26/20 CSE 373 AU 05 -- Graph Terminol 44
ogy
Adjacency List for a Digraph
For each v in V, L(v) = list of w such that (v, w) is in
E a b
B A B D
C B
A C
F C D E
D E D E
E
A is a source
E is a sink F
F is disconnected from the rest Space = a |V| + b |E|
11/26/20 CSE 373 AU 05 -- Graph Terminol 45
ogy