You are on page 1of 63

TMC1813 DISCRETE MATHEMATICS

[9.0 Introduction to Graphs]

TERRIN LIM terrin@fit.unimas.my ext 3714


Dept of Computational Science & Mathematics FCSIT, UNIMAS
Sem I 2010/2011

Definitions
def: A vertex is a point, e.g. in 3space, def: An edge is a space curve (without self-intersections) joining a vertex to itself or to another vertex. Such vertices are called endpoints of the edge. def: Two vertices are adjacent if there is an edge joining them. def: A graph is a collection of vertices (V) and edges (E).
2

Type of Graphs def: A graph is simple if


(1) no self-loops, and (2) at most one undirected edge between any pair of vertices. (better etymology: simplicial)
A Graph A simple graph G = (V, E) consists of V, a nonempty set of vertices, and E, a set of unordered pairs of distinct elements of V called edges. A simple Graph
3

Type of Graphs (Cont )


Graphs with multiple edges between pairs of vertices allowed is called multigraphs. Definition: A multigraph G = (V, E) consists of a set V of vertices, a set E of edges, and a function f from E to {{u, v} | u, v V, u { v}. The edges e1 and e2 are called multiple or parallel edges if f(e1) = f(e2).
 Every simple graph is also a multigraph.

Type of Graphs (Cont )


Edges from a vertex to itself, or loops, are not allowed in multigraphs. Graphs with loops are pseudographs. called pseudographs Definition: A pseudograph G = (V, E) consists of a set V of vertices, a set E of edges, and a function f from E to {{u, v} | u, v V }. An edge is a loop if f(e) = {u, v} = {u} for some u V

Type of Graphs (Cont )


Directed graphs are used to model direction of edges between vertices. Directed graphs allowed loops of the same vertex but multiple edges in the same direction between two vertices are not. Definition: A directed graph (V, E) consists of a set of vertices V and a set of edges E that are ordered pairs of elements of V.

Type of Graphs (Cont )


Directed multigraphs allow multiple directed edges from a vertex to a second vertex. Definition: A directed multigraph G = (V, E) consists of a set V of vertices, a set E of edges, and a function f from E to {{u, v} | u, v V }. The edges e1 and e2 are multiple edges if f(e1) = f(e2).

Summary of The Type of Graphs


Type
Simple Graph Multigraph Pseudograph Directed Graph Directed Multigraph

Edges
Undirected Undirected Undirected Directed Directed

Multiple Edges Loops Allowed Allowed


No Yes Yes No Yes No No Yes Yes Yes

Example: A Computer network graph Computer 1 Computer 2

Computer 3 Computer 4 Computer 5

If multiple connection are possible between two machines, we would have a multigraph If a connection can only be one-way, then we would have a directed (multi)graph.
9

Summary

Type of graphs
Simple Graph Multigraph Pseudograph Directed Graph Directed Multigraph

10

9.2 Graph Terminology

TERRIN LIM terrin@fit.unimas.my ext 3714


Dept of Computational Science & Mathematics FCSIT, UNIMAS
Sem I 2007/2008

Adjacency and The Degree of a Vertex Two vertices u and v in an undirected graph G are called adjacent (or neighbours) if {u, v} is an edge of G. If e = {u, v} (more precisely, f(e) = {u, v}), the edge e is called incident with u and v. The edge e is also said to connect u and v. The vertices u and v are called endpoints of the edge {u, v}. The degree of a vertex in an undirected graph is the number of edges incident with it, except that a loop at a vertex contributes twice to the degree of that vertex. The degree of the vertex v is denoted by deg(v).
12

Example 1
What are the degrees of the vertices in the following graph?
b c d

deg(a) = 2 deg(b) = 4 deg(c) = 4 deg(d) = 1 deg(e) = 3 deg(f) = 4 deg(g) = 0

Vertex of degree zero is called isolated. Vertex of only 1 degree is called pendant. d is pendant and g is isolated.

13

The Handshaking Theorem


Theorem: Let G = (V, E) be an undirected graph with e edges. Then
2e =v7V deg(v)

This theorem shows that the sum of the degrees of the vertices of an undirected graph is even.
14

Example 2
How many edges are there in a graph with seven vertices each of degree four?
The sum of the degrees of the vertices is 4.7 = 28. 2e = 28, e = 14.

15

Theorem
An undirected graph has an even number of vertices with odd degrees.

In a directed graph, the in-degree of a vertex v, denoted by deg(v), is number of edges with v as their terminal vertex. The out-degree of v, denoted by deg+(v), is the number of edges with v as their initial vertex.
Theorem: Let G = (V, E) be a directed graph. Then deg(v) = deg(v) = |E|
vV vV
16

Complete Graph
The complete graph on n vertices, denoted by Kn , is the simple graph that contains exactly one edge between each pair of distinct vertices. K1 K3 K5
17

K2 K4

Cycles
The cycle Cn, n u3, consists of n vertices v1, v2, , vn and edges {v1, v2}, {v2, v3}, , {vn-1, vn}, {vn, v1}. C3 C5 C4 C6

18

Wheels
We obtain the wheel Wn when we add an additional vertex to the cycle Cn , and connect this new vertex to each of the n vertices in Cn. W3 W5 W4 W6
19

n-Cubes
The n-dimensional cube, n-cube, denoted by Qn , is the graph that has vertices representing the 2n bit strings of length n. Two vertices are adjacent if and only if the bit string s that they represent differ in exactly one position. Q1
0 1

Q2
10 11

Q3
100

110 101 010 000 001

111

00

01

011

20

Subgraph
A subgraph of a graph G = (V, E) is a graph H = (W, F) where W V and F E. Example: S is a subgraph of K5
a e d K5 c S b e c a b

21

Summary
Adjacency and The Degree of a Vertex The Handshaking Theorem Complete Graph Cycles Wheels n-Cubes Subgraph

22

9.3 Representing Graphs and Graph Isomorphism


TME 1813 Discrete Mathematics

TERRIN LIM terrin@fit.unimas.my ext 3714


Dept of Computational Science & Mathematics FCSIT, UNIMAS

Adjacency List Representation DEF: An adjacency list for a vertex v of a graph G is a list containing each vertex w of G once for each edge between v and w. DEF: An adjacency list representation of a graph is a table of all the adjacency lists.

24

Adjacency Lists
Examples:
b a e
Initial Vertex

Vertex
a b c d e

Adjacent Vertices b, c, e a a, d, e c, e a, c, d

c d
Terminal Vertex

b a e d
25

a b c d e

b, e b a, d, c, e -

Adjacency Matrices
Suppose G = (V, E) is a simple graph where |V| = n. The adjacency matrix A (or AG) of G is the n v n zero-one matrix. Matrix AG = [aij], where
aij =
1 if {vi , vj} is an edge of G 0 otherwise

26

Adjacency Matrix Representation


b a e d c a e a a b c d e
0 0 1 0 0

b c d b c
1 1 0 0 0 0 0 0 1 0

Adjacency matrix
a a b c d e
0 1 1 0 1

Adjacency matrix
d e
0 0 1 0 0 1 0 0 1 0

b c
1 0 0 0 0 1 0 0 1 1

d e
0 0 1 0 1 1 0 1 1 0

27

Adjacency Matrices (Cont )


Can also be used to represent graphs with loops and multiple edges (pseudographs) by letting each matrix elements be the number of links (possibly >1) between the nodes. When multiple edges are present, the adjacency matrix is no longer a zeroone matrix. An entry of this matrix equals to the number of edges that are associated to {ai, aj}.
28

Adjacency Matrix for Pseudographs

Example: Find the adjacency matrix for the following graph


a b 0 3 d c 0 2 3 0 1 1 0 1 1 2 2 1 2 0
29

Graph Isomorphism
The Greek root iso means same . The Greek root morphism means form . DEF: The Simple graphs G1=(V1, E1) and G2=(V2, E2) are isomorphic if there is a one-to-one and onto (bijection) function f from V1 to V2 with the property that a and b are adjacent in G1 if and only if f(a) and f(b) are adjacent in G2. For all a and b inV1 .

30

Isomorphism
Example: Determine if the graphs G = (V, E) and H = (W, F) below are isomorphic. Give the possible correspondence.
a G c 1 3 H d 2 4 b The function f(a) = 1, f(b) = 4, f(c) = 3, f(d) = 2 is a 1-to-1 and onto correspondence between V and W. This also preserves adjacency where (a, b) = (1, 4); (a, b) = (1, 3) and so on Hence, the graphs are isomorphic and the possible correspondence is: a-1, b-4, c-3 and d-2.
31

Graph Invariants under Isomorphism

Graphs that are not isomorphic are called invariant. To be isomorphic, three properties should be met. Graph G1=(V1, E1) is isomorphic to graph G2=(V2, E2) iff:
|V1| = |V2|, and |E1| = |E2|.
The number of vertices with degree n is the same in both graphs. For every proper subgraph g of graph G1, there is a proper subgraph of graph G2 that is isomorphic to g.
32

Isomorphism Example
If isomorphic, label the 2nd graph to show the isomorphism, else identify difference.
b a d e f c c b d a e f

33

Are These Isomorphic?


If isomorphic, label the 2nd graph to show the isomorphism, else identify difference.
a b Same # of vertices Same # of edges Different # of vertices of degree 2! (1 vs 3) e

d c

34

Summary
Adjacency List Representation Adjacency Lists Adjacency Matrices Adjacency Matrix Representation Adjacency Matrix for Pseudographs Graph Isomorphism Graph Invariants

35

9.4 Connectivity
TMC 1813 Discrete Mathematics

TERRIN LIM terrin@fit.unimas.my ext 3714


Dept of Computational Science & Mathematics FCSIT, UNIMAS
Sem I 2009/2010

Announcements
No more Discussion slots. Replacement class is on for this week FRIDAY 22 OCT 2010 730 pm 930 pm @ DK, CTF!

37

8.4: Connectivity
In an undirected graph, a path of length n from u to v is a sequence of adjacent edges going from vertex u to vertex v. A path is a circuit if it begins and ends at the same vertex that is u=v and has length greater then zero. A path or circuit is also called simple if it does not contain the same edge more then once. A path traverses the vertices along it.

38

8.4: Connectivity
a b c

a,d,c,f,e is a simple path of length 4.

39

8.4: Connectivity
a b c

e b,c,f,e,b is a circuit of length 4.

6/12/2011 40

Paths in Directed Graphs


Same as in undirected graphs, but the path must go in the direction of the arrows. For ease of reference the definitions are summarized in the following table.
Repeated Edge? Repeated Vertex? Start and Ends at Same Point? allowed no yes yes

Path Simple path Circuit Simple circuit

yes no yes no

allowed no allowed First and last only

41

Connectedness
An undirected graph is connected iff there is a path between every pair of distinct vertices in the graph. Theorem: There is a simple path between any pair of vertices in a connected undirected graph. Connected component: disjoint connected subgraphs A cut vertex or cut edge separates 1 connected component into 2 if removed.

42

Connectedness
What are the connected components of the graph H shown below? b H1 H2 d a c e h g f H3

The graph H is the union of the three disjoint connected subgraphs H1, H2 and H3. These 3 subgraph are the connected components of H
43

Directed Connectedness
A directed graph is strongly connected iff there is a directed path from a to b for any two vertices a and b. It is weakly connected iff the underlying undirected graph (i.e., with edge directions removed) is connected. Note strongly implies weakly but not vice-versa. Any strongly connected directed graph is also weekly connected.

44

Directed Connectedness
Are the directed graphs G and H shown in figure 5 strongly connected? Are they weekly connected

b c

b c

e G

e H

d
Weakly connected

Strongly and weakly connected

45

Paths & Isomorphism


Note that connectedness, and the existence of a circuit or simple circuit of length k are graph invariants with respect to isomorphism.

46

Counting Paths w Adjacency Matrices

Let A be the adjacency matrix of graph G. The number of paths of length k from vi to vj is equal to (Ak)i,j.
The notation (M)i,j denotes mi,j where [mi,j] = M.

47

Counting Paths w Adjacency Matrices

Example
How many paths of length 4 are there from a to d in the simple graph a below?

48

Counting Paths w Adjacency Matrices

The adjency matrix of G (in order abcd) is


0 1 1 0

A=

1 0 0 1 1 0 0 1 0 1 1 0

The numbers of paths of length 4 from a to d is the (1,4)th entry of A4.

49

Counting Paths w Adjacency Matrices


8 0 0 8

A = 0 8 8 0
0 8 8 0 8 0 0 8 From the graph it could be observed that there are exactly 8 paths of length 4 from a to d. What are the paths?

a,b,a,b,d; a,b,a,c,d ; a,b,d,b,d ; a,b,d,c,d; a,c,a,b,d ; a,c,a,c,d ; a,c,d,b,d and a,c,d,c,d


50

9.5 Euler & Hamilton Paths


TMC 1813 Discrete Mathematics

TERRIN LIM terrin@fit.unimas.my ext 3714


Dept of Computational Science & Mathematics FCSIT, UNIMAS

Euler & Hamilton Paths


An Euler circuit in a graph G is a simple circuit containing every edge of G. An Euler path in G is a simple path containing every edge of G. A Hamilton circuit is a circuit that traverses each Hamilt vertex in G exactly once. A Hamilton path is a path that traverses each Hamilt vertex in G exactly once.
52

Euler & Hamilton Paths


Which one of these graph has an Euler Circuit and an Euler Graph?
a e d c d b a e c c d e b a b

G1 Euler Circuit

G2

G3 Euler Graph

53

Hamiltons Circuit
Which of these graph has a Hamilton circuit and which one has a Hamilton path?
Hamilton circuit

e d G1

d G2

Hamilton path
54

Bridges of Knigsberg Problem Knigsberg


Can we walk through town, crossing each bridge exactly once, and return to start? C

B The original problem

Equivalent multigraph
55

Euler Path Theorems


Theorem: A connected multigraph has an Euler circuit iff each vertex has even degree.
Proof:
( ) The circuit contributes 2 to degree of each node. ( ) By construction using algorithm on p. 636

Theorem: Theorem A connected multigraph has an Euler path (but not an Euler circuit) iff it has exactly 2 vertices of odd degree.
One is the start, the other is the end.

56

Euler Path Theorems


Eg. Does the graf below have an Euler path?
a b

2 Vertices with odd


degree. Euler path

57

Euler Circuit Algorithm


Begin with any arbitrary node. Construct a simple path from it till you get back to start. Repeat for each remaining subgraph, splicing results back into original cycle.

58

Hamilton s Voyage Round-the-World Puzzle Round-the-

Can we traverse all the vertices of a dodecahedron, visiting each once?`

Dodecahedron puzzle

Equivalent graph

Pegboard version

59

Hamiltonian Path Theorems


Dirac s theorem If (but not only if) G theorem: is connected, simple, has nu3 vertices, and v deg(v)un/2, then G has a Hamilton circuit.
Ore s corollary If G is connected, corollary: simple, has n 3 nodes, and deg(u)+deg(v) n for every pair u,v of non-adjacent nodes, then G has a Hamilton circuit.

60

HAMHAM-CIRCUIT is NP-complete NPLet HAM-CIRCUIT be the problem:


Given a simple graph G, does G contain a Hamiltonian circuit?

This problem has been proven to be NP-complete!


This means, if an algorithm for solving it in polynomial time were found, it could be used to solve all NP problems in polynomial time.

61

9.1 pg. 596 6, 8, 16, 26 9.2 pg. 608 8, 10, 20, 54 9.3 pg. 618 4, 8, 12, 14, 18, 22, 36, 40

62

FIN!
Tutorial Following week! 9.4 pg.629
4, 8, 14, 20, 24

9.5 pg.643
8, 14, 18, 24, 30, 32, 38, 42, 44

63

You might also like