Date post: | 04-Apr-2015 |
Category: |
Documents |
Upload: | ruzza-alamurah |
View: | 212 times |
Download: | 3 times |
M131-Chapter9 By Ms. Suha Al-Shaikh-Dammam
1
A graph G =(V, E) where:
V: set of vertices (nodes)
E: set of edges.
Definition: A graph G=(V,E) consists of V, a non-empty set of vertices and E, a set of
edges. Each edge has either one or two vertices associated with it, called its end
points. An edge is said to connect its end point.
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.
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.
Chapter 9: Graphs
Section (9.1): Graph and Graph Models
Undirected Graphs:
M131-Chapter9 By Ms. Suha Al-Shaikh-Dammam
2
Pseudo graphs: graphs that may include loops and possibly multiple edges
connecting the same pair of vertices are sometimes called pseudo 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.
directed Graphs:
Directed graphs: we obtain a directed graph when we assign a direction to each
edge in an undirected graph.
Note:A graph with both directed an undirected edges is called a mixed graph
M131-Chapter9 By Ms. Suha Al-Shaikh-Dammam
3
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.
loops Multiple
edges
edges Table(1)
No No undirected Simple graph
No Yes Undirected Multi graph
Yes Yes Undirected Pseudo graph
No No Directed Simple directed graph
Yes Yes Directed Directed multi graph
yes yes Directed and
undirected
Mixed graph
M131-Chapter9 By Ms. Suha Al-Shaikh-Dammam
5
Graph Models:
1. Niche over lap Graph in Ecology. It is a simple graph because no loops or
multiple edges are needed in this model. In this model we connect two animals
if some of their food resource are the same.(refer to text book page 593).
2. Acquaintanceship graph: ( we use it to represent relation between people). It is
a simple graph to represent whether 2people know each other, that is whether
they are acquainted. (refer to text book page 593; read the other models from
the text book page 593, 594, and 595.
M131-Chapter9 By Ms. Suha Al-Shaikh-Dammam
6
Basic Terminology:
Definition: two vertices u and v in an undirected graph G are called adjacent
(neighbors) in G if u and v are end points of an edge in G.
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.
Definition: (gives how many edges are incident to a vertex)
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.
Remark: the degree of a vertex is denoted by deg (v).
Example: what are the degrees of the vertices in the following graphs G and H?
Solution:
(1) In undirected graph G: deg(a)=2, deg(b)=4
deg(c)=4, deg(f)=4
deg(d)=1, deg(e)=3
deg(g)=0 (isolated)
(2) In Undirected graph H: deg(a)=2, deg(b)=6
deg(e)=6, deg(c)=1 (pendant)
deg(d)=5
Remark:
1) a vertex of degree zero is called isolated.
2) A vertex is pendant if and only if it has degree one.
Section9.2: Graphs Terminology and Special Types of Graphs
M131-Chapter9 By Ms. Suha Al-Shaikh-Dammam
7
Theorem : (THE HANDSHAKING THEOREM)
let G=(V,E) be an undirected graph with e=|E| edges then:
Example: how many edges where in a graph with 10 vertices each of degree six?
Solution:
Remark: last theorem shows that the sum of the degrees of the vertices of an
undirected graph is even.
Theorem: an undirected graph has an even number of vertices of odd degree.
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.
u→ the vertex u is called the initial vertex of (u,v)
v→ is called the terminal or end vertex of (u,v)
The initial vertex and the terminal vertex for a loop are the same.
Definition: in a graph with directed edges:
1) The in-degree of a vertex v, denoted by degˉ(v) is the number of edges with v
as their terminal vertex.
2) The out-degree of v, denoted by is the number of edges with v as
their initial vertex.
Example: find the in-degree and out-degree of each vertex in the graph G with
directed edges in the following directed graph G.
Solution: The In-degree in G
Vvve )deg(2
30.
302
60602
60)10(6)deg(
isedgesofnothehence
ee
V
)(deg V
M131-Chapter9 By Ms. Suha Al-Shaikh-Dammam
8
Theorem: let G=(V,E) be a graph with directed edges. Then
Refer to example4.
Some special simple graphs
Example(page601): complete graphs
The complete graph on n vertices denoted by , is the simple graph that contains
exactly one edge between each pair of distinct vertices.
The complete graph for n=1,2,3 and 4
For n=5 and 6 see the book page(601) .
Example: Cycles
Example: wheels;
we obtain the wheel when we add an a additional vertex to the cycle ,for 3n and
connect the new vertex to each of the n vertices in nC .
Read Example 8(page 602).
EVVVvVv
)(deg)(deg
nk
nW nC
M131-Chapter9 By Ms. Suha Al-Shaikh-Dammam
9
Bipartite Graphs:
A simple graph G is called bipartite if its vertex set V can be partitioned into 2
disjoint sets such that every edge in the graph connects a vertex in and a
vertex in . (That is no edge in G connect either two vertices in V1 or two vertices in
V2).
We call the pair a bipartition of the vertex set V of G.
Example:
Consider C6
C6 is bipartite because its vertex set can be partitioned into the 2 sets
and every edge of C6 connects a vertex in 1V and a vertex in 2V .
Example:
K3 is not bipartite .
Suppose
Since there is an edge between is not a bipartite graph .
21andVV 1V
2V
),( 21 VV
64225311 ,,,, VVVandVVVVV
},{},{ 32211 VVVVV
332 , KandVV
M131-Chapter9 By Ms. Suha Al-Shaikh-Dammam
11
Example: show that graph G is bipartite
Solution: since the vertex set of G , where
And every edge is a connection of so G is a bipartite.
Read (example 11 page 603).
Theorem: A simple graph is bipartite if and only if it is possible to assign one of 2
different colors to each vertex of the graph so that no 2 adjacent vertices are assigned
the same color.
Example: Complete Bipartite Graph :
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.
Read Examples:14,15 and 16
New graph from an old one:
(1) Sub graph H=(W,F) of G=(V,E) is when WV and FE.
A sub graph H of G is proper sub graph if H≠G.
(2) Union of two simple Graphs: ),(),( 222111 EVandGEVG is the simple
graph with vertex set 21 VV and edges set 21 EE , and denoted as 21 GG
21 VVV },,,{},,{ 21 gfecandVdbaV
21andVV
M131-Chapter9 By Ms. Suha Al-Shaikh-Dammam
11
• Graph representations:
– Adjacency lists.
– Adjacency matrices.
Example: Use adjacency lists to describe the following graph:
Solution: An adjacency list for a simple graph
Matrix A=[aij], where aij is 1 if {vi, vj} is an edge of G, 0 otherwise.
Example:
Section9.3: Graph Representations
Undirected: Adjacency Lists
Undirected: Adjacency Matrices
otherwise
GofedgeanisVVifa
ji
ij0
},{1
M131-Chapter9 By Ms. Suha Al-Shaikh-Dammam
12
Example:Draw a graph using the following adjacency matrix with respect to the
vertices: a,b,c,d .
Example: use an adjacency matrix to represent the pseudo graph.
the adjacency matrix using the ordering of vertices a,b,c,d is: :Solution
Remark: 1) the adjacency matrix of a simple graph is symmetric
2) The adjacency matrix for a directed graph does not have to be symmetric, because
there may not be an edge from when there is an edge from
3) Adjacency matrices can also be used to represent directed multi graphs
4) In the adjacency matrix for a directed multi graph the number of edges that
are associated to
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
ij atoa ji atoa
ija
ji VV ,
M131-Chapter9 By Ms. Suha Al-Shaikh-Dammam
13
Incidence Matrices:
Another way to represent graphs is to use incidence matrices. Let G=(V,E) be an
undirected graph. Suppose that are the vertices and
Are the edges of G. then the incidence matrix with respect to this ordering of V and E
is the nXn matrix , where
Example page 614:
Represent the following graph with an incidence matrix:
1 row per node, listing the terminal nodes of each edge incident from that node.
Directed Adjacency Lists
nVVV ,...,, 21 neee ,...,, 21
ijmM
otherwise
Vwithincidenteedgewhenm
ij
ij0
1
M131-Chapter9 By Ms. Suha Al-Shaikh-Dammam
14
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, of G such that is associated
with , and so on, with associated with
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
},,,{ 20 nxxx
Example: consider the following simple graph.
1) a,d,c,f,e is a simple path of length4. {a,d},{d,c},{c,f},{f,e} are all edges.
2) d,e,c,a is not a path, because {e,c} is not an edge.
3) b,c,f,e,b is a circuit of length4. because {b,c},{c,f},{f,e},{e,b} are all edges and
this path begins and ends at b.
Directed: Adjacency Matrices
Section9.4: Connectivity
nee ,.....,1 1e
},{ 10 xx ne
vxanduxwherexx nnn 01 },{
M131-Chapter9 By Ms. Suha Al-Shaikh-Dammam
15
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?
a) a,e,b,c,b b) a,e,a,d,b,c,a c) e,b,a,d,b,e d) c,b,d,a,e,c
Solution: a) {a,e},{e,b},{b,c},{c,b} are all edges so it is a path of length 4. not a
circuit, not simple (because of {b,c}, {c,b})
b) {a,e},{e,a},{a,d},{d,b},{b,c}, there is no edge {c,a} so it os not a path
c) {e,b} there is no path between {b,a} so it is not a path
d) {c,b},{b,d},{d,a},{a,e},{e,c} is a circuit of length 5 it is simple circuit.
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 of G such that is associated
with is associated with and so on, with associated with
Remarks: 1) when there are no multiple edges in the directed graph this path is
denoted by its vertex sequence
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.
Read examples 2,3 and 4 page 623.
neee ,...,, 21 1e
210 ),,( exx ),( 21 xx ne
vxanduxwherexx nnn 01 ),,(
nxxx ,...,, 10
M131-Chapter9 By Ms. Suha Al-Shaikh-Dammam
16
When is there always a path between 2 vertices in the graph?
Definition: an undirected graph is called connected if there is a path between every
pair of distinct vertices of the graph.
Remark: any 2 computers in the network can communicate if and only if the graph of
this network is connected.
Example: consider the following graphs:
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.
Remark: 1) a connected component of a graph G is a connected sub graph of G that
is not a proper sub graph of another connected sub graph of G.
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]
Connectedness In Undirected Graphs:
M131-Chapter9 By Ms. Suha Al-Shaikh-Dammam
17
Example: find the cut vertices and cut edges in graph G
remark: (remove a,h,g,h gives 1 components)
Solution: the cut vertices of G are b,c, and e. the cut edges are {a,b}, {c,e}
Removing either one of these edges or vertices disconnect G
Definition: a directed graph is strongly connected if there is a path from a to b and
from b to a whenever a and b are vertices in the graph.
Definition: a directed graph is weakly connected if there is a path between every 2
vertices in the underlying undirected graph.
Remarks:
1) a directed graph is weakly connected if and only if there is always a path
between 2 vertices when the direction of the edges are disregarded.
2) Any strongly connected directed graph is also weakly connected.
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.
Connectedness in Directed Graph:
M131-Chapter9 By Ms. Suha Al-Shaikh-Dammam
18
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.
Solution: a) the graph G is weakly connected, because there is no path from a to b.
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).