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

Lecture 18

The document provides an overview of graph theory, including definitions, types of graphs, and their applications in various fields such as computer networks, social networks, and software design. It explains key concepts such as directed and undirected graphs, multigraphs, and paths, as well as algorithms for finding the shortest paths in weighted graphs, specifically Dijkstra's algorithm. Additionally, it discusses how graph models can represent real-world systems and relationships.

Uploaded by

nafeyrehman27
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views

Lecture 18

The document provides an overview of graph theory, including definitions, types of graphs, and their applications in various fields such as computer networks, social networks, and software design. It explains key concepts such as directed and undirected graphs, multigraphs, and paths, as well as algorithms for finding the shortest paths in weighted graphs, specifically Dijkstra's algorithm. Additionally, it discusses how graph models can represent real-world systems and relationships.

Uploaded by

nafeyrehman27
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 36

MATH-161

Discrete Mathematics
Instructor: Dr. Samra Kanwal

National University of Sciences & Technology


(NUST)
Military College of Signals
Department of Computer Software Engineering
Chapter 10 Graphs
Definition: A graph G = (V, E) consists of a nonempty set
V of vertices (or nodes) and a set E of edges. Each edge
has either one or two vertices associated with it, called
its endpoints. An edge is said to connect its endpoints.

Basic Types of GRAPH


• Simple Graph

• Multi Graph

• Pseudo Graph

• Null Graph

• Complete Graph

• Regular Graph
Some Terminology
• In a simple graph each edge connects two different vertices and no two edges
connect the same pair of vertices.
• Multigraphs may have multiple edges connecting the same two vertices. When
m different edges connect the vertices u and v, we say that {u,v} is an edge of
multiplicity m.
• An edge that connects a vertex to itself is called a loop.
• A pseudograph may include loops, as well as multiple edges connecting the
same pair of vertices.

Example: a b Remark: There is no standard


This terminology for graph theory.
pseudograph So, it is crucial that you
has both understand the terminology
multiple edges being used whenever you read
and a loop. material about graphs.
c
Directed Graphs
Definition: An directed graph (or digraph)
G = (V, E) consists of a nonempty set V of vertices
(or nodes) and a set E of directed edges (or arcs).
Each 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.

Remark:
• Graphs where the end points of an edge are not
ordered are said to be undirected graphs.
Some Terminology (continued)

• A simple directed graph has no loops and no multiple edges.


a b
Example:
This is a directed graph
with three vertices and
four edges. c
• A directed multigraph may have multiple directed edges. When there are m
directed edges from the vertex u to the vertex v, we say that (u,v) is an
edge of multiplicity m.

Exampl
e:
multiplicity of (a,b) is 1 and the
In this directed multigraph the a b

multiplicity of (b,c) is 2.
c
Graph Terminology: Summary
• To understand the structure of a graph and to build a graph
model, we ask these questions:
• Are the edges of the graph undirected or directed (or both)?
• If the edges are undirected, are multiple edges present that connect the
same pair of vertices? If the edges are directed, are multiple directed
edges present?
• Are loops present?
10.1 Graphs and
Graph Models
• When we build a graph model, we use the appropriate type of graph to capture the
important features of the application.
• We illustrate this process using graph models of different types of computer networks.
In all these graph models, the vertices represent data centers and the edges represent
communication links.
• To model a computer network where we are only concerned whether two data
centers are connected by a communications link, we use a simple graph. This is the
appropriate type of graph when we only care whether two data centers are directly
linked (and not how many links there may be) and all communications links work in
both directions.
Graph Models:
Computer Networks (continued)

• To model a computer network where we care about the


number of links between data centers, we use a multigraph.
Graph Models: Computer Networks

• To model a computer network with diagnostic links at data


centers, we use a pseudograph, as loops are needed.
Graph Models: Computer Networks
• To model a network with multiple one-way links, we use a
directed multigraph. Note that we could use a directed graph
without multiple edges if we only care whether there is at least
one link from a data center to another data center.
Graph Models: Social Networks
• Graphs can be used to model social structures based on
different kinds of relationships between people or groups.
• In a social network, vertices represent individuals or
organizations and edges represent relationships between
them.
• Useful graph models of social networks include:

• friendship graphs - undirected graphs where two people


are connected if they are friends (in the real world, on
Facebook, or in a particular virtual world, and so on.)
• collaboration graphs - undirected graphs where two
people are connected if they collaborate in a specific way
• influence graphs - directed graphs where there is an
edge from one person to another if the first person can
influence the second person ..
Graph Models: Social
Networks
Example: A friendship graph where two people are
connected if they are Facebook friends.
Graph Models: Social
Networks
Example: An influence graph
Applications to Information Networks
• Graphs can be used to model different types of networks that
link different types of information.
• In a web graph, web pages are represented by vertices and
links are represented by directed edges.

• A web graph models the web at a particular time.


• We will explain how the web graph is used by search engines in Section
11.4.
• In a citation network:

• Research papers in a particular discipline are represented by vertices.


• When a paper cites a second paper as a reference, there is an edge from
the vertex representing this paper to the vertex representing the second
paper.
Transportation Graphs
• Graph models are extensively used in the study of
transportation networks.
• Airline networks can be modeled using directed
multigraphs where
• airports are represented by vertices
• each flight is represented by a directed edge from the vertex
representing the departure airport to the vertex representing the
destination airport
• Road networks can be modeled using graphs where
• vertices represent intersections and edges represent roads.
• undirected edges represent two-way roads and directed edges
represent one-way roads.
Software Design Applications
• Graph models are extensively used in software design. We will
introduce two such models here; one representing the
dependency between the modules of a software application
and the other representing restrictions in the execution of
statements in computer programs.

• When a top-down approach is used to design software, the


system is divided into modules, each performing a specific task.

• We use a module dependency graph to represent the
dependency between these modules. These dependencies
need to be understood before coding can be done.
Software Design Applications

• In a module dependency graph vertices represent software modules and


there is an edge from one module to another if the second module
depends on the first.

Example: The dependencies between the seven


modules in the design of a web browser are
represented by this module dependency graph.
Software Design Applications
• We can use a directed graph called a precedence graph to
represent which statements must have already been executed
before we execute each statement.

• Vertices represent statements in a computer program


• There is a directed edge from a vertex to a second vertex if the second
vertex cannot be executed before the first

Example: This
precedence graph shows
which statements must
already have been
executed before we can
execute each of the six
statements in the
program.
Graph Terminology
and
Special Types of

Section 10.2
Graphs
Basic Terminology
Definition 1. Two vertices u, v in an undirected graph G are
called adjacent (or neighbors) in G if there is an edge e between
u and v. Such an edge e is called incident with the vertices u and
v and e is said to connect u and v.

Definition 2. The set of all neighbors of a vertex v of G = (V, E),


denoted by N(v), is called the neighborhood of v. If A is a subset
of V, we denote by N(A) the set of all vertices in G that are
adjacent to at least one vertex in A. So,

Definition 3. The degree of a vertex in a undirected graph is the


number of edges incident with it, except that a loop at a vertex
contributes two to the degree of that vertex. The degree of the
vertex v is denoted by deg(v).
Degrees and Neighborhoods of
Vertices
Example: What are the degrees and neighborhoods of the vertices
in the graphs G and H?

Solution:
G: deg(a) = 2, deg(b) = deg(c) = deg(f ) = 4, deg(d ) = 1, deg(e) = 3, deg(g) = 0.
N(a) = {b, f }, N(b) = {a, c, e, f }, N(c) = {b, d, e, f }, N(d) = {c},
N(e) = {b, c , f }, N(f) = {a, b, c, e}, N(g) =  .
H: deg(a) = 4, deg(b) = deg(e) = 6, deg(c) = 1, deg(d) = 5.
N(a) = {b, d, e}, N(b) = {a, b, c, d, e}, N(c) = {b}, N(d) = {a, b, e},
N(e) = {a, b ,d}.
Special Types of Graphs
and Computer Network
Architecture
Various special graphs play an important role in the design of computer
networks.

• Some local area networks use a star topology, which is a complete bipartite
graph K1,n ,as shown in (a). All devices are connected to a central control
device.
• Other local networks are based on a ring topology, where each device is
connected to exactly two others using Cn ,as illustrated in (b). Messages may
be sent around the ring.
• Others, as illustrated in (c), use a Wn – based topology, combining the
features of a star topology and a ring topology.
Paths
Informal Definition: 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. As the path travels along
its edges, it visits the vertices along this path, that is, the
endpoints of these.

Applications: Numerous problems can be modeled with


paths formed by traveling along edges of graphs such as:

• determining whether a message can be sent


between two computers.
• efficiently planning routes for mail delivery.
Paths
Definition: Let n be a nonnegative integer and G an undirected graph. A path
of length n from u to v in G is a sequence of n edges e1, … , en of G for which
there exists a sequence x0 = u, x1, …, xn-1, xn = v of vertices such that ei has, for
i = 1, …, n, the endpoints xi-1 and xi.

• When the graph is simple, we denote this path by its vertex sequence
x0, x1, … , xn(since listing the vertices uniquely determines the path).
• The path is a circuit if it begins and ends at the same vertex (u = v)
and has length greater than zero.
• The path or circuit is said to pass through the vertices x1, x2, … , xn-1
and traverse the edges e1, … , en.
• A path or circuit is simple if it does not contain the same edge more
than once.
Paths (continued)

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


Example: In the simple graph here:

• b, c, f, e, b is a circuit of length 4.
• d, e, c, a is not a path because e is not connected to c.

• a, b, e, d, a, b is a path of length 5, but it is not a simple


path.
10.6
Shortest-Path Problems
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 860

191
1855 722 NY
CHI
SF DEN 908
957
606

7 60
4
349 83

1090
2 45 1
ATL
LA 595
MIA
Weighted Graphs
FARES

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

$ 79

$ 99
$39 $89 $129
ATL
LA

$ 69
MIA
Weighted Graphs
FLIGHT
TIMES

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

1:55
1:4

2:45
0
1:15 2:00 3:50
ATL
LA

1:3
0
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 vs Bellman Ford vs Floyd Warshall

• Dijkstra’s Algorithm finds the shortest path between two vertices.


Dijkstra’s Algorithm
• Dijkstra’s algorithm is used in problems relating to finding the shortest path.

• Each node is given a temporary label denoting the length of the shortest path
from the start node so far.

• This label is replaced if another shorter route is found.

• Once it is certain that no other shorter paths can be found, the temporary
label becomes a permanent label.

• Eventually all the nodes have permanent labels.

• At this point the shortest path is found by retracing the path backwards.
Dijkstra’s algorithm: example
D(v) D(w) D(x) D(y) D(z)
Step N'
0 u 7,u 3,u 5,u ∞ ∞
1 uw 6,w 5,u 11,w ∞
2 uwx 6,w 11,w 14,x
3 uwxv 10,v 14,x
4 uwxvy 12,y
5 uwxvyz x
9

notes: 5
4
7
 construct shortest path
8
tree by tracing
predecessor nodes u
3 w y z
 ties can exist (can be 2
broken arbitrarily) 3
7 4
v
Dijkstra’s algorithm: another example

Step N' D(v) D(w) D(x) D(y) D(z)


0 u 2,u 5,u 1,u ∞ ∞
1 ux 2,u 4,x 2,x ∞
2 uxy 2,u 3,y 4,y
3 uxyv 3,y 4,y
4 uxyvw 4,y
5 uxyvwz
5
3
v w 5
2
u 2 1 z
3
1 2
x 1
y
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

You might also like