0% found this document useful (0 votes)
3 views62 pages

09 - Graphs

MAD - Graghs
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views62 pages

09 - Graphs

MAD - Graghs
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 62

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 links

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
Simple graph

Non-simple graph
with loops

Non-simple graph
with multi-edges

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 adjacent The edge {u, v} is called
verte adjacency incident with u and v
x list
edge incident
a a, c vertices
b c {a, a} a
c a, b {a, c} a, c
d {c, b} c, b

12 Chapter 9 - Graphs
Basic Terminology

The degree of a vertex v: vertex degree


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

Remark: degree = 2| Edges |

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.
σv deg(v) = 5 + 5 + 4 + 3 + 2 + 1 + 0
= 20 = 2.|E| ➔ |E| = 10.

15 Chapter 9 - Graphs
16 Chapter 9 - Graphs
Directed graphs -Basic
Terminology

Vertex In-degree Out-degree


deg- deg+
a 2 1
b 0 2
c 1 0
d 1 1

deg- = deg+ = 4 directed edges

17 Chapter 9 - Graphs
Special simple graphs

Complete graphs Kn (n 1)

K4 K5 K6
K20

18 Chapter 9 - Graphs
Cycles Cn

Cycles Cn (n  3)

C5 C6 C8

19 Chapter 9 - Graphs
Wheels Wn

Cycles
Cn
C5 C6
C8

Wheels • •
Wn (n  3)

W5 W6

20 Chapter 9 - Graphs
n-cubes Qn

n-dimensional hypercube

1-D

2-D 3-D

Graph |V| = number of vertices |E| = number of edges


Qn 2n n.2n-1

21 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

22 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

23 Chapter 9 - Graphs
Bipartite Graphs…

bipartite

Edge considered Set 1 Set 2


ab a b
ae a b, e
af a b, e, f
bc ac
Conflic
be a, c, e t
➔ Non- bipartite
Bipartite graphs

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

d • ➔ bipartite
b
• V1 = {a, e, f}
V2 = {b, c, d}
f
e

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


? ➔ G is not bipartite

G

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

m=3

n=5
K3,5

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 n
G1 = (V1, E1), G2 = (V2, E2)
• • • m

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
Isomorphic?

YES

33 Chapter 9 - Graphs
Isomorphic?

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

34 Chapter 9 - Graphs
Representing graphs
 Adjacency matrix

 Incidence matrix
edge 1 edge 2 … edge m

Vertex 1
Vertex 2

Vertex n

35 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}

36 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.

37 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

38 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

39 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.

  

40 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.

 

41 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.

42 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

43 Chapter 9 - Graphs
Connectedness in Directed Graphs

Strongly connected vs weakly connected

G H
G: strongly connected
➔ weakly connected H: weakly connected
 connected

44 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

45 Chapter 9 - Graphs
Shortest-path problems

weight

46 Chapter 9 - Graphs
Shortest-path problems

47 Chapter 9 - Graphs
Dijkstra’s algorithm

c d
3 11

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

78 9
b e

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

48 Chapter 9 - Graphs
Dijkstra’s Algorithm

O(n2)
time complexity

49 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

50 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

51 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

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

construct a simple circuit in G


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

53 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

54 Chapter 9 - Graphs
Hamilton Paths and Circuits

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

start

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

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

56 Chapter 9 - Graphs
Hamilton Paths and Circuits

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

57 Chapter 9 - Graphs
Hamilton circuits - sufficient conditions
Dirac’s theorem.
G is a graph:
• simple
• n (  3) vertices
• vi, deg(vi) 
𝟐
𝐧  G has a Hamilton circuit
2 3

Ore’s theorem. ? 3 3
2
G is a graph:
• simple
• n (  3) vertices
• u, v, non-adjacent
deg(u) + deg(v)  n
 G has a
Hamilton circuit

58 Chapter 9 - Graphs
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 ?
59 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
60 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

61 Chapter 9 - Graphs
THANKS

62 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