You are on page 1of 56

Graphs

WIC3001/WRES2109
Dr. Saaidal Razalli Bin Azzuhri

 © 2019 McGraw-Hill Education. All rights reserved. Authorized only for instructor use in the classroom. No reproduction or further distribution permitted without the prior written consent of
Shortest-Path Problems
Planar Graphs
Graph Coloring
Weighted Graphs
Graphs that have a number assigned to
each edge are called weighted graphs. BOS

CHI NY
SF DEN

ATL
LA

MIA
Weighted Graphs
MILES

BOS
2534

1855 722 NY
CHI
SF DEN 908
957

349
ATL
LA 595
MIA
Weighted Graphs
FARES

BOS
$129
$39
$99 $59 NY
CHI
SF DEN
$89

$39
ATL
LA

MIA
Weighted Graphs
FLIGHT
TIMES

BOS
4:05
0:50
2:55 NY
CHI 1:50
SF DEN 2:10
2:20

1:15
ATL
LA

MIA
Weighted Graphs

 A weighted graph is a graph in which each edge (u,


v) has a weight w(u, v). Each weight is a real
number.
 Weights can represent distance, cost, time,
capacity, etc.
 The length of a path in a weighted graph is the sum
of the weights on the edges.
 Dijkstra’s Algorithm finds the shortest path between
two vertices.
Dijkstra's Algorithm
Problem: shortest path from a to z

b 5 d 5 f
4 7
4 3 1
a 2 z
3 4
c 5 e 5 g
Theorems
Dijkstra’s algorithm finds the length of a shortest
path between two vertices in a connected simple
undirected weighted graph G=(V,E).
The Traveling Salesman Problem

The traveling salesman problem is one of the classical problems


in computer science.
A traveling salesman wants to visit a number of cities and then
return to his starting point. Of course he wants to save time and
energy, so he wants to determine the shortest cycle for his trip.
We can represent the cities and the distances between them by a
weighted, complete, undirected graph.
The problem then is to find the shortest cycle (of minimum total
weight that visits each vertex exactly one).
Finding the shortest cycle is different than Dijkstra’s shortest path.
It is much harder too, no polynomial time algorithm exists!
The Traveling Salesman Problem
 Importance:
 Variety of scheduling application can be solved as a
traveling salesmen problem.
 Examples:
 Ordering drill position on a drill press.
 School bus routing.
 The problem has theoretical importance because it
represents a class of difficult problems known as NP-hard
problems.
THE FEDERAL EMERGENCY MANAGEMENT AGENCY

 A visit must be made to four local offices


of FEMA, going out from and returning to
the same main office in Northridge,
Southern California.
FEMA traveling salesman
Network representation
2 40
3
25 35
50 40
50
1
4
45 65

30 80

Home
FEMA - Traveling Salesman
• Solution approaches
– Enumeration of all possible cycles.
• This results in (m-1)! cycles to enumerate for a graph with m
nodes.
• Only small problems can be solved with this approach.
FEMA – full enumeration

Possible cycles
Cycle Total Cost
For this problem 1. H-O1-O2-O3-O4-H 210
we have
Minimum
2. H-O1-O2-O4-O3-H 195
(5-1)! / 2 = 12 3. H-O1-O3-O2-O3-H 240
cycles. 4. H-O1-O3-O4-O2-H 200
Symmetrical 5. H-O1-O4-O2-O3-H 225
problems
6. H-O1-O4-O3-O2-H 200
need to
7. H-O2-O3-O1-O4-H 265
enumerate only
(m-1)! / 2 cycles. 8. H-O2-O1-O3-O4-H 235
9. H-O2-O4-O1-O3-H 250
10. H-O2-O1-O4-O3-H 220
11. H-O3-O1-O2-O4-H 260
12. H-O3-O1-O2-O4-H 260
FEMA – optimal solution

2 40
3
25 50 35
40
1 50 4
45 65
30 80

Home
The Traveling Salesman Problem

Unfortunately, no algorithm solving the traveling salesman problem


with polynomial worst-case time complexity has been devised yet.
This means that for large numbers of vertices, solving the traveling
salesman problem is impractical.
In these cases, we can use efficient approximation algorithms
that determine a path whose length may be slightly larger than the
traveling salesman’s path, but
Planar Graphs
 A graph (or multigraph) G is called planar if G can be drawn in the plane with
its edges intersecting only at vertices of G, such a drawing of G is called an
embedding of G in the plane.

Application Example: VLSI design (overlapping edges requires extra layers),


Circuit design (cannot overlap wires on board)

Representation examples: K1,K2,K3,K4 are planar, Kn for n>4 are non-


planar

K4
Planar Graphs
 Representation examples: Q3
Planar Graphs
 Representation examples: K3,3 is Nonplanar

v1 v2 v3 v1 v5 v1 v5

R21
R2 R1
R1 R22
v3

v4 v5 v6 v4 v2 v4 v2
Planar Graphs
Theorem : Euler's planar graph theorem
For a connected planar graph or multigraph:
v–e+r=2

number
number number of regions
of vertices of edges
Planar Graphs
Example of Euler’s theorem

A planar graph divides the plane


R1 into several regions (faces), one
K4 R4
R2 of them is the infinite region.

v=4,e=6,r=4, v-e+r=2
R3
Planar Graphs
 Proof of Euler’s formula: By Induction
Base Case: for G1 , e1 = 1, v1 = 2 and r1= 1

v
u
R1

n+1 Case: Assume, rn = en – vn + 2 is true. Let {an+1, bn+1} be the edge


that is added to Gn to obtain Gn+1 and we prove that rn = en – vn + 2 is
true. Can be proved using two cases.
Planar Graphs
 Case 1:

rn+1 = rn + 1, en+1 = en + 1, vn+1 = vn => rn+1 = en+1 – vn+1 + 2

an+1

bn+1
Planar Graphs
 Case 2:

rn+1 = rn, en+1 = en + 1, vn+1 = vn + 1 => rn+1 = en+1 – vn+1 + 2

an+1

R
bn+1
Planar Graphs
Corollary 1: Let G = (V, E) be a connected simple planar graph with e edges and
v vertices where v ≥ 3, then e ≤ 3v – 6
Proof: A connected planar simple graph drawn in the plane divides the plane into
regions, say r of them. The degree of each region is at least three. (Because the
graphs discussed here are simple graphs, no multiple edges that could produce
regions of degree two, or loops that could produce regions of degree one, are
permitted.) In particular, note that the degree of the unbounded region is at least
three because there are at least three vertices in the graph..
Degree of region: In a planar embedding of a connected graph, the number of
edges bordering region is called the degree of the region, counting bridges, if any,
twice.

an+1

R
bn+1
Region Degree

R Degree of R = 3

Degree of R = ?

R
Planar Graphs
Planar Graphs

Example: show that K5 is nonplanar using Corollary 1.

Solution:
The graph K5 has five vertices and 10 edges. However, the inequality e
≤ 3v − 6 is not satisfied for this graph because e = 10 and 3v − 6 = 9.
Therefore, K5 is not planar.
Planar Graphs
Corollary 2: Let G = (V, E) be a connected simple planar graph then
G has a vertex degree that does not exceed 5
Proof: If G has one or two vertices the result is true
If G has 3 or more vertices then by Corollary 1, e ≤ 3v – 6
2e ≤ 6v – 12
If the degree of every vertex were at least 6:
by Handshaking theorem: 2e = Sum (deg(v))
 2e ≥ 6v. But this contradicts the inequality 2e ≤ 6v – 12
There must be at least one vertex with degree no greater than 5
Planar Graphs
Corollary 3: Let G = (V, E) be a connected simple planar graph with
v vertices ( v ≥ 3) , e edges, and no circuits of length 3 then e ≤ 2v
-4

Example: Show that K3,3 is nonplanar using Corollary 3

Solution: Because K3,3 has no circuits of length three (this is easy to


see because it is bipartite), Corollary 3 can be used. K3,3 has six
vertices and nine edges. Because e = 9 and 2v − 4 = 8, Corollary 3
shows that K3,3 is nonplanar.
Planar Graphs
 Elementary sub-division: Operation in which a graph are obtained
by removing an edge {u, v} and adding the vertex w and edges {u, w},
{w, v}

u v u w v

 Homeomorphic Graphs: Graphs G1 and G2 are termed as


homeomorphic if they are obtained by sequence of elementary sub-
divisions.
Planar Graphs
Planar Graphs
Show that the graphs G1, G2 and G3 are all homeomorphic

Solution: These three graphs are homeomorphic because all three can be obtained from
G1 by elementary subdivisions. G1 can be obtained from itself by an empty sequence of
elementary subdivisions. To obtain G2 from G1 we can use this sequence of elementary
subdivisions:
 (i ) remove the edge {a, c}, add the vertex f , and add the edges {a, f } and {f, c};
 (ii ) remove the edge {b, c}, add the vertex g, and add the edges {b, g} and {g, c}; and
 (iii ) remove the edge {b, g}, add the vertex h, and add the edges {g, h} and {b, h}.
Kuratowski Theorem
A graph is nonplanar if and only if it contains a
subgraph homeomorphic to K3,3 or K5.

The intuition: homeomorphism is like graph isomorphism after ignoring


some of degree 2 nodes. Example: after ignoring nodes d, e, f in graph H,
H is isomorphic to K5.

44
Chapter 10.8
Graph Coloring

These class notes are based on material from our


textbook, Discrete Mathematics and Its
Applications, 8th ed., by Kenneth H. Rosen. They are
intended for classroom use only and are not a
substitute for reading the textbook.
Introduction

 When a map is colored, two regions with a


common border are customarily assigned
different colors.
 We want to use the smallest number of
colors instead of just assigning every region
its own color.
4-Color Map Theorem
 It can be shown that any two-dimensional
map can be painted using four colors in
such a way that adjacent regions (meaning
those which sharing a common boundary
segment, and not just a point) are different
colors.
Map Coloring

 Four colors are sufficient to color a map of the contiguous


United States.
 Source of map: http://www.math.gatech.edu/~thomas/FC/fourcolor.html
Dual Graph
 Each map in a plane can be represented by a
graph.
 Each region is represented by a vertex.
 Edges connect to vertices if the regions
represented by these vertices have a common
border.
 Two regions that touch at only one point are not
considered adjacent.
 The resulting graph is called the dual graph
of the map.
Dual Graph Examples

B
B G A
C D
A F C
D E
E

b
b
c

a d f g a c e

e d
Graph Coloring
 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 is the least
number of colors needed for a coloring of the
graph.
 What is the chromatic number of a bipartite
graph?
The Four Color Theorem
 The chromatic number of a planar graph is no
greater than four.
It was originally posed as a conjecture in the 1850s.
It was finally proved by two American mathematicians
Kenneth Apple and Wolfgang Haken in 1976.
This is the first mathematical theorem
that has been proven with help of computers.
They showed that if the theorem is false, there must be a counterexample
of one of approximately 2000 types.
They used computers to show that none of these counterexamples exists.
Example
• What is the chromatic number of the graph
shown below?
The chromatic number
must be at least 3 since
b e
a, b, and c must be
a d g
assigned different colors.
So Let’s try 3 colors first.
c f
3 colors work, so the
chromatic number of this
graph is 3.
Example
 What is the chromatic number for each of
the following graphs?

White
White Yellow

Green Yellow
Yellow White

White Yellow Yellow White

Chromatic number: 2 Chromatic number: 3


Time Complexity
The best algorithms known for finding the chromatic
number of a graph have exponential
worst-case time complexity (in the number of vertices of
the graph).

Even the problem of finding an approximation to the


chromatic number of a graph is difficult.

This explains why scheduling final exams is so


difficult, i.e., how can the final exams at a university be
scheduled so that no student has two exams at the same
time?
Scheduling Final Exams
How can the final exams at a university be scheduled so that no student has two
exams at the same time? For instance, suppose there are seven finals to be
scheduled. Suppose the courses are numbered 1 through 7. Suppose that the
following pairs of courses have common students: 1 and 2, 1 and 3, 1 and 4, 1 and
7, 2 and 3, 2 and 4, 2 and 5, 2 and 7, 3 and 4, 3 and 6, 3 and 7, 4 and 5, 4 and 6, 5
and 6, 5 and 7, and 6 and 7.

Solution:

The graph representing the Using a coloring to


scheduling of final exams schedule final exams

You might also like