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

Graphs

Chapter 10 covers the fundamentals of graphs, including definitions, types, and terminology such as simple graphs, directed graphs, and bipartite graphs. It also discusses special types of graphs, their applications in computer networks, and methods for representing graphs like adjacency lists and matrices. The chapter concludes with concepts of connectivity and paths within graphs.

Uploaded by

Hina Khan
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

Graphs

Chapter 10 covers the fundamentals of graphs, including definitions, types, and terminology such as simple graphs, directed graphs, and bipartite graphs. It also discusses special types of graphs, their applications in computer networks, and methods for representing graphs like adjacency lists and matrices. The chapter concludes with concepts of connectivity and paths within graphs.

Uploaded by

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

Graphs

Chapter 10
Graphs and Graph
Models
Section 10.1
Section Summary

• Introduction to Graphs
• Graph Taxonomy
• Graph Models
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?
Graph Terminology
and
Special Types of

Section 10.2
Graphs
Section Summary

• Basic Terminology
• Some Special Types of Graphs
• Bipartite Graphs
• Bipartite Graphs and Matchings
• Some Applications of Special Types of Graphs
• New Graphs from Old
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}.
Directed Graphs

Recall the definition of a directed graph.

Definition: An directed graph G = (V, E) consists of V, a nonempty set of


vertices (or nodes), and E, a set of directed edges or arcs. Each edge is an
ordered pair of vertices. The directed edge (u,v) is said to start at u and
end at v.
Definition: Let (u,v) be an edge in G. Then u is the initial vertex of this
edge and is adjacent to v and v is the terminal (or end) vertex of this
edge and is adjacent from u. The initial and terminal vertices of a loop
are the same.
Directed Graphs (continued)
Definition: The in-degree of a vertex v, denoted deg−(v), is the
number of edges which terminate at v. The out-degree of v,
denoted deg+(v), is the number of edges with v as their initial
vertex. Note that a loop at a vertex contributes 1 to both the in-
degree and the out-degree of the vertex.
Example: In the graph G we have

deg−(a) = 2, deg−(b) = 2, deg−(c) = 3, deg−(d) = 2, deg−(e) = 3,


deg−(f) = 0.
deg+(a) = 4, deg+(b) = 1, deg+(c) = 2, deg+(d) = 2, deg+ (e) = 3,
+
Special Types of Simple
Graphs:
Complete Graphs
A complete graph on n vertices, denoted by Kn, is the simple graph that
contains exactly one edge between each pair of distinct vertices.
Special Types of Simple
Graphs:
Cycles and Wheels
A cycle Cn for n ≥ 3 consists of n vertices v1, v2 ,⋯ , vn, and edges {v1, v2}, {v2,
v3} ,⋯ , {vn-1, vn}, {vn, v1}.

A wheel Wn is obtained by adding an additional vertex to a cycle Cn


for n ≥ 3 and connecting this new vertex to each of the n vertices in
Cn by new edges.
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.
Special Types of Simple Graphs:
n-Cubes

An n-dimensional hypercube, or n-cube, Qn, is a graph with 2n vertices


representing all bit strings of length n, where there is an edge
between two vertices that differ in exactly one bit position.
Special Types of Graphs and Computer
Network Architecture
• Various special graphs also play a role in parallel processing where
processors need to be interconnected as one processor may need the
output generated by another.
• The n-dimensional hypercube, or n-cube, Qn, is a common way to connect
processors in parallel, e.g., Intel Hypercube.
• Another common method is the mesh network, illustrated here for 16
processors.
Bipartite Graphs
Definition: A simple graph G is bipartite if V can be partitioned into
two disjoint subsets V1 and V2 such that every edge connects a
vertex in V1 and a vertex in V2. In other words, there are no edges
which connect two vertices in V1 or in V2.

• It is not hard to show that an equivalent definition of a


bipartite graph is a graph where it is possible to color the
vertices red or blue so that no two adjacent vertices are the
same color.
Bipartite Graphs (continued)

Example: Show that C3 is not bipartite.


Solution: If we divide the vertex set of C3 into two
nonempty sets, one of the two must contain two vertices.
But in C3 every vertex is connected to every other vertex.
Therefore, the two vertices in the same partition are
connected. Hence, C3 is not bipartite.
Bipartite Graphs (continued)

Example: Show that C6 is bipartite.


Solution: We can partition the vertex set into
V1 = {v1, v3, v5} and V2 = {v2, v4, v6} so that every edge of C6 connects a vertex
in V1 and V2 .
Bipartite Graphs

G is H is not bipartite since if we color a


bipartite red, then the adjacent vertices f and b
must both be blue.
Bipartite Graphs and Matchings

• Bipartite graphs are used to model applications that involve


matching the elements of one set to elements in another, for
example:
• Job assignments - vertices represent the jobs and the
employees, edges link employees with those jobs they have
been trained to do. A common goal is to match jobs to
employees so that the most jobs are done.
Complete Bipartite Graphs

Definition: A complete bipartite graph Km,n is a graph that has its


vertex set partitioned into two subsets V1 of size m and V2 of size n
such that there is an edge from every vertex in V1 to every vertex in
V2.
Example: We display four complete bipartite graphs here.
New Graphs from Old

where W ⊂ V and F ⊂ E. A subgraph H of G is a proper


Definition: A subgraph of a graph G = (V,E) is a graph (W,F),

subgraph of G if H ≠ G.
Example: Here we show K5 and one of its subgraphs.

Definition: Let G = (V, E) be a simple graph. The subgraph induced by a


subset W of the vertex set V is the graph (W,F), where the edge set F
contains an edge in E if and only if both endpoints are in W.
Example: Here we show K5 and the subgraph induced by W = {a,b,c,e}.
New Graphs from Old (continued)
simple graph with vertex set V1 ⋃ V2 and edge set E1 ⋃ E2. The union of G1
Definition: The union of two simple graphs G1 = (V1, E1) and G2 = (V2, E2) is the

and G2 is denoted by G1 ⋃ G2.


Example:
Representations of
Graphs
Section 10.3
Section Summary

• Adjacency Lists
• Adjacency Matrices
• Incidence Matrices
Representing Graphs:
Adjacency
Definition: Lists
An adjacency list can be used to represent a graph with no
multiple edges by specifying the vertices that are adjacent to each
vertex of the graph.

Example:
Representing Graphs: Adjacency Lists

Example:
Representation of Graphs:
Adjacency Matrices
Definition: Suppose that G = (V, E) is a simple graph where |V| = n.
Arbitrarily list the vertices of G as v1, v2, … , vn. The adjacency

zero-one matrix with 1 as its (i, j)th entry when vi and vj are adjacent,
matrix AG of G, with respect to the listing of vertices, is the n × n

and 0 as its (i, j)th entry when they are not adjacent.
• In other words, if the graphs adjacency matrix is AG = [aij], then
Adjacency Matrices (continued)

Exampl When a graph is


e: sparse, that is, it has
few edges relatively
to the total number of
The
possible edges, it is
ordering
of vertices much more efficient
is a, b, c, d. to represent the
graph using an
adjacency list than an
The
ordering
adjacency matrix.
of But for a dense
vertices is graph, which includes
a, b, c, d. a high percentage of
possible edges, an
adjacency matrix is
Note: The adjacency matrix of a simple graph is symmetric, i.e., aij
preferable.
Also, since there are no loops, each diagonal entry aij for i = 1, 2,
= aji

3, …, n, is 0.
Adjacency Matrices (continued)
• Adjacency matrices can also be used to represent graphs with loops
and multiple edges.
• A loop at the vertex vi is represented by a 1 at the (i, j)th position of
the matrix.
• When multiple edges connect the same pair of vertices vi and vj, (or
if multiple loops are present at the same vertex), the (i, j)th entry
equals the number of edges connecting the pair of vertices.
• Example: We give the adjacency matrix of the pseudograph shown
here using the ordering of vertices a, b, c, d.
Adjacency Matrices (continued)

The matrix for a directed graph G = (V, E) has a 1 in its (i, j)th
• Adjacency matrices can also be used to represent directed graphs.

position if there is an edge from vi to vj, where v1, v2, … vn is a list of


the vertices.
• In other words, if the graphs adjacency matrix is AG = [aij], then

• The adjacency matrix for a directed graph does not have to be symmetric, because there
may not be an edge from vi to vj, when there is an edge from vj to vi.
• To represent directed multigraphs, the value of aij is the number of edges connecting vi to
vj.
Representation of Graphs: Incidence
Matrices
Definition: Let G = (V, E) be an undirected graph with vertices where
v1, v2, … vn and edges e1, e2, … em. The incidence matrix
with respect to the ordering of V and E is the n × m matrix M = [mij],
where
Incidence Matrices (continued)

Example: Simple Graph and Incidence Matrix


The rows
going from
top to bottom
represent v1
through v5
and the
columns
going from
left to right
represent e1
Example: Pseudograph and Incidence Matrix through e6.
The rows
going from top
to bottom
represent v1
through v5 and
the columns
going from
left to right
represent e
Connectivity
Section 10.4
Section Summary

• Paths
• Connectedness in Undirected Graphs
• Connectedness in Directed Graphs
• Counting Paths between Vertices
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

= v of vertices such that ei has, for i = 1, …, n, the endpoints xi-1


e1, … , en of G for which there exists a sequence x0 = u, x1, …, xn-1, xn

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)

Example: In the simple graph here:


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

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.




Connectedness in Undirected
Graphs
Definition: An undirected graph is called connected if there is a
path between every pair of vertices. An undirected graph that is
not connected is called disconnected. We say that we disconnect a
graph when we remove vertices or edges, or both, to produce a
disconnected subgraph.
Example: G1 is connected because there is a path between any pair
of its vertices, as can be easily seen. However G2 is not connected
because there is no path between vertices a and f, for example.
Euler and Hamiltonian
Graphs
Section 10.5
Section Summary

• Euler Paths and Circuits


• Hamilton Paths and Circuits
• Applications of Hamilton Circuits
Euler Paths and Circuits
Definition: An 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.
Example: Which of the undirected graphs G1, G2, and G3 has a Euler circuit?
Of those that do not, which has an Euler path?

Solution: The graph G1 has an Euler circuit (e.g., a, e, c, d, e, b, a). But, as can
easily be verified by inspection, neither G2 nor G3 has an Euler circuit. Note that
G3 has an Euler path (e.g., a, c, d, e, b, d, a, b), but there is no Euler path in G2,
which can be verified by inspection.
Necessary Conditions for Euler Circuits
and Paths
• An Euler circuit begins with a vertex a and continues with an edge
incident with a, say {a, b}. The edge {a, b} contributes one to deg(a).
• Each time the circuit passes through a vertex it contributes two to the
vertex’s degree.
• Finally, the circuit terminates where it started, contributing one to
deg(a). Therefore deg(a) must be even.
• We conclude that the degree of every other vertex must also be even.
• By the same reasoning, we see that the initial vertex and the final
vertex of an Euler path have odd degree, while every other vertex has
even degree. So, a graph with an Euler path has exactly two vertices of
odd degree.
• In the next slide we will show that these necessary conditions are also
sufficient conditions.
Euler Circuits and Paths
Example:

G1 contains exactly two vertices of odd degree (b and d). Hence it has an Euler
path, e.g., d, a, b, c, d, b.

G2 has exactly two vertices of odd degree (b and d). Hence it has an Euler path,
e.g., b, a, g, f, e, d, c, g, b, c, f, d.

G3 has six vertices of odd degree. Hence, it does not have an Euler path.
Applications of Euler Paths and
Circuits
• Euler paths and circuits can be used to solve many practical problems
such as finding a path or circuit that traverses each
• street in a neighborhood,
• road in a transportation network,
• connection in a utility grid,
• link in a communications network.
• Other applications are found in the
• layout of circuits,
• network multicasting,
• molecular biology, where Euler paths are used in the sequencing of DNA.
William
Rowan
Hamilton Paths and Circuits
(1805- 1865)
Hamilton

• Euler paths and circuits contained every edge only once.

• William Hamilton invented the Icosian puzzle in 1857. It consisted of a wooden


Now we look at paths and circuits that contain every vertex exactly once.

dodecahedron (with 12 regular pentagons as faces), illustrated in (a), with a peg at

a circuit visiting 20 cities exactly once


each vertex, labeled with the names of different cities. String was used to used to plot

• The graph form of the puzzle is given in (b).

• The solution (a Hamilton circuit) is given here.


Hamilton Paths and Circuits

Definition: 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.

That is, a simple path x0, x1, …, xn-1, xn in the graph G = (V, E) is
called a Hamilton path if V = {x0, x1, … , xn-1, xn } and xi ≠ xj for
0≤ i < j ≤ n, and the simple circuit x0, x1, …, xn-1, xn, x0
(with n > 0) is a Hamilton circuit if x0, x1, … , xn-1, xn is a
Hamilton path.
Hamilton Paths and Circuits
Example: Which of these simple graphs has a Hamilton circuit or, if not, a
Hamilton path?

Solution:
G1 does not have a Hamilton circuit (Why?), but does have
a Hamilton path : a, b ,e , c, d.
G2 has a Hamilton circuit: a, b, c, d, e, a.
G3 has a Hamilton circuit: a,b,e,d,c,a
Necessary Conditions for
Hamilton Circuits Gabriel Andrew
Dirac
• Unlike for an Euler circuit, no simple necessary and sufficient
(1925-1984)
conditions are known for the existence of a Hamiton circuit.
• However, there are some useful necessary conditions. We describe

Dirac’s Theorem: If G is a simple graph with n ≥ 3 vertices such that


two of these now.

the degree of every vertex in G is ≥ n/2, then G has a Hamilton


circuit.

Ore’s Theorem: If G is a simple graph with n ≥ 3 vertices such that


deg(u) + deg(v) ≥ n for every pair of nonadjacent vertices, then G has
a Hamilton circuit.
Øysten Ore

1968)
(1899-
Applications of Hamilton Paths and
Circuits
• Applications that ask for a path or a circuit that visits each
intersection of a city, each place pipelines intersect in a utility grid, or
each node in a communications network exactly once, can be solved
by finding a Hamilton path in the appropriate graph.
• The famous traveling salesperson problem (TSP) asks for the shortest
route a traveling salesperson should take to visit a set of cities. This
problem reduces to finding a Hamilton circuit such that the total sum
of the weights of its edges is as small as possible.
• A family of binary codes, known as Gray codes, which minimize the
effect of transmission errors, correspond to Hamilton circuits in the
n-cube Qn.
Shortest Paths
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’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