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

Module9 Graphs

The document outlines the content of Week 10 of a course on Discrete Mathematics in Computer Science, focusing on graphs and their applications. It covers definitions, types of graphs, shortest-path problems, Dijkstra's algorithm, planar graphs, and graph coloring. The material is intended to enhance understanding of graph theory and its practical uses in various fields, including computer networks and social networks.

Uploaded by

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

Module9 Graphs

The document outlines the content of Week 10 of a course on Discrete Mathematics in Computer Science, focusing on graphs and their applications. It covers definitions, types of graphs, shortest-path problems, Dijkstra's algorithm, planar graphs, and graph coloring. The material is intended to enhance understanding of graph theory and its practical uses in various fields, including computer networks and social networks.

Uploaded by

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

‫الجامعة السعودية االلكترونية‬

‫الجامعة السعودية االلكترونية‬

‫‪26/12/2021‬‬
College of Computing and
Informatics
BS in Computer Science
CS243
Discrete Mathematics in Computer Science
Discrete Mathematics in Computer Science

Week 10

Chapter 10: Graphs


Contents

10.1 Graphs and Graph Models

10.6 Shortest-Path Problems

10.7 Planar Graphs

10.8 Graph Coloring


Weekly Learning Outcomes

• Illustrate examples to highlight the use of graphs

and explain graph theory.

• Learn to Solve Shortest Path Problems

• Study the applications of Graphs such as Planar

Graphs
Required Reading
1. Chapter 10; 10.1, 10.6 – 10.8 “Discrete Mathematics and Its
Application”
2. Chapter 10 Key Terms and Results
Recommended Reading
Difference between graph and tree
https://www.geeksforgeeks.org/difference-between-graph-and-tree/

Recommended videos
Discrete Mathematics 1: Introduction to Graphs
https://www.youtube.com/watch?v=PLU1sLuVnKI

This Presentation is mainly dependent on the textbook: Discrete Mathematics and Its Application by Kenneth H. Rosen
10.1 Graphs and Graph Models
• Definition 1: 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; an edge is
said to connect its endpoints.

• Remark 1: The set of vertices V of a graph G may be infinite. A graph with an infinite vertex set or an
infinite number of edges is called an infinite graph, and in comparison, a graph with a finite vertex set
and a finite edge set is called a finite graph. In this book, we will usually consider only finite graphs.

 Remark 2: A graph in which each edge connects two different vertices and where no two edges
connect the same pair of vertices is called a simple graph.
 Note that in a simple graph, each edge is associated with an unordered pair of vertices, and no other edge is associated
with this same edge. Consequently, when there is an edge of a simple graph associated with {u, v}, we can also say,
without possible confusion, that {u, v} is an edge of the graph.
Graphs and Graph Models
• Now suppose that a network is made up of data centers and communication links between

computers. We can represent the location of each data center by a point and each communications

link by a line segment, as shown in Figure 1.

• The following computer network can be

modeled using a graph in which the vertices

of the graph represent the data centers and

the edges represent communication links.

• In general, we visualize graphs by using points to represent vertices and line segments, possibly

curved, to represent edges, where the endpoints of a line segment representing an edge are the

points representing the endpoints of the edge.


Graphs and Graph Models- multigraphs

• A computer network may contain multiple links between data centers, as shown in Figure
2. To model such networks, we need graphs that have more than one edge connecting
the same pair of vertices. Graphs that may have multiple edges connecting the same
vertices are called multigraphs.

• When there are m different edges


associated with the same unordered
pair of vertices {u, v}, we also say that
{u, v} is an edge of multiplicity m. That
is, we can think of this set of edges as m
different copies of an edge {u, v}.
Graphs and Graph Models- loops & pseudographs

• Sometimes a communications link connects a data center with itself, perhaps a feedback
loop for diagnostic purposes. Such a network is illustrated in Figure 3. To model this network,
we need to include edges that connect a vertex to itself. Such edges are called loops.

• Sometimes we may even have


more than one loop at a vertex.
Graphs that may include loops, and
possibly multiple edges connecting
the same pair of vertices or a
vertex to itself, are sometimes
called pseudographs.
Graphs and Graph Models- undirected graphs
• So far, the graphs we have introduced are undirected graphs. Their edges are also said to
be undirected edges.

• However, to construct a graph model, we may find it necessary to


assign directions to the edges of a graph. For example, in a computer
network, some links may operate in only one direction (such links are
called
• Thissingle
may beduplex lines).
the case if there is a large
amount of traffic sent to some data centers,
with little or no traffic going in the opposite
direction. Such a network is shown in Figure
4.
Graphs and Graph Models- Directed graph

• Definition 2 A directed graph (or digraph) (V, E) consists of a nonempty set of vertices V and a
set of directed edges (or arcs) E.

Each directed edge is associated with an ordered pair of vertices. The directed edge
associated with the ordered pair (u, v) is said to start at u and end at v.

• When a directed graph has no loops and has no multiple directed edges, it is called a
simple directed graph.

• Directed graphs that may have multiple directed edges are called directed multigraphs.

• A graph with both directed and undirected edges is called a mixed graph.
Graphs and Graph Models- Graphs
10.1.1 Graph Models

• Graphs are used in a wide variety of models.

• Social Networks: Graphs are extensively used to model social structures based on
different kinds of relationships between people or groups of people. These social
structures, and the graphs that represent them, are known as social networks.
Graph Models

• Acquaintanceship [‫]التعارف‬ and Friendship Graphs We can


use a simple graph to represent whether two people
know each other, that is, whether they are friends or
acquainted (either in the real world or in the virtual
world via a social networking site such as Facebook).

• Influence Graphs In studies of group behavior it is observed that


certain people can influence the thinking of others. A directed graph
called an influence graph can be used to model this behavior.
10.6 Shortest-Path Problems
• Many problems can be modeled using graphs with
weights assigned to their edges.

• Graphs that have a number assigned to each edge


are called weighted graphs.
• E.g: Weighted graphs are used to model computer networks.
• Communications costs (such as the monthly cost of
leasing/rental a telephone line), the response times of the
computers over these lines, or the distance between
computers, can all be studied using weighted graphs.

• The length of a path in a weighted graph is the sum


of the weights of the edges of this path.
10.6.2: A Shortest-Path
Algorithm
• There are several different algorithms that find the shortest path between two
vertices in a weighted graph.

• Example 1 What is the length of the shortest path between a and z in the weighted

graph shown in Figure 3?

SOLUTION: There are three such paths, a, b, c, z of length 7


& a, d, e, z of length 6, and a, b, e, z of length 8.
Because the shorter path from a to z is a, d, e, z, then
The length of the shortest path from a to z is
6. brute force approach is impractical for humans and
This
even for computers for graphs with a large number of edges.
Dijkstra’s algorithm
• We will now consider the general problem of finding the length of the shortest path
between a and z in an undirected connected simple weighted graph. Dijkstra’s algorithm
proceeds by finding the length of the shortest path from a to a first vertex, the length of the
shortest path from a to a second vertex, and so on until the length of the shortest path from
a to z is found.
• As a side benefit, this algorithm is easily extended to find the length of the shortest path
from a to all other vertices of the graph, and not just to z.
• The algorithm relies on a series of iterations. A distinguished set of vertices is constructed by
adding one vertex at each iteration. A labeling procedure is carried out at each iteration.

• We now give the details of Dijkstra’s algorithm. It begins by labeling a with 0 and the other
vertices with ∞. We use the notation L0(a) = 0 and L0(v) = ∞ for these labels before any
iterations have taken place (the subscript 0 stands for the “0th” iteration).
• These labels are the lengths of shortest paths from a to the vertices, where the paths contain
only the vertex a. (Because no path from a to a vertex different from a exists, ∞ is the length of
the shortest path between a and this vertex.)
Dijkstra’s algorithm
• Dijkstra’s algorithm proceeds by forming a distinguished set of vertices. Let Sk denote this set

after k iterations of the labeling procedure. We begin with S0 = ∅. The set Sk is formed from

Sk−1 by adding a vertex u not in Sk−1 with the smallest label.

• Once u is added to Sk, we update the labels of all vertices not in Sk, so that Lk(v), the label of
the vertex v at the kth stage, is the length of the shortest path from a to v that contains
vertices only in Sk (that is, vertices that were already in the distinguished set together with
u).
• Note that the way we choose the vertex u to add to Sk at each step is an optimal choice at each step, making
this a greedy algorithm. (We will prove shortly that this greedy algorithm always produces an optimal
solution.)
Dijkstra’s algorithm
• Dijkstra’s algorithm proceeds by forming a distinguished set of vertices. Let Sk denote this set

after k iterations of the labeling procedure. We begin with S0 = ∅. The set Sk is formed from

Sk−1 by adding a vertex u not in Sk−1 with the smallest label.

• Once u is added to Sk, we update the labels of all vertices not in Sk, so that Lk(v), the label of
the vertex v at the kth stage, is the length of the shortest path from a to v that contains
vertices only in Sk (that is, vertices that were already in the distinguished set together with
u).
• Note that the way we choose the vertex u to add to Sk at each step is an optimal choice at each step, making
this a greedy algorithm. (We will prove shortly that this greedy algorithm always produces an optimal
solution.)
Dijkstra’s algorithm
• Let v be a vertex not in Sk. To update the label of v, note that Lk(v) is the length of the

shortest path from a to v containing only vertices in Sk. The updating can be carried out
efficiently when this observation is used: The shortest path from a to v containing only
elements of Sk is either the shortest path from a to v that contains only elements of Sk−1 (that
is, the distinguished vertices not including u), or it is the shortest path from a to u at the (k −
1)st stage with the edge {u, v} added. In other words,
L k (a, v) = min{L k − 1 (a, v), L k − 1 (a, u) + w(u, v)} ,

where w(u, v) is the length of the edge with u and v as endpoints. This procedure is iterated
by successively adding vertices to the distinguished set until z is added. When z is added to
the distinguished set, its label is the length of the shortest path from a to z.
Dijkstra’s algorithm
Dijkstra’s algorithm

• EXAMPLE 2 Use Dijkstra’s algorithm to find the length of the shortest path between
the vertices a and z in the weighted graph displayed in Figure 4(a).
Dijkstra’s algorithm
 Solution: The steps used by Dijkstra’s
algorithm to find the shortest path
between a and z are shown in Figure 4.

• At each iteration of the algorithm the


vertices of the set Sk are circled.

• A shortest path from a to each vertex


containing only vertices in Sk is
indicated for each iteration.

• The algorithm terminates when z is


circled.

• We find that a shortest path from a to z


is a, c, b, d, e, z, with length 13.
Dijkstra’s algorithm
Exercises: Find the length of the shortest path between a and z in the
given weighted graph.
10.7 Planar Graphs
• Definition 1 A graph is called planar if it can be drawn in the plane without any edges
crossing (where a crossing of edges is the intersection of the lines or arcs
representing them at a point other than their common endpoint). Such a drawing is
called a planar representation of the graph.
• A graph may be planar even if it is usually drawn with crossings, because it may be possible to draw it in a
different way without crossings.

EXAMPLE 1 Is K4 (shown in Figure 2 with two edges crossing) planar?


Solution: K4 is planar because it can be drawn without crossings, as
shown in Figure 3.
10.7 Planar Graphs
• EXAMPLE 2 Is Q3, shown in Figure 4, planar?
• Solution: Q3 is planar because it can be drawn without any edges crossing, as shown
in Figure 5.
10.7.2 Euler’s Formula
• A planar representation of a graph splits the plane into regions, including an
unbounded region.

• For instance, the planar representation of the graph shown in Figure 8 splits the plane into
six regions. These are labeled in the figure. Euler showed that all planar representations of a
graph split the plane into the same number of regions.
• He accomplished this by finding a relationship among the number of regions, the number of
vertices, and the number of edges of a planar graph.
10.7.2 Euler’s Formula
• 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.

EXAMPLE 4 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?

• Solution: This graph has 20 vertices, each of degree 3, so v = 20.


Because the sum of the degrees of the vertices, 3v = 3 ⋅ 20 = 60, is
equal to twice the number of edges, 2e, we have 2e = 60, or e = 30.
Consequently, from Euler’s formula, the number of regions is r = e − v +
2 = 30 − 20 + 2 = 12.
10.7.2 Euler’s Formula
Textbook
Page757+758
• COROLLARY 1 If G is a connected planar simple graph with e edges and v vertices, where v
≥ 3, then e ≤ 3v − 6.

• COROLLARY 2 If G is a connected planar simple graph, then G has a vertex of degree not
exceeding five.

• EXAMPLE 5 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
10.8 Graph Coloring

• Definition 1 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.
• A graph can be colored by assigning a different color to each of its vertices. However, for most
graphs, coloring can be found that uses fewer colors than the number of vertices in the graph.

• What is the least number of colors necessary?


• Definition 2 The chromatic number of a graph is the least number of colors needed for
coloring this graph. The chromatic number of a graph G is denoted by 𝜒(G). (Here 𝜒 is the
Greek letter chi.)
Graph Coloring
• THEOREM 1 THE FOUR COLOR THEOREM The chromatic number of a planar graph is no
greater than four.

• EXAMPLE What are the chromatic numbers of the graphs G shown in Figure 3?
• Solution: The chromatic number of G is at least three because the vertices a, b, and c must
be assigned different colors.
• To see if G can be colored with three colors, assign red to a, blue to b,
and green to c. Then, d can (and must) be colored red because it is
adjacent to b and c.
• Furthermore, e can (and must) be colored green because it is adjacent
only to vertices colored red and blue, and f can (and must) be colored
blue because it is adjacent only to vertices colored red and green.
• Finally, g can (and must) be colored red because it is adjacent only to
vertices colored blue and green. This produces a coloring of G using
exactly three colors.
Graph Coloring
• THEOREM 1 THE FOUR COLOR THEOREM The chromatic number of a planar graph is
no greater than four.

• EXAMPLE What are the chromatic numbers of the graphs H shown in Figure 4?
• Solution:
• The graph H is made up of graph G with an edge connecting a and g.
• Any attempt to color H using three colors must follow the same
reasoning as that used to color G, except at the last stage, when all
vertices other than g have been colored.
• Then, because g is adjacent (in H) to vertices colored red, blue, and
green, a fourth color, say brown, needs to be used.
• Hence, H has a chromatic number equal to 4. A coloring of H is
shown in Figure 4.
Graph Coloring
• EXAMPLE What is the chromatic number of the graph Cn, where n ≥ 3? (Recall

that Cn is the cycle with n vertices.)

• Solution: 𝜒(Cn) = 2 if n is an even positive integer with n ≥ 4 and 𝜒(Cn) = 3 if n is an


odd positive integer with n ≥ 3.
• let n = 6. Pick a vertex and color it red.
• Proceed clockwise in the planar representation of
C6 shown in Figure 7.
• It is necessary to assign a second color, say blue, to the next
vertex reached.
• Hence, the chromatic number of C6 is 2, and 3 for C5 .
Thank
You

You might also like