Escolar Documentos
Profissional Documentos
Cultura Documentos
Suha Al-Shaikh-Dammam
Chapter 9: Graphs
E: set of edges.
Remark: the computer can be modeled using a graph in which the vertices of the
graph represent the data centers, and the edges represent communication links.
Undirected Graphs:
Simple graphs: a graph in which each edge connects 2 different vertices and where
no 2 edges connect the same pair of vertices.
Note: in the simple graph each edge is associated to an unordered pair of vertices, and
no other edge is associated to this same edge.
We say that {u,v} is an edge in the simple graph if there is an edge associated to {u,v}
Multi graphs: graphs that may have multiple edges connecting the same vertices.
Where there are m different edges associated to the same unordered pair of vertices
{u,v}. we say that {u,v} is an edge of multiplicity m.
1
M131-Chapter9 By Ms. Suha Al-Shaikh-Dammam
Pseudo graphs: graphs that may include loops and possibly multiple edges
connecting the same pair of vertices are sometimes called pseudo graphs.
directed Graphs:
Definition: a directed graph (or digraph) (V,E) consists of a non empty set of vertices
V and a set of directed edges E. each directed edge is associated with an order pair of
vertices (u,v) is said to start at u and end at v.
Simple directed graph: it is when a directed graph has no loops and has no multiple
directed edges .
Directed multi graphs: directed graphs that may have multiple directed edges from a
vertex to a second vertex .
When there are m directed edges, each associated to an ordered pair of vertices (u,v),
we say that( u,v) is an edge of multiplicity m.
Note:A graph with both directed an undirected edges is called a mixed graph
2
M131-Chapter9 By Ms. Suha Al-Shaikh-Dammam
The Terminology for the various types of graphs is summarized in the following
Table:
Example: draw graph models, starting the type of graph (from table1) used to
represent air line routes where every day there are four flights from Boston to New
York, 2 flights from New York to Boston, 3 flights from New York to Miami, 2
flights from Miami to New York, one flight from New York to Detroit, 2 flights from
Detroit to New York, 3 flights from New York to Washington, 2 flights from
Washington to New York, and one flight from Washington to Miami, with
a) An edge between vertices representing cities that have a flight between them
(in either direction)
b) An edge between vertices representing cities for each flight that operate
between them (in either direction)
c) An edge between vertices representing cities for each flight that operate
between them (in either direction) plus a loop for a special sight seeing trip
that takes off and land in Miami.
d) An edge from a vertex representing a city where a flight starts to the vertex
representing the city where it ends
e) An edge for each flight from a vertex representing a city where the flight
begins to the vertex representing the city where the flight ends.
3
M131-Chapter9 By Ms. Suha Al-Shaikh-Dammam
Solution:
4
M131-Chapter9 By Ms. Suha Al-Shaikh-Dammam
Graph Models:
5
M131-Chapter9 By Ms. Suha Al-Shaikh-Dammam
Basic Terminology:
If e is associated with {u,v}, the edge e is called incident with the vertex u and v. The
edge e is also said to connect u and v.
The degree of a vertex in an undirected graph is the number of edges incident with it,
except that a loop at a vertex contributes twice to the degree of that vertex.
Example: what are the degrees of the vertices in the following graphs G and H?
Solution:
deg(c)=4, deg(f)=4
deg(d)=1, deg(e)=3
deg(g)=0 (isolated)
deg(d)=5
Remark:
6
M131-Chapter9 By Ms. Suha Al-Shaikh-Dammam
let G=(V,E) be an undirected graph with e=|E| edges then: 2e vV deg( v)
Example: how many edges where in a graph with 10 vertices each of degree six?
Solution:
deg(V ) 6(10) 60
60
2e 60 e 30
2
hence the no. of edges is 30
Remark: last theorem shows that the sum of the degrees of the vertices of an
undirected graph is even.
Definition: when (u,v) is an edge of the graph G with directed edges, u is said to be
adjacent to v and v is said adjacent to v.
Example: find the in-degree and out-degree of each vertex in the graph G with
directed edges in the following directed graph G.
7
M131-Chapter9 By Ms. Suha Al-Shaikh-Dammam
Refer to example4.
The complete graph on n vertices denoted by k n , is the simple graph that contains
exactly one edge between each pair of distinct vertices.
Example: Cycles
Example: wheels;
we obtain the wheel Wn when we add an a additional vertex to the cycle C n,for n 3 and
connect the new vertex to each of the n vertices in C n .
8
M131-Chapter9 By Ms. Suha Al-Shaikh-Dammam
Bipartite Graphs:
A simple graph G is called bipartite if its vertex set V can be partitioned into 2
disjoint sets V1andV2 such that every edge in the graph connects a vertex inV1 and a
vertex in V2 . (That is no edge in G connect either two vertices in V1 or two vertices in
V2).
Example:
Consider C6
C6 is bipartite because its vertex set can be partitioned into the 2 sets
Example:
K3 is not bipartite .
9
M131-Chapter9 By Ms. Suha Al-Shaikh-Dammam
Is the graph that has its vertex set partitioned into 2 subsets of m and n vertices
respectively. There is an edge between 2 vertices if and only if one vertex is in the
first subset and the other vertex in the second subset.
11
M131-Chapter9 By Ms. Suha Al-Shaikh-Dammam
• Graph representations:
– Adjacency lists.
– Adjacency matrices.
11
M131-Chapter9 By Ms. Suha Al-Shaikh-Dammam
Example:Draw a graph using the following adjacency matrix with respect to the
vertices: a,b,c,d .
Solution: the adjacency matrix using the ordering of vertices a,b,c,d is:
2) The adjacency matrix for a directed graph does not have to be symmetric, because
there may not be an edge from a j to ai when there is an edge from ai to a j
4) In the adjacency matrix for a directed multi graph aij the number of edges that
are associated to Vi ,V j
5) When a simple graph contains few edges, that is, when it is sparse use adjacency
list.
6) When a simple graph is dense, that is when it contains more than half of all
possible edges use adjacency matrix to represent the graph
12
M131-Chapter9 By Ms. Suha Al-Shaikh-Dammam
Incidence Matrices:
Are the edges of G. then the incidence matrix with respect to this ordering of V and E
is the nXn matrix M mij , where
13
M131-Chapter9 By Ms. Suha Al-Shaikh-Dammam
Section9.4: Connectivity
Paths: a path is a sequence of edges that begins at a vertex of a graph and travels
from vertex to vertex along edges of a graph.
Definition: let n be a non negative 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 such that e1 is associated
with {x0 , x1 } , and so on, with en associated with
{xn1 , xn } where x0 u and xn v
Remarks: 1) the path is a circuit if it begins and ends at the same vertex, that is, if
u=v, and has length greater than zero.
2) A path or circuit is simple if it doesn’t contain the same edge more than once.
3) When the graph is simple, we denote this path by its vertex sequence
{x0 , x2 ,, xn }
14
M131-Chapter9 By Ms. Suha Al-Shaikh-Dammam
4) a,b,c,d,a,b is a path of length 5. which is not simple because it contains the edge
{a,b} twice.
Example: does each of these lists of vertices form a path in the following graph?
Which paths are simple which are circuits? What are the length of those that are
paths?
Definition: let n be a non negative integer and G a directed graph. A path of length n
from u to v in G is a sequence of edges e1 , e2 ,..., en of G such that e1 is associated
with ( x0 , x1 ), e2 is associated with ( x1 , x2 ) and so on, with en associated with
( xn1 , xn ), where x0 u and xn v
Remarks: 1) when there are no multiple edges in the directed graph this path is
denoted by its vertex sequence x0 , x1 ,..., xn
2) A path of length greater than zero that begins and ends at the same vertex is called
a circuit or cycle.
3) A path or circuit is called simple if it doesn’t contain the same edge more than
once.
15
M131-Chapter9 By Ms. Suha Al-Shaikh-Dammam
Remark: any 2 computers in the network can communicate if and only if the graph of
this network is connected.
G1 is connected because for every pair of distinct vertices there is a path between
them.
The graph G2 is not connected because there is no path between a and d, or c and d,
or b and d.
Theorem: there is a simple path between every pair of distinct vertices of a connected
undirected graph.
2) A graph G that is not connected has 2 or more connected components that are
disjoint and have G as their union.
3) Sometimes the removal of a vertex and all edges incident with it produces a sub
graph with more connected components than in the original graph such vertices are
called cut vertices.
4) An edge whose removal produces a graph with more connected components than in
the original graph is called a cut edge or bridge.
Note:[the removal of a cut vertex from a connected graph produces a sub graph that is
not connected]
16
M131-Chapter9 By Ms. Suha Al-Shaikh-Dammam
Solution: the cut vertices of G are b,c, and e. the cut edges are {a,b}, {c,e}
Remarks:
Example: are the directed graphs G and H strongly connected? Are they weakly
connected?
Solution: the graph G is strongly connected there is a path between any 2 vertices in
G. hence G is also weakly connected.
17
M131-Chapter9 By Ms. Suha Al-Shaikh-Dammam
The graph H is not strongly connected, because there is no directed path from a to b.
H is weakly connected.
Example: determine whether each of these graphs is strongly connected and if not.
Whether it is weakly connected.
b) The graph H is weakly connected, because there is a path from e to c, but there is
no path from c to e.
Remark: the sub graphs of a directed graph G that are strongly connected but not
contained in larger strongly connected sub graphs are called the strongly connected
components or strong components of G.
Example:
the graph H has 3 strongly components the vertex a; the vertex e; and the graph
consisting of the vertices b,c, and d and edges (b,c), (c,d) and (d,b).
18