0% found this document useful (0 votes)
41 views

Graph Terminology: CSE 373 Data Structures

Graphs are composed of nodes and edges. They can model a variety of structures like mazes, networks, and data relationships. The document discusses graph terminology like vertices, edges, directed/undirected graphs, and degrees. It also covers graph representations using adjacency matrices and adjacency lists to store the graph in memory. Adjacency matrices use O(V^2) space while lists use O(V+E) space.

Uploaded by

manny oluan
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
41 views

Graph Terminology: CSE 373 Data Structures

Graphs are composed of nodes and edges. They can model a variety of structures like mazes, networks, and data relationships. The document discusses graph terminology like vertices, edges, directed/undirected graphs, and degrees. It also covers graph representations using adjacency matrices and adjacency lists to store the graph in memory. Adjacency matrices use O(V^2) space while lists use O(V+E) space.

Uploaded by

manny oluan
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 42

Graph Terminology

CSE 373
Data Structures

Reading
Reading Chapter 13
Sections 13.1 and 13.2

Graph Terminology

What are graphs?


Yes, this is a graph.

But we are interested in a different kind of


graph
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

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
Up-trees: nodes with multiple
incoming edges + 1 outgoing edge

node
Value Next

node
Value Next

94

97

10
a
96
d

Graph Terminology

99

b
6

Motivation for Graphs


How can you generalize these data
structures?
Consider data structures for representing
the following problems

Graph Terminology

Representing a Maze
S
S
B
E
E

Nodes = cells
Edges = door or passage
Graph Terminology

CSE Course Prerequisites at


UW
322

143

321
326

142

370

341

378

Nodes = courses
Directed edge = prerequisite
Graph Terminology

421
401
9

Representing Electrical
Circuits
Battery

Nodes = battery, switch, resistor, etc.


Edges = connections
Graph Terminology

Switch

Resistor

10

Program statements
x1=q+y*z
x2=y*z-q

Naive:

x1

x2

y*z calculated twice


common
subexpression
eliminated:

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;

Which statements must execute before S6?


S1, S2, S3, S4

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

Traffic Flow on Highways

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

Time complexity to test if 2 graphs are isomorphic?


Graph Terminology

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

Related Problems: Puzzles


A

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

Sparsely Connected Graph


n vertices
n edges total
Ring

Graph Terminology

20

Densely Connected Graph


n vertices total
(n (n-1))/2 edges total (w/o self loops)

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

Four Color Conjecture


is it true that any map can be colored using
four colors in such a way that adjacent
regions (i.e. those sharing a common
boundary segment, not just a point) receive
different colors (1852)?
Many attempts at proof
Finally solved by computer program (1974)
Still extremely complex.
Graph Terminology

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

The nodes are known as vertices (node =


vertex)
Formal Definition: A graph G is a pair (V, E)
where
V is a set of vertices or nodes
E is a set of edges that connect vertices
Graph Terminology

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

The degree of a vertex in an undirected graph


is the number of edges incident with it
a self-loop counts twice (both ends count)
denoted with deg(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)

Vertex v is adjacent from vertex u


vertex v is the terminal (or end) 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:

ind (v) = outd (v) = e

v in G

v in g

Graph Terminology

36

Graph ADT
Nothing unexpected

Build the graph (vertices, edges)


Return the edges incident in(or out) of a vertex)
Find if two vertices are adjacent etc..
Replace , InsertRemove

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

Adjacency Matrix for a


Digraph
B
C

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

Space = a |V| + 2 b |E|


41

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
C

F
D

E
F
Graph Terminology

Space = a |V| + b |E|


42

You might also like