Graph Terminology: CSE 373 Data Structures
Graph Terminology: CSE 373 Data Structures
CSE 373
Data Structures
Reading
Reading Chapter 13
Sections 13.1 and 13.2
Graph Terminology
Graphs
Graphs are composed of
Nodes (vertices)
Edges (arcs)
node
edge
Graph Terminology
Varieties
Nodes
Labeled or unlabeled
Edges
Directed or undirected
Labeled or unlabeled
Graph Terminology
node
Value Next
node
Value Next
94
97
10
a
96
d
Graph Terminology
99
b
6
Graph Terminology
Representing a Maze
S
S
B
E
E
Nodes = cells
Edges = door or passage
Graph Terminology
143
321
326
142
370
341
378
Nodes = courses
Directed edge = prerequisite
Graph Terminology
421
401
9
Representing Electrical
Circuits
Battery
Switch
Resistor
10
Program statements
x1=q+y*z
x2=y*z-q
Naive:
x1
x2
Nodes = symbols/operators
Edges = relationships
Graph Terminology
*
z
x1
x2
*
y
q
z
11
Precedence
S1
S2
S3
S4
S5
S6
a=0;
b=1;
c=a+1
d=b+a;
e=d+1;
e=c+d;
Nodes = statements
Edges = precedence requirements
Graph Terminology
2
12
Information Transmission in a
Computer Network
56
Tokyo
Seattle
Seoul
128
16
New York
181
30
140
L.A.
Sydney
Nodes = computers
Edges = transmission rates
Graph Terminology
13
UW
Nodes = cities
Edges = # vehicles on
connecting highway
Graph Terminology
14
The Internet
Graph Terminology
15
Isomorphism
Same number of vertices connected in the same way
16
Bipartite Graphs
Melrose Place
Football
Player
CSE
Nerd
Two disjoint
sets of
vertices.
Edges link a
vertex from
one set to a
vertex in the
other set
Graph Terminology
17
Planarity
Can the circuit be put onto the chip in one layer?
Graph Terminology
18
Two problems:
1) Can you draw these without lifting your pen,
drawing each line only once
2) Can you start and end at the same point.
Graph Terminology
19
Graph Terminology
20
Graph Terminology
21
In Between (Hypercube)
n vertices
log n edges between two vertices
101
n log n edges total
001
000
Graph Terminology
100
111
011
010
110
22
In Between (Hypercube)
1110
- 16 nodes
- 4 edges
btwn two nodes
1111
-32 total edges
1010
1011
0010
0111
0110
S: (16,8,16)
D: (16,1,120)
0011
0000
1100 H: (32,5,80)
1000
0001
S: (32,16,32)
0100
D: (32,1,496)
0101
S: (64,32,64)
H: (64,6,192)
1001
Graph Terminology
1101
D: (64,1,2016)
23
Neural Networks
Graph Terminology
24
Colorings
Graph Terminology
25
26
We should mention that both our programs use only integer arithmetic, and
so we need not be concerned with round-off errors and similar dangers of
floating point arithmetic. However, an argument can be made that our proof
is not a proof in the traditional sense, because it contains steps that can
never be verified by humans. In particular, we have not proved the
correctness of the compiler we compiled our programs on, nor have we
proved the infallibility of the hardware we ran our programs on. These have to
be taken on faith, and are conceivably a source of error. However, from a
practical point of view, the chance of a computer error that appears
consistently in exactly the same way on all runs of our programs on all the
compilers under all the operating systems that our programs run on is
infinitesimally small compared to the chance of a human error during the
same amount of case-checking. Apart from this hypothetical possibility of a
computer consistently giving an incorrect answer, the rest of our proof can be
verified in the same way as traditional mathematical proofs. We concede,
however, that verifying a computer program is much more difficult than
checking a mathematical proof of the same length.
Graph Terminology
27
Graph Definition
A graph is a collection of nodes plus edges
Linked lists, trees, and heaps are all special cases
of graphs
28
Graph Example
Here is a graph G = (V, E)
Each edge is a pair (v1, v2), where v1, v2 are vertices
in V
V = {A, B, C, D, E, F}
E = {(A,B), (A,D), (B,C), (C,D), (C,E), (D,E)}
B
C
A
F
D
E
Graph Terminology
29
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
Graph Terminology
30
Undirected Terminology
Two vertices u and v are adjacent in an
undirected graph G if {u,v} is an edge in G
edge e = {u,v} is incident with vertex u and vertex
v
Graph Terminology
31
Undirected Terminology
B is adjacent to C and C is adjacent to B
(A,B) is incident
to A and to B
B
C
Self-loop
A
F
D
Degree = 0
Degree = 3
Graph Terminology
32
Directed Terminology
Vertex u is adjacent to vertex v in a directed
graph G if (u,v) is an edge in G
vertex u is the initial vertex of (u,v)
Degree
in-degree is the number of edges with the vertex
as the terminal vertex
out-degree is the number of edges with the vertex
as the initial vertex
Graph Terminology
33
Directed Terminology
B adjacent to C and C adjacent from B
B
C
A
F
D
In-degree = 2
Out-degree = 1
Graph Terminology
In-degree = 0
Out-degree = 0
34
Handshaking Theorem
Let G=(V,E) be an undirected graph with
|E|=e edges
Then 2e = deg(v)
vV
Every edge contributes +1 to the degree of
each of the two vertices it is incident with
number of edges is exactly half the sum of deg(v)
the sum of the deg(v) values must be even
Graph Terminology
35
Handshaking Theorem II
For a directed graph:
v in G
v in g
Graph Terminology
36
Graph ADT
Nothing unexpected
What is interesting
How to represent graphs in memory
What representation to use for what algorithms
Graph Terminology
37
Graph Representations
Space and time are analyzed in terms of:
Number of vertices = |V| and
Number of edges = |E|
There are at least two ways of representing
graphs:
The adjacency matrix representation
The adjacency list representation
Graph Terminology
38
Adjacency Matrix
B
C
F
D
E
1 if (v, w) is in E
M(v, w) =
0 otherwise
Space = |V|2
Graph Terminology
39
F
D
E
1 if (v, w) is in E
M(v, w) =
0 otherwise
Space = |V|2
Graph Terminology
40
Adjacency List
For each v in V, L(v) = list of w such that (v, w) is in E
a
b
B
C
F
D
F
Graph Terminology
F
D
E
F
Graph Terminology