GraphTerminology(how graphs are used in discrete maths)

ahmadd8572 14 views 45 slides Jun 25, 2024
Slide 1
Slide 1 of 45
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11
Slide 12
12
Slide 13
13
Slide 14
14
Slide 15
15
Slide 16
16
Slide 17
17
Slide 18
18
Slide 19
19
Slide 20
20
Slide 21
21
Slide 22
22
Slide 23
23
Slide 24
24
Slide 25
25
Slide 26
26
Slide 27
27
Slide 28
28
Slide 29
29
Slide 30
30
Slide 31
31
Slide 32
32
Slide 33
33
Slide 34
34
Slide 35
35
Slide 36
36
Slide 37
37
Slide 38
38
Slide 39
39
Slide 40
40
Slide 41
41
Slide 42
42
Slide 43
43
Slide 44
44
Slide 45
45

About This Presentation

graph terminology


Slide Content

Graph Terminology
CSE 373
Data Structures

6/25/2024 CSE 373 AU 05 --Graph
Terminology
2
What are graphs?
•Yes, this is a graph….
•But we are interested in a different kind of
“graph”

6/25/2024 CSE 373 AU 05 --Graph
Terminology
3
Graphs
•Graphs are composed of
›Nodes (vertices)
›Edges (arcs) node
edge

6/25/2024 CSE 373 AU 05 --Graph
Terminology
4
Varieties
•Nodes
›Labeled or unlabeled
•Edges
›Directedor undirected
›Labeled or unlabeled

6/25/2024 CSE 373 AU 05 --Graph
Terminology
5
Motivation for Graphs
•Consider the data structures we have
looked at so far…
•Linked list: nodes with 1 incoming
edge + 1 outgoing edge
•Binary trees/heaps: nodes with 1
incoming edge + 2 outgoing edges
•B-trees: nodes with 1 incoming edge
+ multiple outgoing edges
10
96 99
94
97
ValueNext
node
ValueNext
node
3 5

6/25/2024 CSE 373 AU 05 --Graph
Terminology
6
A Very Regular Graph:
Mine Sweeper

6/25/2024 CSE 373 AU 05 --Graph
Terminology
7
Motivation for Graphs
•How can you generalize these data
structures?
•Consider data structures for representing
the following problems…

6/25/2024 CSE 373 AU 05 --Graph
Terminology
8
CSE Course Prerequisites at
UW
321
143
142
322
326
341
370
378
401
421
Nodes = courses
Directed edge = prerequisite
373
410
413
415
417
461

6/25/2024 CSE 373 AU 05 --Graph
Terminology
9
Representing a Maze
S
Nodes = rooms
Edge = door or passage
S
E
B
E

6/25/2024 CSE 373 AU 05 --Graph
Terminology
10
Representing Electrical
Circuits
Nodes = battery, switch, resistor, etc.
Edges = connections
Battery Switch
Resistor

6/25/2024 CSE 373 AU 05 --Graph
Terminology
11
Program statements
x1=q+y*z
x2=y*z-q
Naive:
common
subexpression
eliminated:
y z
*
-
q
+
q *
x1 x2
y z
-
q
+
q *
x1 x2
Nodes = symbols/operators
Edges = relationships
y*z calculated twice

6/25/2024 CSE 373 AU 05 --Graph
Terminology
12
Precedence
S
1 a=0;
S
2 b=1;
S
3 c=a+1
S
4 d=b+a;
S
5 e=d+1;
S
6 e=c+d;
3
1
2
6
5
4
Which statements must execute before S
6?
S
1, S
2, S
3, S
4
Nodes = statements
Edges = precedence requirements

6/25/2024 CSE 373 AU 05 --Graph
Terminology
13
Information Transmission in a
Computer Network
Seattle
New York
L.A.
Tokyo
Sydney
Seoul
Nodes = computers
Edges = transmission rates
128
140
181
30
16
56

6/25/2024 CSE 373 AU 05 --Graph
Terminology
14
The Internet

6/25/2024 CSE 373 AU 05 --Graph
Terminology
15
Traffic Flow on Highways
Nodes = cities
Edges = # vehicles on
connecting highway
UW

6/25/2024 CSE 373 AU 05 --Graph
Terminology
16
Polygonal Meshes

6/25/2024 CSE 373 AU 05 --Graph
Terminology
17
Isomorphism

6/25/2024 CSE 373 AU 05 --Graph
Terminology
18
Isomorphism

6/25/2024 CSE 373 AU 05 --Graph
Terminology
19
Bipartite Graphs
Football
Player
CSE
Nerd
Melrose Place

6/25/2024 CSE 373 AU 05 --Graph
Terminology
20
Duality
•Vertices become faces,
faces vertices
•Max-flow becomes
Min-cut

6/25/2024 CSE 373 AU 05 --Graph
Terminology
21
Planarity
Can the circuit be put onto the chip in one layer?

6/25/2024 CSE 373 AU 05 --Graph
Terminology
22
Planarity
Can the circuit be put onto the chip in one layer?

6/25/2024 CSE 373 AU 05 --Graph
Terminology
23
Planarity
Can the circuit be put onto the chip in one layer?
K_5 K_3,3

6/25/2024 CSE 373 AU 05 --Graph
Terminology
24
Sparsely Connected Graph
•n vertices
•worst n/2 edges between two vertices
•n edges total

6/25/2024 CSE 373 AU 05 --Graph
Terminology
25
Densely Connected Graph
•n vertices total
•worst 1 edge between two vertices
•½(n^2-n) edges total

6/25/2024 CSE 373 AU 05 --Graph
Terminology
26
In Between (Hypercube)
•n vertices
•worst log n edges between two vertices
•½ n log n edges total
001011
000 010
101 111
100 110

6/25/2024 CSE 373 AU 05 --Graph
Terminology
27
0110
0000
0010
0111
0100
0011
0001
0101
In Between (Hypercube)
1000
1010
1011
1001
1110
1111
1101
1100
-16 nodes
-worst 4 edges
btwn two nodes
-32 total edges
S: (16,8,16)
D: (16,1,120)
S: (32,16,32)
H: (32,5,80)
D: (32,1,496)
S: (64,32,64)
H: (64,6,192)
D: (64,1,2016)

6/25/2024 CSE 373 AU 05 --Graph
Terminology
28
Statistical Mechanics

6/25/2024 CSE 373 AU 05 --Graph
Terminology
29
Modeling Nonlinear Data

6/25/2024 CSE 373 AU 05 --Graph
Terminology
30
Neural Networks

6/25/2024 CSE 373 AU 05 --Graph
Terminology
31
Colorings

6/25/2024 CSE 373 AU 05 --Graph
Terminology
32
“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.”

6/25/2024 CSE 373 AU 05 --Graph
Terminology
33
Graph Definition
•A graph is simply a collection of nodes plus
edges
›Linked lists, trees, and heaps are all special cases
of graphs
•The nodes are known as vertices (node =
“vertex”)
•Formal Definition: A graph Gis a pair (V, E)
where
›Vis a set of vertices or nodes
›Eis a set of edges that connect vertices

6/25/2024 CSE 373 AU 05 --Graph
Terminology
34
Graph Example
•Here is a directed graph G= (V, E)
›Each edgeis a pair (v
1, v
2), where v
1, v
2are vertices
in V
›V= {A, B, C, D, E, F}
E= {(A,B), (A,D), (B,C), (C,D), (C,E), (D,E)}
A
B
C
E
D
F

6/25/2024 CSE 373 AU 05 --Graph
Terminology
35
Directed vs Undirected
Graphs
•If the order of edge pairs (v
1, v
2) matters, the graph is
directed (also called a digraph):(v
1, v
2) (v
2, v
1)
•If the order of edge pairs (v
1, v
2) does not matter, the
graph is called an undirected graph:in this case, (v
1,
v
2) = (v
2, v
1)
v
1
v
2
v
1
v
2

6/25/2024 CSE 373 AU 05 --Graph
Terminology
36
Undirected Terminology
•Two vertices u and v are adjacentin an undirected
graph G if {u,v} is an edge in G
›edge e = {u,v} is incident with vertex u and vertex v
›Some undirected graphs allow “self loops”. These will need
slightly different notation, because {u,u} = {u}. Therefore,
use [u,v] and [u,u] to represent the edges of such graphs.
•The degree of a vertexin an undirected graph is the
number of edges incident with it
›a self-loop counts twice (both ends count)
›denoted with deg(v)

6/25/2024 CSE 373 AU 05 --Graph
Terminology
37
Undirected Graph Terminology
A
B
C
E
D
F
Degree = 3
Degree = 0
B is adjacent to C and C is adjacent to BEdge [A,B] is incident
to A and to B
Self-loop

6/25/2024 CSE 373 AU 05 --Graph
Terminology
38
Directed Graph Terminology
•Vertex u is adjacenttovertex v in a directed
graph G if (u,v) is an edge in G
›vertex u is the initial vertex of (u,v)
•Vertex v is adjacent fromvertex u
›vertex v is the terminal (or end) vertex of (u,v)
•Degree
›in-degreeis the number of edges with the vertex
as the terminal vertex
›out-degreeis the number of edges with the vertex
as the initial vertex

6/25/2024 CSE 373 AU 05 --Graph
Terminology
39
Directed Terminology
A
B
C
E
D
F
In-degree = 2
Out-degree = 1
In-degree = 0
Out-degree = 0
B adjacent toC and C adjacent fromB

6/25/2024 CSE 373 AU 05 --Graph
Terminology
40
Handshaking Theorem
•Let G=(V,E) be an undirected graph with
|E|=e edges. Then
•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


Vv
deg(v)2e
Add up the degrees of all vertices.

6/25/2024 CSE 373 AU 05 --Graph
Terminology
41
•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 matrixrepresentation
•The adjacency listrepresentation
Graph Representations

6/25/2024 CSE 373 AU 05 --Graph
Terminology
42
A B C D E F
0 1 0 1 0 0
1 0 1 0 0 0
0 1 0 1 1 0
1 0 1 0 1 0
0 0 1 1 0 0
0 0 0 0 0 0
M(v, w) =
1 if [v, w] is in E
0 otherwise
A
B
C
D
E
F
Space = |V|
2
A
B
C
E
D
F
Adjacency Matrix

6/25/2024 CSE 373 AU 05 --Graph
Terminology
43
A B C D E F
0 1 0 1 0 0
0 0 1 0 0 0
0 0 0 1 1 0
0 0 0 0 1 0
0 0 0 0 0 0
0 0 0 0 0 0
A
B
C
D
E
F
Space = |V|
2
M(v, w) =
1 if (v, w) is in E
0 otherwise
A
B
C
E
D
F
Adjacency Matrix for a
Digraph

6/25/2024 CSE 373 AU 05 --Graph
Terminology
44
B D
B D
C
A C E
D
E
A C
A
B
C
D
E
F
A
B
C
E
D
F
Space = a|V| + 2 b|E|
Foreach v in V, L(v) = list of wsuch that [v, w] is in E
a b
Adjacency List
list of
neighbors

6/25/2024 CSE 373 AU 05 --Graph
Terminology
45
B D
E
D
C
a b
A
B
C
D
E
F
E
A
B
C
E
D
F
Foreach v in V, L(v) = list of wsuch that (v, w) is in E
Space = a|V| + b|E|
Adjacency List for a Digraph
A is a source
E is a sink
F is disconnected from the rest
Tags