You are on page 1of 74

DISMATH

Discrete Mathematics and Its Applications


Graph Theory
 Graph – discrete structures consisting of
vertices and edges that connect these vertices.
 A graph G = (V, E) consists of V, a nonempty set
of vertices (or nodes ) and E, a set of edges.
Each edge has either one or two vertices
associated with it, called its endpoints.
Applications:
 Networks (LAN, MAN, Social Networks, etc.)
 Job assignments
 Representing computational models
 Developing a bot to retrieve info off www
2
Terminology
 An isolated vertex is a vertex which has no
edges incident with it.
 A simple graph is a graph which has no loops or
multiple edges.
 A graph is complete if it has no loops and every
pair of distinct vertices is joined by a unique edge.
 A loop is an edge connecting a vertex with itself.
 A multigraph is an undirected graph that may
contain multiple edges but no loops.
 A pseudograph is an undirected graph that may
contain multiple edges and loops
3
Example
 Telephone network

4
Example
 Social network

5
Basic Terminology
 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.

deg(a) = 2 , deg(b) = deg(c) = deg(f ) = 4 deg(a) = 4, deg(b) = deg(e) = 6,


deg(d ) = 1 , deg(e) = 3 , and deg(g) = 0. deg(c) = 1 , and deg(d ) = 5

6
Handshaking Theorem
 Let G = (V, E) be an undirected graph with e
edges. Then
2e   deg  v 
vV

 Ex. How many edges are there in a graph with


10 vertices each of degree six?

 deg  v   6  10  60
vV

2e  60
e  30
7
Basic Terminology
 A subgraph of a graph G = (V, E) is a graph H
= (W, F), where W  V and F E . A subgraph
H of G is a proper subgraph of G if H  G.

G subgraph of G

8
Basic Terminology
 The union of two simple graphs G1 = (V1, E1)
and G2 = ( V2, E2) is the simple graph with
vertex set V1 U V2 and edge set E1 U E2 .

9
Paths
 A path is a sequence of edges that begins at a
vertex of a graph and travels from vertex to
vertex along edges of the graph.

 Is a, d, c, f, e a path?
 YES. {a , d}, {d, c} , {c, f}, and {f, e} are all edges
10
Paths
 A path is a sequence of edges that begins at a
vertex of a graph and travels from vertex to
vertex along edges of the graph.


 Is
. a, d, e, c, f a path?
 NO. because {e, c} is not an edge

11
Königsberg Problem
Find a
walk
through
the city
that
would
cross
each
bridge
once and
only once
12
Euler Circuit and Paths
 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 .

13
Drill
 Which of the undirected graphs have an Euler
circuit? Of those that do not, which have an
Euler path?

 G1 has an Euler circuit, for example, a , e, c, d, e, b, a.


Neither of the graphs G2 or G3 has an Euler circuit. G3
has an Euler path, namely, a , c, d, e, b, d, a , b.
 G2 does not have an Euler path
14
Euler Circuit and Paths
 A connected multigraph with at least two
vertices has an Euler circuit if and only if each
of its vertices has even degree.

Since it has four vertices of


odd degree, it does not
have an Euler circuit. There
is no way to start at a given
point, cross each bridge
exactly once, and return to
the starting point.

15
Euler Circuit and Paths
 A connected multigraph has an Euler path but
not an Euler circuit if and only if it has exactly
two vertices of odd degree.

 G1 contains exactly two vertices of odd degree,


namely, b and d. Hence, it has an Euler path that must
have b and d as its endpoints. One such Euler path is
d, a , b, c, d, b.
16
Euler Circuit and Paths
 G2 has exactly two vertices of odd degree, namely, b
and d. So it has an Euler path that must have b and d
as endpoints. One such Euler path is b, a , g, j, e, d, c,
g, b, c, j, d.
 G3 has no Euler path because it has six vertices of
odd degree.

17
Hamilton Paths and Circuits
 A simple path in a graph G that passes
through every vertex exactly once is called a
Hamilton path, and a simple circuit in a graph
G that passes through every vertex exactly
once is called a Hamilton circuit.

18
Example
 Hamilton Path or Circuit?

a b

d c

19
Example
 Hamilton Path or Circuit?

a b

d c

20
Drill
 Which of the simple graphs have a Hamilton
circuit or, if not, a Hamilton path?

 G1 has a Hamilton circuit: a, b, c, d, e, a. There is no


Hamilton circuit in G2 but it does have a Hamilton
path, namely, a , b, c, d. G3 has neither a Hamilton
circuit nor a Hamilton path, because any path
containing all vertices must contain one of the edges
{a, b}, {e, f}, and {c, d} more than once.
21
Matrices of Graphs
 The adjacency matrix A (or AG ) of G, with
respect to this listing of the vertices, is the nxn
zero-one matrix with 1 as its (i, j)th entry when
vi and vj are adj acent, and 0 as its (i, j)th entry
when they are not adjacent

ai,j  {
1 if (vi ,v j ) is an edge
0

22
Example
 Use an adjacency matrix to represent the
following graph.

23
Isomorphism of Graphs
 Simple graphs G1 = (V1, E1) & G2 = (V2, E2)
are isomorphic if there is a one-to-one and
onto 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
in V1 .

24
Visualization
 Twist or bend

25
Example
 The function f with f(u1) = V1, f(u2) = V4 , f(u3)
= V3 , and f(u4) = V2 is a one-to-one
correspondence between V and W.
 Adjacent vertices in G are u1 and u2 , u1 and
u3, u2 and u4, and u3 and u4, and each of the
pairs f(u1) = V1 and f(u2) = V4, f(u1) = V1 and
f(u3) = V3 , f(u2) = V4 and f(u4) = V2 , and
f(u3) = V3 and f(u4) = V2 are adjacent in H.

26
Dijkstra’s Algorithm Definitions
• Find shortest paths from given source node to all other nodes,
by developing paths in order of increasing path length
N= set of nodes in the network
s= source node
T= set of nodes so far incorporated by the algorithm
• w(i, j) = link cost from node i to node j
– w(i, i) = 0
– w(i, j) =  if the two nodes are not directly connected
– w(i, j)  0 if the two nodes are directly connected
• L(n) = cost of least-cost path from node s to node n currently
known
– At termination, L(n) is cost of least-cost path from s to n
Dijkstra’s Algorithm Method
• Step 1 [Initialization]
– T = {s} Set of nodes so far incorporated consists of only
source node
– L(n) = w(s, n) for n ≠ s
– Initial path costs to neighboring nodes are simply link
costs
• Step 2 [Get Next Node]
– Find neighboring node not in T with least-cost path
from s
– Incorporate node into T
– Also incorporate the edge that is incident on that node
and a node in T that contributes to the path
Dijkstra’s Algorithm Method
• Step 3 [Update Least-Cost Paths]
– L(n) = min[L(n), L(x) + w(x, n)] for all n  T
– If latter term is minimum, path from s to n is path
from s to x concatenated with edge from x to n

• Algorithm terminates when all nodes have been


added to T
• At termination, value L(x) associated with each node x
is cost (length) of least-cost path from s to x.
Example
Dijkstra’s Algorithm Results
Ite T L(2) Path L(3) Path L(4) Path L(5) Path L(6) Path
rat
ion
1 {1} 2 1–2 5 1-3 1 1–4  -  -

2 {1,4} 2 1–2 4 1-4-3 1 1–4 2 1-4–5  -

3 {1, 2, 4} 2 1–2 4 1-4-3 1 1–4 2 1-4–5  -

4 {1, 2, 4, 2 1–2 3 1-4-5–3 1 1–4 2 1-4–5 4 1-4-5–6


5}

5 {1, 2, 3, 2 1–2 3 1-4-5–3 1 1–4 2 1-4–5 4 1-4-5–6


4, 5}

6 {1, 2, 3, 2 1-2 3 1-4-5-3 1 1-4 2 1-4–5 4 1-4-5-6


4, 5, 6}
Example
• Apply Dijkstra’s Algorithm to the ff. topology:
Solution
Solution
Planar Graphs
• Planar graph – are graphs that can be drawn
in the plane without edges having to cross.

• Any graph representation of maps/


topographical information is planar.
– graph algorithms often specialized to planar
graphs (e.g. traveling salesman)
• Circuits usually represented by planar graphs
– PCB circuit design

36
Example
• Are the following graphs planar?

37
Drill
• Is the following graph planar?

38
Drill
• Is the following graph planar?

39
Drill
• Is the following graph planar?

40
Drill
• Is the following graph planar?

41
Drill
• Is the following graph planar?

42
Drill
• Is the following graph planar?

43
Drill
• Is the following graph planar?

44
Drill
• Is the following graph planar?

45
Drill
• Is the following graph planar?

YES

46
Example
• Is the following graph planar?

47
Example
• Is the following graph planar?

48
Euler's Formula
• Let G be a connected planar simple graph
with e edges and v vertices. Let r be the
number of regions in a planar
representation of G . Then
r=e-v+2
• A planar representation of a graph splits the
plane into regions, including an unbounded
region.

49
Example
• Suppose that a connected planar simple graph
has 20 vertices, each of degree 3 . Into how
many regions does a representation of this
planar graph split the plane?
r=e-v+2

2e   deg  v 
vV r=e-v+2
2e  3  20  = 30 – 20 + 2
= 12
e  30
50
Homeomorphic Graphs
• Elementary subdivision - If a graph is planar, so
will be any graph obtained by removing an
edge { u, v} and adding a new vertex w
together with edges { u, w } and {w, v} .
• The graphs G1= ( V1, E1 ) and G2 = ( V2 , E2) are
called homeomorphic if they can be obtained
from the same graph by a sequence of
elementary subdivisions.

51
Example
• Show that the graphs G1, and G2 are
homeomorphic.

52
Kuratowski's Theorem
• A graph is nonplanar if and only if it contains a
subgraph homeomorphic to the following
graphs.

53
Example
• Determine whether graph G is planar.

54
Example
• Is the Petersen graph shown below planar?

55
Graph Coloring

56
Colored Graphs
• A coloring of a simple graph is the assignment of
a color to each vertex of the graph so that no two
adjacent vertices are assigned the same color.
• The chromatic number of a graph c(G) is the least
number of colors needed for a coloring of this
graph.
• The best algorithms known for finding the
chromatic number of a graph have exponential
worst-case time complexity
57
FOUR COLOR THEOREM
• The chromatic number of a planar graph is no
greater than four.

• Note that the Four Color Theorem applies only to planar graphs.
Nonplanar graphs can have arbitrarily large chromatic numbers.

58
Graph Coloring

59
Example
• What is the chromatic numbers of the graphs
G?

c(G) = 3

60
Example
• What is the chromatic numbers of the graphs
H?

c(G) = 4

61
Trees
• A tree is a connected undirected graph with
no simple circuits.
• It is a data structure that emulates a
hierarchical tree structure with a set of
linked nodes.

62
Why study Trees?
• used to construct efficient algorithms for
locating items in a list (binary search trees…)
• used in algorithms, such as Huffman coding,
that construct efficient codes saving costs in
data transmission and storage
• used to study games such as checkers and chess
and can help determine winning strategies for
playing these games
• used to model procedures carried out using a
sequence of decisions
• etc.
63
Example
• Which of the graphs shown below are trees?

G1 G2 G3 G4

64
Example
• Which of the graphs shown below are trees?

Tree Tree NOT a Tree NOT a Tree

65
Rooted Tree
• Rooted Tree - a tree in which one vertex has
been designated as the root and every edge is
directed away from the root.

66
Example
• In the rooted tree T
(with root a) shown
below, find the parent
of c, the children of g,
the siblings of h , all
ancestors of e, all
descendants of b, all
internal vertices, and
all leaves.
• What is the subtree
rooted at g?
67
Example
• In the rooted tree T (with root a) shown below,
find the parent of c, the children of g, the
siblings of h , all ancestors of e, all descendants
of b, all internal vertices, and all leaves.
• The parent of c is b.
• The children of g are h, i, and j.
• The siblings of h are i and j.
• The ancestors of e are c, b, and a.
• The descendants o f b are c, d, and e.
• The internal vertices are a, b, c, g, h, and j.
• The leaves are d, e, f, i , k, I, and m.

68
Example
• What is the subtree rooted at g?

69
m-ary tree
• A rooted tree is called an m-ary tree if every
internal vertex has no more than m children.
The tree is called a full m-ary tree if every
internal vertex has exactly m children.
• An m –ary tree with m = 2 is called a binary
tree.

Full 5-ary tree n/a


Full binary tree Full 3-ary tree

70
Ordered rooted tree
• Ordered rooted tree - a rooted tree where the
children of each internal vertex are ordered.
• Ex. What are the left and right children of d in
the binary tree T shown below (where the
order is that implied by the drawing)? What
are the left and right subtrees of c?

LEFT RIGHT

71
Applications
• Trees as models (Ex. Representing Organizations)

72
Tree Example-Linux Directory

73
\end

74

You might also like