Você está na página 1de 18

M131-Chapter9 By Ms.

Suha Al-Shaikh-Dammam

Chapter 9: Graphs

Section (9.1): Graph and Graph Models

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

Directed graphs: we obtain a directed graph when we assign a direction to each


edge in an undirected graph.

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:

Table(1) edges Multiple loops


edges

Simple graph undirected No No

Multi graph Undirected Yes No

Pseudo graph Undirected Yes Yes

Simple directed graph Directed No No

Directed multi graph Directed Yes Yes

Mixed graph Directed and yes yes


undirected

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:

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.

5
M131-Chapter9 By Ms. Suha Al-Shaikh-Dammam

Section9.2: Graphs Terminology and Special Types of Graphs

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.

6
M131-Chapter9 By Ms. Suha Al-Shaikh-Dammam

Theorem : (THE HANDSHAKING THEOREM)

let G=(V,E) be an undirected graph with e=|E| edges then: 2e  vV 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.

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 deg (V ) 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

7
M131-Chapter9 By Ms. Suha Al-Shaikh-Dammam

Theorem: let G=(V,E) be a graph with directed edges. Then  vV


deg  (V )  vV deg  (V )  E

Refer to example4.

Some special simple graphs

Example(page601): complete graphs

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.

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

Read Example 8(page 602).

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).

We call the pair (V1 ,V2 ) 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

V1  V1 ,V3 ,V5 andV2  V2 ,V4 ,V6 

and every edge of C6 connects a vertex in V1 and a vertex in V2 .

Example:

K3 is not bipartite .

Suppose V1  {V1},V2{V2 ,V3}

Since there is an edge between V2 andV3 , K3 is not a bipartite graph .

9
M131-Chapter9 By Ms. Suha Al-Shaikh-Dammam

Example: show that graph G is bipartite

Solution: since the vertex set of G , V  V1  V2 where V1  {a, b, d}andV2{c, e, f , g}

And every edge is a connection of V1andV2 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 W  V and F  E.


A sub graph H of G is proper sub graph if H≠G.
(2) Union of two simple Graphs: G1  (V1 , E1 )andG2  (V2 , E2 ) is the simple
graph with vertex set V1  V2 and edges set E1  E2 , and denoted as G1  G2

11
M131-Chapter9 By Ms. Suha Al-Shaikh-Dammam

Section9.3: Graph Representations

• Graph representations:

– Adjacency lists.

– Adjacency matrices.

Undirected: Adjacency Lists

Example: Use adjacency lists to describe the following graph:

Solution: An adjacency list for a simple graph

Undirected: Adjacency Matrices

Matrix A=[aij], where aij is 1 if {vi, vj} is an edge of G, 0 otherwise.

1 if {Vi ,V j }is an edge of G


aij  
Example: 0 otherwise

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 .

Example: use an adjacency matrix to represent the pseudo graph.

Solution: the adjacency matrix using the ordering of vertices a,b,c,d is:

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 a j to ai when there is an edge from ai to a j

3) Adjacency matrices can also be used to represent directed multi graphs

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:

Another way to represent graphs is to use incidence matrices. Let G=(V,E) be an


undirected graph. Suppose that V1 ,V2 ,...,Vn are the vertices and e1 , e2 ,..., en

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

1 when edge e j incident with Vi


mij  
0 otherwise

Example page 614:

Represent the following graph with an incidence matrix:

Directed Adjacency Lists


1 row per node, listing the terminal nodes of each edge incident from that node.

13
M131-Chapter9 By Ms. Suha Al-Shaikh-Dammam

Directed: Adjacency Matrices

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
{xn1 , 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 }

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.

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?

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 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
( xn1 , 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.

Read examples 2,3 and 4 page 623.

15
M131-Chapter9 By Ms. Suha Al-Shaikh-Dammam

Connectedness In Undirected Graphs:

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]

16
M131-Chapter9 By Ms. Suha Al-Shaikh-Dammam

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

Connectedness in Directed Graph:

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.

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.

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).

18

Você também pode gostar