0% found this document useful (0 votes)
29 views

GRAPH THEORY

Uploaded by

Poli Abrenica
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)
29 views

GRAPH THEORY

Uploaded by

Poli Abrenica
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/ 9

Lesson 6: Graph Theory (3,5), (4,0), (4,1), (4,2), (4,3), (4,5), (5,0),

(5,1), (5,2), (5,3), (5,4) }


• Graph Concepts.
• Euler’s Theorems and Fleury’s Algorithm. So bale icoconnect sa lahat
• Hamilton Circuits, Hamilton Paths, Traveling-
Example 3:
Salesman Problem.
• Spanning Trees and Kruskal’s Algorithm Let
• Graph Coloring
V = {0, 1, 2, 3, 4, 5},

𝐸3 = { (x, y) } | 0 < |x – y| ≤ 2 }
Graph Concepts
Let
Definition

Let V be a non-empty set, and E be any set of


ordered pairs over V. The pair (V , E) is called a
graph.
We denote a graph by G = (V , E). V is called the
vertex set of G and its elements as vertices, while
E is called the edge set of G and its elements as
edges. 𝐺3 = (V , 𝐸3 ) = { (0,1), (0,2), (1,0), (1,2), (1,3),
(2,0), (2,1), (2,3), (2,4), (3,1), (3,2), (3,4),
Example 1: (3,5), (4,2), (4,3), (4,5), (5,3), (5,4) }

Let
V = {0, 1, 2, 3, 4, 5}, (magiging means ng Definition
ating vertices)
Vertices are said to be adjacent if there is an edge
𝐸1 = { (x, y) } x and y are either both odd or that joins them. Edges are said to be adjacent if they
both even} share a common vertex.
Let The degree of a vertex is the number of edges at
𝐺1 =(V , 𝐸1 ) = { (0,0), (0,2), (0,4), (1,1), (1,3), that vertex.
(1,5), (2,0), (2,2), (2,4), (3,1), (3,3), (3,5),
Special Case: For graphs with loops, you have to
(4,0), (4,2), (4,4), (5,1), (5,3), (5,5) }
add 1 to the degree of the vertex with loops
0 connect sa sarili nya as even
1 as odd and connect sa odd din
Example 1:
Determine the degree of each Vertex 𝐺1
In this graph, a vertex is vertices of 𝐺1 . 0 4
adjacent to itself. Such 1 4
edges are called loops. 2 4
3 4
4 4
5 4
=24
12 edges + 12 for loop
Example 2:
= 24.
Let
V = {0, 1, 2, 3, 4, 5},
𝐸2 = { (x, y) } | x ≠ y }
𝐺1 = (𝑉, 𝐸1 )
Let
(0 is not adjacent to 1 and 5 because there is no
𝐺2 =(V , 𝐸2 ) = { (0,1), (0,2), (0,3), (0,4), (0,5), edge that connects them.)
(1,0), (1,2), (1,3), (1,4), (1,5), (2,0), (2,1),
Always remember add 1 sa loop.
(2,3), (2,4), (2,5), (3,0), (3,1), (3,2), (3,4),
Example 2: A-D-E-B-A
Determine the degree of each vertices of 𝐺2 . A-C-B-E-D-A

Vertex 𝐺2
Definition
0 5
1 5 A graph G is said to be connected if there is a path
2 5
joining any two of its vertices. Otherwise, it is said to
3 5
be disconnected.
4 5
5 5

Example: (connected graph) (kapag bawat vertices


connected sa isa’t isa)
𝐺2 = (𝑉, 𝐸2 )

Example 3:
Determine the degree of each vertices of 𝐺3

Vertex 𝐺3
0 2
1 3
2 4
3 4
Example: (disconnected graph)
4 3
5 2

𝐺3 = (𝑉, 𝐸3 )

Definition

Given a graph G = (V , E). A path in G is a sequence


of vertices with no repeated edges. A circuit in G is
a path that starts and ends at the same vertex.
Moreover, we can visualize graphs thru the following
models.
Consider the graph illustrated below. 1. In 1736, the attention of mathematician Leonhard
The following are Euler was caught by a simple puzzle: Is it possible
some paths: (hindi ka to walk around and cross all the seven bridges of the
uulit ng edges na old town of Konigsberg exactly once?
dadaanan)
A-B-E-D
A-B-C-A-D-E
A-B-C-B-E
A-C-B-E-E-D

Four small islands are connected by seven bridges


The following are not paths: (bumabalik sa edges as shown above in the left figure. Its graph
or umuulit) representation is shown above in the right figure.
A-C-A-D-E
A-B-C-B-A-D
A-D-E-E-D
A-B-C-B-E-E-D-A-C-B
The following are some circuits: (a path where
kung san ka nagstart, dun ka rin mageend)
A-B-C-A
2. Can you continuously trace this figure starting Example: Determine if there are Euler paths and
from any vertex such that you can only pass through Euler circuits in these graphs.
every edge and every vertex once without lifting your
pen?
In this graph, paths
E-A-B-C-A-D-G-F-D.
So, lahat nadaanan
ng edge. This is a
Euler path.
Is there an Euler
circuit? None

3. The table below shows the distances of towns


Alpra, Betra, Gamra at Deltra from each other, in km. In this graph, paths E-A-B-C-A-D-G-F-D and E-A-C-
B-A-D-G-F-D are Euler paths.
Alpra Betra Gamra Deltra
Alpra * 11 13 14
Betra 11 * 12 13 In this graph, paths
Gamra 13 12 * 15
D,G,F,D,A,C,B,A,E,D.
Deltra 14 13 15 *
So, this is a Euler
If a courier service personnel aims to drop packages
Circuit kase lahat ng
once in each town, what routing schedule can be
edges ay nadaanan
made so that he can travel the shortest distance?
and bumalik tayu sa
4. Suppose you are tasked to color a blank map of vertex na pinuntahan
Metro Manila in such a way that no two adjacent natin. And also this
cities will have the same color. What is the least path is a Euler path
number of colors you can use to complete this task?
Kapag may Euler circuit sa Graph may Euler path
din sya kase diba ang circuit is justly path.

Eulers Theorems and Fleury’s Algorithm In this graph, paths A-B-C-A-D-F-G-D-E-A and D-A-
C-B-A-E-D-G-F-D are Euler circuits.
Euler Path, Euler Circuit

Given a connected graph G. An edge in G is said to


be a bridge if G becomes disconnected when it is
deleted. Eulers Theorem 1
An Euler path is a path that travels through every 1. If a graph has any vertices of odd degree, then it
edge of G. cannot have an Euler circuit.
An Euler circuit is a circuit that travels through 2. If a graph is connected and every vertex has an
every edge of G. even degree, then it has at least one Euler circuit.

Example: Determine which of the following graphs Example: Determine if the given graph below has
has a bridge. an Euler circuit.
Vertices D and E have
odd degrees. Hence,
the given graph has no
Euler circuit.

𝐺1 has a bridge. 𝐺2 does not have a bridge.

All vertices have even


degrees. Hence, the
given graph has at least
one Euler circuit.
Example: Determine if the given graph below has Eulers Theorem 3
an Euler circuit.
1. The sum of the degrees of all the vertices of a
graph equals twice the number of edges.

2. The number of vertices of odd degree must be


Every vertex has an odd even.
degree. Hence, the given
graph has no Euler
circuit. Example: Consider the graph below.
number of vertices with
even degree: 5 (A,
B,C,G,F)
number of vertices with
Eulers Theorem 2 odd degree: 2 (E and
D)
1. If a graph has more than two vertices of odd
degree, then it cannot have an Euler path. number of edges: 8
sum of degrees of all
2. If a graph is connected and has just two vertices
vertices: 16 (E=1, A=4, B=2, C=2, D=3, F=2, G=2)
of odd degree, then it has at least one Euler path.
Any such path must start at one of the odd-degree
vertices and end at the other one.
number of vertices with
even degree: 7
Example: Determine if the given graph below has number of vertices with
an Euler path. odd degree: 0
There are only two number of edges: 9
vertices with odd
sum of degrees of all
degrees (D and E).
vertices: 18
Hence, the given graph
has at least one Euler
path.
number of vertices with
even degree: 0
number of vertices with
odd degree: 4
number of edges: 7
Every vertex has an even
degree. By Eulers sum of degrees of all
Theorem1, the given vertices: 14
graph has at least one
Euler circuit, thus, it has
an Euler path.

Fleury’s Algorithm for Finding Eulerian Circuit


(Dont cross the bridge until you have to)

Example: Determine if the given graph below has 1. Make sure that the graph is connected, and all
an Euler path. vertices have even degree.
2. Start at any vertex.
More than two vertices 3. Travel through an edge if:
have odd degrees. Hence,
3.1 it is not a bridge for the untraveled part, or
the given graph has no
Euler path. 3.2 there is no other alternative.
4. Label the edges in the order in which you travel
them.
5. When you can’t travel any more, stop.
Example: Using Fleury’s algorithm, and an Euler Example:
circuit.
Consider the given graph below.

Hamilton Circuits, Hamilton Paths, Traveling


Salesman Problem

Hamilton Path, Hamilton Circuit The path B-E-A-D-C is a Hamilton path.

Given a connected graph G. A Hamilton circuit is a The given graph has no Hamilton circuit.
circuit that passes through each vertex exactly once.

A Hamilton path is a path that passes through each Example:


vertex exactly once.
Consider the given graph below.
Example:
Consider the given graph below.

The given graph has neither Hamilton path nor


Hamilton circuit.
The path A-B-C-D-E is a Hamilton path.
The path A-B-C-D-E-A is a Hamilton circuit. Complete Graph

A graph 𝐾𝑛 with n vertices is said to be a complete


Example: graph if every vertex is adjacent to the other (n - 1)
vertices.
Consider the given graph below.
The following are examples of complete graphs.

1 vertices 2 vertices(1edge) 3 edges 4 vertices


(6edges)

Weighted Graph

A weighted graph is a graph whose edges have


assigned numbers. Such numbers are called
The path A-B-C-G-D-E-F is a Hamilton path. weights. Common weights are time, distance and
The path A-B-F-E-D-G-C-A is a Hamilton circuit. cost. Complete graphs that are weighted are simply
called complete weighted graphs.

The Traveling Salesman Problem.


Suppose that a salesman has to visit each of a
number of cities exactly once before returning to his
starting point. What is the shortest available route
through the cities?
Remarks. Consider this complete weighted graph.
1. Given a complete weighted graph, TSP asks for Example: Consider the given graph below. The
the circuit of minimum total weight in a graph that weights represent the cost of reaching one
visits each vertex exactly once and returns to its destination from another destination. Using the Brute
starting point. Force Method in this complete weighted graph,
determine all the Hamilton circuits starting at B and
2. The optimal solution for a TSP is a Hamilton circuit
its optimal solution.
for a complete weighted graph for which the sum of
the weights of the edges traversed is the smallest
possible number.

Consider this complete weighted graph.


The vertices represent 5 destinations, and the
weights represent the cost of reaching one
destination from another destination. Starting at any
destination, what is the optimal solution so that all
destinations will be reached exactly once and
returns to its starting point?

The least cost is 1 550 (optimal solution or maliit


na costs) and belongs to the Hamilton circuit A-
Three methods to determine a solution for a B-C-D-E-A.
Traveling Salesman Problem

• Brute Force Method


• Nearest Neighborhood Method The Nearest Neighbour Method (an approximate
solution)
• Cheapest Link Algorithm
1. Draw a complete weighted graph for the problem.
The Brute Force Method
2. Starting at a designated vertex, pick the edge with
1. Draw a complete weighted graph for the problem.
the smallest weight and move to the second vertex.
2. List all possible Hamilton circuits.
3. At the next vertex, pick the edge with smallest
3. Find the sum of the weights of the edges for each weight that doesn’t go to a vertex already used.
circuit.
4. Continue until the circuit is completed.
The circuit with the smallest sum is the optimal
The sum of the weights is an approximation to the
solution.
optimal solution.
Start at vertex A. The edge with the least cost from 1. A tree has no circuits.
A is A-B (200). Pick A-B
2. Trees are connected graphs.
From vertex B, the edge with the least cost, without
3. Every edge in a tree is a bridge.
returning to A, is B-C (310). Pick B-C.
4. A tree with n vertices has exactly (n - 1) edges.
From vertex C, the edge with the least cost, without
returning to B, is C-E(410). Pick C-E. Example:
From vertex E, the only vertex left not visited is D. The following are examples of trees with 6 vertices.
Pick E-D and then return to A. D-A.
The Hamilton circuit formed is A-B-C-E-D-A.
An approximate solution is the Hamilton circuit A-B-
C-E-D-A. with sum of costs
200+310+410+375+390=1685.

The Cheapest Link Algorithm

1. Draw a complete weighted graph for the problem.


2. Pick the edge with the smallest overall weight. In
case of a tie, pick at random.
Spanning Tree
3. Pick the edge with the next smallest overall weight
that doesnt: A spanning tree for a connected graph G of n
3.1 enclose a smaller circuit that doesn’t reach vertices is a connected subgraph that is a tree on n
every vertex or vertices.

3.2 result in three chosen edges coming from the A spanning tree for a graph is a tree that results from
same vertex. the removal of as many edges as possible from the
original graph without making it disconnected.
4. Repeat Step 2 until the Hamilton circuit is
complete
Example:
Find two different spanning trees for the graph
shown below.

The given graph has five


vertices, so a spanning
tree will have four edges.
Since the original graph
has six edges, we need
to remove two edges
without making the graph
disconnected.

200 = / 375 = / 510 = X


240 = / 410 = X
310 = / 415 = X
350 = X 425 = /
An approximate solution is the Hamilton circuit A-B-
C-D-E-A or A-E-D-C-B-A with cost
200+240+310+375+425=1550 units.

Spanning Trees and Kruskal’s Algorithm

Tree

A tree is a graph in which any two vertices are


connected by exactly one path.

Some properties of trees:


Minimum Spanning Tree Graph Coloring

A minimum spanning tree for a weighted graph Graph Coloring


is the spanning tree for that graph that has the
smallest possible sum of the weights. Graph coloring is a function that assigns either the
vertices or edges of a graph by a unique color (or
To find the underlying minimum spanning tree in a label). Graph coloring is speci ed as either vertex
connected graph, one may apply the so-called coloring or edge coloring depending on whether
Kruskal’s algorithm the vertices or the edges are labelled.

KRUSKAL’S ALGORITHM

To construct a minimum spanning tree for a Planar Graph


weighted graph:
A graph is said to be a planar graph if it can be
1. Choose the edge with the lowest weight (and drawn in a plane without the edges crossing.
highlight it in color). If there is more than one, pick
one at random. The graph below is a planar graph since it can be
drawn in a plane without the edges crossing.
2. Choose the unmarked edge with the next lowest
weight that does not form a circuit with the edges
already highlighted, (and highlight it).
3. Repeat until all vertices have been connected.

Example:
Determine the minimum spanning tree in this
weighted graph.
With the six vertices already chosen, we have the Chromatic Number
required minimum spanning tree highlighted:
Given a graph coloring problem, the smallest
14 = / 27 = /
number of colors needed to color a graph is called
18 = / 30 = X the chromatic number.

20 = / 31 = X
21 = / 32 = X The Four-Color Theorem
24 = X 35 = X Every possible geographical map can be colored
with at most four colors in such a way that no two
adjacent regions have the same color.

Two regions are called adjacent if they share a


border segment, not just a point.
To determine the chromatic number for a given
geographical map, it should be represented as a
graph where a vertex represents a region, and
vertices are adjacent if the region they represent are
adjacent in the map.

VERTEX COLORING ALGORITHM

1. Determine the vertex with the highest degree.


Assign to it the first color.
2. Also, assign the first color to all vertices that are
The sum of the weights is 14 +18+20+21+27 = 100 not adjacent to the first chosen vertex.
3. Among the remaining vertices, determine the
vertex with the highest degree. Assign to it the
second color.
4. Also, assign the second color to all vertices that
are neither adjacent to the second chosen vertex nor
to vertices that already received the second color.
5. Continue doing Steps 3 and 4 to until all vertices
are colored.
The number of colors used is the chromatic number.
Example:
Apply the Four-Color Theorem to determine the
chromatic number of the vertex coloring for the
graph below.

B = H, J, M (IKULAY SA MGA VERTICES NG HINDI


NYA ADJACENT)
Remaining is ung mga edges or degree na
nakaconnect
F = A, D, L, N
I = E, O, K, C
G
A=2
B=6
D=3
E=4
H =5
L=2
I=6
M=3
0=2
N=4
J=4
K=3
G=4
C=3
F=6

You might also like