0% found this document useful (0 votes)
4 views75 pages

Chapter 9 Graphs

Uploaded by

Thảo Vy
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views75 pages

Chapter 9 Graphs

Uploaded by

Thảo Vy
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 75

Chapter 9-Graphs

“One graph is worth a thousand logs.”


Michal Aharon, Gilad Barash, Ira Cohen and Eli Mordechai.

1 Chapter 9 - Graphs
Introduction

LEONHARD EULER
(1707–1783)

The Seven Bridges of Königsberg.

Multigraph Model

2 Chapter 9 - Graphs
Introduction

Web Graph
Google PageRank

A network with 5 websites and lin

3 Chapter 9 - Graphs
Objectives
 9.1- Graphs and Graph Models
 9.2- Graph Terminology and
Special Types of Graphs
 9.3- Representing Graphs and
Graph Isomorphism
 9.4- Connectivity
 9.5- Euler and Hamilton Paths
 9.6- Shortest Path Problems
Graphs
 Graphs = (vertices, edges)  G = (V,
E)

V = vertices = { a, b, c, d }
E = edges = { {a, b}, {a, c} }

Computer network

5 Chapter 9 - Graphs
Simple graphs

Non-simple graphNon-simple graph


Simple graph
with multi-edges with loops

6 Chapter 9 - Graphs
Types of graphs

An undirected graph
A directed graph
(digraph)

7 Chapter 9 - Graphs
Graphs and Graph Models….
Graphs and Graph Models….

Niche Overlap Graph in Ecology Acquaintanceship Graph


(sinh thái học) – Đồ thị lấn tổ Đồ thị cho mô hình quan hệ giữa người
Graphs and Graph Models….

An Influence Graph
A Graph Model of a Round-Robin An Precedence Graph
Tournament

Call Graph
Graph models - Social networks

11 Chapter 9 - Graphs
Basic Terminology

If an edge {u, v} exists,


then u and v are called The edge {u, v} is
adjacent called incident
vert adjacenc
ex y list with u and v
edge incident
a a, c vertices
b c {a, a
c a, b a}
d {a, a, c
c}
12 Chapter{c,
9 - Graphs c, b
Basic Terminology

The degree of a vertex verte degre


x e
v:
a 3
b is called pendant
= the number of edges b 1
incident with v, except c 2
d is called isolated
that a loop at a vertex d 0
degree= 6
contributes twice.
Remark: degree = 2| Edges |
Notation: deg(v)

13 Chapter 9 - Graphs
THE HANDSHAKING THEOREM (for undirected graphs)

3 edges: {a, a}, {c, b}, {a, c}


deg(a) = 3
deg(b) = 1
deg(c) = 2
deg(d) = 0
deg= 6
THE HANDSHAKING THEOREM:
(one edge = two degrees)

vVdeg(v) = 2|E| always EVEN

“the sum of the degrees is twice the number of


edges”.

14 Chapter 9 - Graphs
THE HANDSHAKING THEOREM -
Examples
Ex2. How many edges does a graph have
if its degree sequence is 5, 5, 4, 3, 2, 1,
0?
Draw a such graph.
=5+5+4+3+2+1+0
= 20 = 2.|E|  |E| = 10.

15 Chapter 9 - Graphs
Directed graphs -Basic
Terminology

Vertex In- Out-


degree degree
deg- deg+

a 2 1
b 0 2
c 1 0
d 1
deg- = 1deg+= directed
4 edges

16 Chapter 9 - Graphs
Special simple graphs

Complete graphs Kn (n 1)

K4 K5 K6

K20

17 Chapter 9 - Graphs
Cycles Cn

Cycles Cn (n )

C5 C6 C8

18 Chapter 9 - Graphs
Wheels Wn

Cycles
Cn
C5 C6
C8

Wheels  
Wn (n )

W5 W6

19 Chapter 9 - Graphs
n-cubes Qn

n-dimensional hypercube

1-D

2-D 3-D

Graph |V| = number of |E| = number of


vertices edges
Qn 2n n.2n-1

20 Chapter 9 - Graphs
n-cube Qn
 Construct Q4 from two copies of Q3

0 1
0 0

0 0 1
1

0 1 1
0

1 1
0 0

1 1

21 Chapter 9 - Graphs
Bipartite graphs
 A simple graph G = (V, E) is called bipartite
if:
 V = V1 V2, V1  V2 = 
 no edge connects two vertices in V1
 no edge connects two vertices in V2
We call the pair (V1,V2) a bipartition of V.
Ex. Study graph C6 (cycle)
V = { a, b, c, d, e, f }
V1 = {a, e, c} ae ac ec 
V2 = {b, f, d} bf bd fd
 C6 is bipartite
22 Chapter 9 - Graphs
Bipartite Graphs…

bipartite

Edge Set 1 Set 2


considered
ab a b
ae a b, e
af a b, e, f
bc ac Confli
ct
be a, c, e
 Non-
bipartite
Bipartite graphs

a b
 Ex. • Let color the vertices 
 C6 is bipartite
using 2 different colors f  c V1 = {a, c, e}
• Two adjacent vertices V2 = {b, d, f}
must have different
colors (e.g., red and 
e d
black) a
c

d   bipartite
b
 V1 = {a, e, f}
V2 = {b, c, d}
f
e

24 Chapter 9 - Graphs
Example
Ex. Is the graph G bipartite?


? G is not bipartite

G

25 Chapter 9 - Graphs
Km,n - Complete bipartite graphs

m=3

n=5
K3,5

26 Chapter 9 - Graphs
Euler path Euler circuit Hamilton path Hamilton
circuit

Kn + K2 n is odd (n >
2)
+ K2 All n > 2
e.g: K3; K4; K5
+ n is odd (n > + All n > 2
2) e.g: K3; K5; K7 e.g: K3; K4; K5
e.g: K3; K5; K7

Cn >2 All n All n All n All n

Wn>2 NO NO

Qn

Km,n
27 Chapter 9 - Graphs
Some Applications of Special Types of Graphs

Figure 10: Modeling the jobs for


which employees have been
trained
New Graphs From Old
Isomorphism

THE SAME

30 Chapter 9 - Graphs
Isomorphism

a b m n
G1 = (V1, E1), G2 = (V2, E2)
   
G1 and G2 are called isomorphic if
$ function f: V1  V2

o One-to-one
o Onto c d  p  q 
o a, b are adjacent in V1
 f(a), f(b) are adjacent in V2
function f = {(a, m); (b, p); (d, n); (c, q)}
 Two graphs are called isomorphic

31 Chapter 9 - Graphs
Isomorphism of Graphs

Pull
out
33 Chapter 9 - Graphs
Isomorphic?

YES

34 Chapter 9 - Graphs
Isomorphic?

G H
G and H are NOT isomorphic
(in H: deg(e) = 1, no vertex in G has degree 1)

35 Chapter 9 - Graphs
Representing graphs
 Adjacency matrix

 Incidence matrix
edge 1 edge 2 … edge m

Vertex 1
Vertex 2

Vertex n

36 Chapter 9 - Graphs
Adjacency matrices

a b c d
a 0 0 1 0
b 0 0 1 2
c 1 1 0 1
d 0 2 1 0

Adjacency matrix.
A = [aij],
where aij = the number of
edges that are associated to
{vi, vj}
37 Chapter 9 - Graphs
In 2010 the Web graph was
estimated to have at least 55
billion vertices and one trillion
edges.
 More than 40 TB of
computer memory would have
been needed to represent its
adjacency matrix.
38 Chapter 9 - Graphs
Incidence matrices

edges
e6
e1
e1 e2 e3 e4 e5 e6
e2 a 1 1 0 0 0 0
b 1 0 0 0 0 1
e3
e5 c 0 1 0 0 0 0
e4
d 0 0 1 1 0 0
e 0 0 1 0 1 0
Vertices = { a, b, c, d, e, f } f 0 0 0 1 1 0
Edges = { e1, e2, e3, e4, e5, e6 } g 0 0 0 0 0 0

39 Chapter 9 - Graphs
Incidence matrices
If the edge ej is incident with the vertex vi
the (vi, ej)-entry = 1
Else
the (vi, ej)-entry = 0

40 Chapter 9 - Graphs
A path of length n

• A path of length n
from u to v:
A sequence of n  
consecutive edges
• Ex.
a, e, f, c, d
is a path of
length 4.   

41 Chapter 9 - Graphs
Circuits

• A circuit is a path of
length greater than
zero that starts and   
ends at the same
vertex.

• Ex.
c, b, e, a, d, c is  
circuit.

42 Chapter 9 - Graphs
Simple paths/circuits

• A path/circuit is
simple if it does not   
contain the same
edge more than once.

• Ex.
b, e, a, b, f, c   
is a simple path.
c, b, e, a, d, e, b,
f, c
is NOT a simple circuit.

43 Chapter 9 - Graphs
Connectedness in Undirected
Graphs

o Connected = there is a path


between every pair of distinct
vertices of the graph.
o Not connected = disconnected.

G
A disconnected with
G is connected 3 connected
components

44 Chapter 9 - Graphs
45 Chapter 9 - Graphs
Connectedness in Directed Graphs

Strongly connected vs weakly connected

G H
G: strongly connected
 weakly connected H: weakly connected
 connected

46 Chapter 9 - Graphs
H

47 Chapter 9 - Graphs
G

48 Chapter 9 - Graphs
Counting Paths Between Vertices
How many paths of length four from
a to d in the simple graph G?
The adjacency matrix of G is given below
(ordering the vertex as a, b, c, d)
to

from
G

Result = 8

49 Chapter 9 - Graphs
Shortest-path problems

weight

50 Chapter 9 - Graphs
Shortest-path problems

51 Chapter 9 - Graphs
Dijkstra’s algorithm

c d
 11
3 
14
12
11
12
3 6
a 0 4 2 
25 z
23
5
8 9 16

8
7 
9

b e

S = {a,c,b, e, d, z}
The shortest path from a to z: a, c, e, d, z

52 Chapter 9 - Graphs
Find the length of the shortest path from A to G.

53 Chapter 9 - Graphs
om

h: A,

E,

54 Chapter 9 - Graphs
How many strongly connected?

2 STRONGLY Connected
component

55 Chapter 9 - Graphs
56 Chapter 9 - Graphs
han lien thong manh.
=(V, E)
ong. Chua A.

57 Chapter 9 - Graphs
Dijkstra’s Algorithm

O(n2)
time complexity

58 Chapter 9 - Graphs
Euler and Hamilton paths - introduction

Can one travel across


all the bridges once and
return to the starting
point?
LEONHARD EULER
(1707–1783)

The Seven Bridges of Königsberg.


Multigraph Model

59 Chapter 9 - Graphs
Euler circuit/path - definitions

o An Euler path/circuit in a graph G is


a simple path/circuit containing every
edge of G.

G3 has no an Euler circuit,


G1 has an Euler circuit
But G3 has an Euler path
a, b, e, d, c, e, a
a, c, d, e, b, d, a, b

60 Chapter 9 - Graphs
Euler circuit

Theorem.
A connected multigraph,  2 vertices,
has an Euler circuit  every vertex has
even degree
3 NOT OK
2 2

4 OK
2 2

61 Chapter 9 - Graphs
How to construct an Euler circuit?
procedure Euler(G: connected, every
a d
vertex has even degree)

construct a simple circuit in G


b c H:= G – circuit // remove passed
edges
G while H has edges
e f construct a simple subcircuit in
H beginning at a vertex in circuit
H: = H – subcircuit // remove
c passed edges
H circuit : = add subcircuit to
circuit
e f
circuit: a, b, c, d, a
{ circuit is an Euler circuit }
subcircuit: c, e, f, c
 circuit: a, b, c, e, f, c, d, a

62 Chapter 9 - Graphs
Euler path

Theorem.

A connected multigraph has


an Euler path but not an Euler
circuit

it has exactly
two vertices of odd degree
Note that: an Euler circuit is also an Euler path

63 Chapter 9 - Graphs
Hamilton Paths and Circuits

Hamilton circuit/path:
A simple circuit/path passes through
every vertex exactly once.

start

end
?
Hamilton No Hamilton circuit
path a,b,c,d,e is a Hamilton path

64 Chapter 9 - Graphs
Example - A Hamilton circuit for Q3

65 Chapter 9 - Graphs
Hamilton Paths and Circuits

There are
NO known simple
necessary and sufficient
criteria
for the existence of
Hamilton circuits

66 Chapter 9 - Graphs
Hamilton circuits - sufficient
conditions
Dirac’s theorem.
G is a graph:
• simple


• n (  3) vertices
G has a Hamilton circuit
•  vi, deg(vi)  2 3

Ore’s theorem.
G is a graph:
? 3 3
2

• simple


• n (  3) vertices
•  u,  v, non-adjacent
G has a
deg(u) + deg(v)  n Hamilton circuit

67 Chapter 9 - Graphs
Lms: practice 9, 123

68 Chapter 9 - Graphs
Degree sequence: 4
2,2,2,2,2
(even degree) So:
Has Euler circuit (als
E.path)

69 Chapter 9 - Graphs
Degree sequence: 4, 3, 3,
2,2,2
Has Euler path (but not
E.circuit)

70 Chapter 9 - Graphs
Degree sequence: 4,4, 2,2,2,2 (even degree)
So, it has Euler circuit (also E.path)
The Traveling Salesman Problem

Total Distance
= 58 + 133 + 137 + 113 + 147
= 588

Salesman starts in one city (ex. Detroit). He wants to visit


n cities exactly once and return to his starting point
(Detroit). In which order should he visit theses cities to
travel the minimum total distance ?
72 Chapter 9 - Graphs
The Traveling Salesman Problem

4!
=12
2

Exhaustive search technique // vét cạn

[(n-1) (n-2) (n-2) … 3.2.1]/2 = (n-1) !]/2  O((n-1)!) complexity

 Approximation algorithm
73 Chapter 9 - Graphs
Summary
 9.1- Graphs and Graph Models
 9.2- Graph Terminology and Special Types of
Graphs
 9.3- Representing Graphs and Graph Isomorphism
 9.4- Connectivity
 9.5- Euler and Hamilton Paths
 9.6- Shortest Path Problems

74 Chapter 9 - Graphs
THANKS

75 Chapter 9 - Graphs

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy