chapter # 10 : graphssite.iugaza.edu.ps/musbahshaat/files/chapter10_handout... · 2013. 12. 3. ·...

30
ECOM 2311- Discrete Mathematics Chapter # 10 : Graphs Fall, 2013/2014 ECOM 2311- Discrete Mathematics - Ch.10 Dr. Musbah Shaat 1 / 30

Upload: others

Post on 19-Aug-2020

1 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Chapter # 10 : Graphssite.iugaza.edu.ps/musbahshaat/files/chapter10_handout... · 2013. 12. 3. · ECOM 2311- Discrete Mathematics Chapter # 10 : Graphs Fall, 2013/2014 ECOM 2311-

ECOM 2311- Discrete Mathematics

Chapter # 10 : Graphs

Fall, 2013/2014

ECOM 2311- Discrete Mathematics - Ch.10 Dr. Musbah Shaat 1 / 30

Page 2: Chapter # 10 : Graphssite.iugaza.edu.ps/musbahshaat/files/chapter10_handout... · 2013. 12. 3. · ECOM 2311- Discrete Mathematics Chapter # 10 : Graphs Fall, 2013/2014 ECOM 2311-

Outline

1 Graphs and Graph Models

2 Graph Terminology and Special Types of Graphs

3 Representing Graphs and Graph Isomorphism

4 Connectivity

5 Shortest-Path Problems

ECOM 2311- Discrete Mathematics - Ch.10 Dr. Musbah Shaat 2 / 30

Page 3: Chapter # 10 : Graphssite.iugaza.edu.ps/musbahshaat/files/chapter10_handout... · 2013. 12. 3. · ECOM 2311- Discrete Mathematics Chapter # 10 : Graphs Fall, 2013/2014 ECOM 2311-

Graphs and Graph Models

A graph G = (V ,E ) consists of V , a nonempty set of vertices (or nodes)and E, a set of edges. Each edge has either one or two vertices associatedwith it, called its endpoints. An edge is said to connect its endpoints.

ECOM 2311- Discrete Mathematics - Ch.10 Dr. Musbah Shaat 3 / 30

Page 4: Chapter # 10 : Graphssite.iugaza.edu.ps/musbahshaat/files/chapter10_handout... · 2013. 12. 3. · ECOM 2311- Discrete Mathematics Chapter # 10 : Graphs Fall, 2013/2014 ECOM 2311-

Graph Terminology and Special Types of GraphsBasic Terminology

Two vertices u and v in an undirected graph G are called adjacent (orneighbors) in G if u and v are endpoints of an edge e of G . Such anedge e is called incident with the vertices u and v and e is said toconnect u and v .

The set of all neighbors of a vertex v of G = (V ,E ), denoted by N(v), iscalled 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, N(A) = ∪v∈AN(v).

The degree of a vertex in an undirected graph is the number of edgesincident with it, except that a loop at a vertex contributes twice to thedegree of that vertex. The degree of the vertex v is denoted by deg(v).A vertex of degree zero is called isolated. A vertex is pendant if and onlyif it has degree one.

ECOM 2311- Discrete Mathematics - Ch.10 Dr. Musbah Shaat 4 / 30

Page 5: Chapter # 10 : Graphssite.iugaza.edu.ps/musbahshaat/files/chapter10_handout... · 2013. 12. 3. · ECOM 2311- Discrete Mathematics Chapter # 10 : Graphs Fall, 2013/2014 ECOM 2311-

Graph Terminology and Special Types of GraphsBasic Terminology

Example: What are the degrees and what are the neighborhoods of thevertices in the graph below?.

deg(a) = 4, deg(b) = deg(e) = 6, deg(c) = 1, and deg(d) = 5. Theneighborhoods of these vertices are N(a) = {b, d , e},N(b) = {a, b, c , d , e}, N(c) = {b}, N(d) = {a, b, e}, andN(e) = {a, b, d}.

ECOM 2311- Discrete Mathematics - Ch.10 Dr. Musbah Shaat 5 / 30

Page 6: Chapter # 10 : Graphssite.iugaza.edu.ps/musbahshaat/files/chapter10_handout... · 2013. 12. 3. · ECOM 2311- Discrete Mathematics Chapter # 10 : Graphs Fall, 2013/2014 ECOM 2311-

Graph Terminology and Special Types of GraphsBasic Terminology

THE HANDSHAKING THEOREM

Let G = (V ,E ) be an undirected graph with m edges. Then2m =

∑v∈V deg(v)

When (u, v) is an edge of the graph G with directed edges, u is said to beadjacent to v and v is said to be adjacent from u. The vertex u is calledthe initial vertex of (u, v), and v is called the terminal or end vertex of(u, v). The initial vertex and terminal vertex of a loop are the same.

In a graph with directed edges the in-degree of a vertex v , denoted bydeg−(v), is the number of edges with v as their terminal vertex. Theout-degree of v , denoted by deg+(v), is the number of edges with v astheir initial vertex. (Note that a loop at a vertex contributes 1 to boththe in-degree and the out-degree of this vertex.)

Let G = (V ,E ) be a graph with directed edges. Then∑v∈V deg−(v) =

∑v∈V deg+(v) = |E |

ECOM 2311- Discrete Mathematics - Ch.10 Dr. Musbah Shaat 6 / 30

Page 7: Chapter # 10 : Graphssite.iugaza.edu.ps/musbahshaat/files/chapter10_handout... · 2013. 12. 3. · ECOM 2311- Discrete Mathematics Chapter # 10 : Graphs Fall, 2013/2014 ECOM 2311-

Graph Terminology and Special Types of GraphsBasic Terminology

Example: Find the in-degree and out-degree of each vertex in the graphbelow with directed edges.

The in-degrees aredeg−(a) = 2, deg−(b) = 2, deg−(c) = 3, deg−(d) = 2, deg−(e) = 3,and deg−(f ) = 0.

The out-degrees aredeg+(a) = 4, deg+(b) = 1, deg+(c) = 2, deg+(d) = 2, deg+(e) = 3,and deg+(f ) = 0.

ECOM 2311- Discrete Mathematics - Ch.10 Dr. Musbah Shaat 7 / 30

Page 8: Chapter # 10 : Graphssite.iugaza.edu.ps/musbahshaat/files/chapter10_handout... · 2013. 12. 3. · ECOM 2311- Discrete Mathematics Chapter # 10 : Graphs Fall, 2013/2014 ECOM 2311-

Graph Terminology and Special Types of GraphsSome Special Simple Graphs

A complete graph on n vertices, denoted by Kn, is a simple graph thatcontains exactly one edge between each pair of distinct vertices.

A cycle Cn, n ≥ 3, consists of n vertices v1, v2, · · · , vn and edges{v1, v2}, {v2, v3}, · · · , {vn−1, vn}, and {vn, v1}.

ECOM 2311- Discrete Mathematics - Ch.10 Dr. Musbah Shaat 8 / 30

Page 9: Chapter # 10 : Graphssite.iugaza.edu.ps/musbahshaat/files/chapter10_handout... · 2013. 12. 3. · ECOM 2311- Discrete Mathematics Chapter # 10 : Graphs Fall, 2013/2014 ECOM 2311-

Graph Terminology and Special Types of GraphsSome Special Simple Graphs

We obtain a wheel Wn when we add an additional vertex to a cycle Cn,for n ≥ 3, and connect this new vertex to each of the n vertices in Cn, bynew edges.

ECOM 2311- Discrete Mathematics - Ch.10 Dr. Musbah Shaat 9 / 30

Page 10: Chapter # 10 : Graphssite.iugaza.edu.ps/musbahshaat/files/chapter10_handout... · 2013. 12. 3. · ECOM 2311- Discrete Mathematics Chapter # 10 : Graphs Fall, 2013/2014 ECOM 2311-

Graph Terminology and Special Types of GraphsBipartite Graphs

A simple graph G is called bipartite if its vertex set V can be partitionedinto two disjoint sets V1 and V2 such that every edge in the graphconnects a vertex in V1 and a vertex in V2. When this condition holds,we call the pair (V1,V2) a bipartition of the vertex set V of G .

C6 is bipartite because its vertex set can be partitioned into the two setsV1 = {v1, v3, v5} and V2 = {v2, v4, v6}, and every edge of C6 connects avertex in V1 and a vertex in V2.

ECOM 2311- Discrete Mathematics - Ch.10 Dr. Musbah Shaat 10 / 30

Page 11: Chapter # 10 : Graphssite.iugaza.edu.ps/musbahshaat/files/chapter10_handout... · 2013. 12. 3. · ECOM 2311- Discrete Mathematics Chapter # 10 : Graphs Fall, 2013/2014 ECOM 2311-

Graph Terminology and Special Types of GraphsBipartite Graphs

Example: Are the graphs G and H displayed below bipartite?

Graph G is bipartite because its vertex set is the union of twodisjoint sets, {a, b, d} and {c , e, f , g}.Graph H is not bipartite because its vertex set cannot be partitionedinto two subsets so that edges do not connect two vertices from thesame subset.

THEOREM

A simple graph is bipartite if and only if it is possible to assign one oftwo different colors to each vertex of the graph so that no two adjacentvertices are assigned the same color.

ECOM 2311- Discrete Mathematics - Ch.10 Dr. Musbah Shaat 11 / 30

Page 12: Chapter # 10 : Graphssite.iugaza.edu.ps/musbahshaat/files/chapter10_handout... · 2013. 12. 3. · ECOM 2311- Discrete Mathematics Chapter # 10 : Graphs Fall, 2013/2014 ECOM 2311-

Graph Terminology and Special Types of GraphsBipartite Graphs

Complete Bipartite Graphs

A complete bipartite graph Km,n is a bipartite graph that has its vertexset partitioned into two subsets of m and n vertices, respectively and inwhich every vertex in V1 is joined to every vertex in V2.

ECOM 2311- Discrete Mathematics - Ch.10 Dr. Musbah Shaat 12 / 30

Page 13: Chapter # 10 : Graphssite.iugaza.edu.ps/musbahshaat/files/chapter10_handout... · 2013. 12. 3. · ECOM 2311- Discrete Mathematics Chapter # 10 : Graphs Fall, 2013/2014 ECOM 2311-

Representing Graphs and Graph IsomorphismRepresenting Graphs

A way to represent a graph with no multiple edges is to use adjacencylists, which specify the vertices that are adjacent to each vertex of thegraph.

ECOM 2311- Discrete Mathematics - Ch.10 Dr. Musbah Shaat 13 / 30

Page 14: Chapter # 10 : Graphssite.iugaza.edu.ps/musbahshaat/files/chapter10_handout... · 2013. 12. 3. · ECOM 2311- Discrete Mathematics Chapter # 10 : Graphs Fall, 2013/2014 ECOM 2311-

Representing Graphs and Graph IsomorphismAdjacency Matrices

Suppose that G = (V ,E ) is a simple graph where |V | = n. Suppose thatthe vertices of G are listed arbitrarily as v1, v2, · · · , vn. The adjacencymatrix A (or AG ) of G , with respect to this listing of the vertices, is then × n zeroone matrix with 1 as its (i , j)th entry when vi and vj areadjacent, and 0 as its (i , j)th entry when they are not adjacent.

ECOM 2311- Discrete Mathematics - Ch.10 Dr. Musbah Shaat 14 / 30

Page 15: Chapter # 10 : Graphssite.iugaza.edu.ps/musbahshaat/files/chapter10_handout... · 2013. 12. 3. · ECOM 2311- Discrete Mathematics Chapter # 10 : Graphs Fall, 2013/2014 ECOM 2311-

Representing Graphs and Graph IsomorphismIncidence Matrices

Let G = (V ,E ) be an undirected graph. Suppose that v1, v2, · · · , vn arethe vertices and e1, e2, · · · , em are the edges of G . Then the incidencematrix with respect to this ordering of V and E is the n ×m matrixM = [mij ], where mij = 1 when edge ej is incident with vi and zerootherwise.

ECOM 2311- Discrete Mathematics - Ch.10 Dr. Musbah Shaat 15 / 30

Page 16: Chapter # 10 : Graphssite.iugaza.edu.ps/musbahshaat/files/chapter10_handout... · 2013. 12. 3. · ECOM 2311- Discrete Mathematics Chapter # 10 : Graphs Fall, 2013/2014 ECOM 2311-

Representing Graphs and Graph IsomorphismIsomorphism of Graphs

Given graphs G1 = (V1,E1) and G2 = (V2,E2), we say G1 is isomorphicto G2 and write G1

∼= G2 if there is a bijective function ψ from V1 to V2

such that: If vw is an edge in G1, then ψ(v)ψ(w) is an edge in G2.

If ψ : G1 → G2, then ψ(u) = A, ψ(v) = C , ψ(w) = D, ψ(x) = B.

G1 and G2 are isomorphic.

The number of vertices, the number of edges, and the number of verticesof each degree are all invariants under isomorphism.

ECOM 2311- Discrete Mathematics - Ch.10 Dr. Musbah Shaat 16 / 30

Page 17: Chapter # 10 : Graphssite.iugaza.edu.ps/musbahshaat/files/chapter10_handout... · 2013. 12. 3. · ECOM 2311- Discrete Mathematics Chapter # 10 : Graphs Fall, 2013/2014 ECOM 2311-

Representing Graphs and Graph IsomorphismIsomorphism of Graphs

Example: Show that the graphs displayed in the figure below are notisomorphic.

Both G and H have five vertices and six edges. However,H has a vertexof degree one, namely, e, whereas G has no vertices of degree one. It

follows that G and H are not isomorphic.

ECOM 2311- Discrete Mathematics - Ch.10 Dr. Musbah Shaat 17 / 30

Page 18: Chapter # 10 : Graphssite.iugaza.edu.ps/musbahshaat/files/chapter10_handout... · 2013. 12. 3. · ECOM 2311- Discrete Mathematics Chapter # 10 : Graphs Fall, 2013/2014 ECOM 2311-

Representing Graphs and Graph IsomorphismIsomorphism of Graphs

Example: Determine whether the graphs shown in the figure below areisomorphic.

The graphs G and H both have eight vertices and 10 edges. Theyalso both have four vertices of degree two and four of degree three.Because these invariants all agree, it is still conceivable that thesegraphs are isomorphic.

However, G and H are not isomorphic. To see this, note thatbecause deg(a) = 2 in G, a must correspond to either t , u, x, or yin H, because these are the vertices of degree two in H. However,each of these four vertices in H is adjacent to another vertex ofdegree two in H, which is not true for a in G.

ECOM 2311- Discrete Mathematics - Ch.10 Dr. Musbah Shaat 18 / 30

Page 19: Chapter # 10 : Graphssite.iugaza.edu.ps/musbahshaat/files/chapter10_handout... · 2013. 12. 3. · ECOM 2311- Discrete Mathematics Chapter # 10 : Graphs Fall, 2013/2014 ECOM 2311-

ConnectivityPaths and Isomorphism

Let n be a nonnegative integer and G an undirected graph. A path oflength n from u to v in G is a sequence of n edges e1, · · · , en of G forwhich there exists a sequence x0 = u, x1, · · · , xn−1, xn = v of verticessuch that ei has, for i = 1, · · · , n, the endpoints xi−1 and xi . When thegraph is simple, we denote this path by its vertex sequence x0, x1, · · · , xn.The path is a circuit if it begins and ends at the same vertex, that is, ifu = v , and has length greater than zero. A path or circuit is simple if itdoes not contain the same edge more than once.

There are several ways that paths and circuits can help determinewhether two graphs are isomorphic.

For example, the existence of a simple circuit of a particular lengthis a useful invariant that can be used to show that two graphs arenot isomorphic.

A useful isomorphic invariant for simple graphs is the existence of asimple circuit of length k, where k is a positive integer greater than2.

ECOM 2311- Discrete Mathematics - Ch.10 Dr. Musbah Shaat 19 / 30

Page 20: Chapter # 10 : Graphssite.iugaza.edu.ps/musbahshaat/files/chapter10_handout... · 2013. 12. 3. · ECOM 2311- Discrete Mathematics Chapter # 10 : Graphs Fall, 2013/2014 ECOM 2311-

ConnectivityPaths and Isomorphism

Example: Determine whether the graphs shown in the figure below areisomorphic.

Both G and H have six vertices and eight edges. Each has fourvertices of degree three, and two vertices of degree two. So, thethree invariants all agree for the two graphs.

However, H has a simple circuit of length three, namely,v1, v2, v6, v1, whereas G has no simple circuit of length three, as canbe determined by inspection ⇒ G and H are not isomorphic.

ECOM 2311- Discrete Mathematics - Ch.10 Dr. Musbah Shaat 20 / 30

Page 21: Chapter # 10 : Graphssite.iugaza.edu.ps/musbahshaat/files/chapter10_handout... · 2013. 12. 3. · ECOM 2311- Discrete Mathematics Chapter # 10 : Graphs Fall, 2013/2014 ECOM 2311-

Shortest-Path ProblemsIntroduction

Many problems can be modeled using graphs with weights assignedto their edges.

Graphs that have a number assigned to each edge are calledweighted graphs.

Determining a path of least length between two vertices in anetwork is one of the problems that arise frequently.

Let the length of a path in a weighted graph be the sum of theweights of the edges of this path.

The question is: What is a shortest path, that is, a path of leastlength, between two given vertices?

Another important problem involving weighted graphs asks for acircuit of shortest total length that visits every vertex of a completegraph exactly once.

This is the famous traveling salesperson problem, which asks for anorder in which a salesperson should visit each of the cities on hisroute exactly once so that he travels the minimum total distance.

ECOM 2311- Discrete Mathematics - Ch.10 Dr. Musbah Shaat 21 / 30

Page 22: Chapter # 10 : Graphssite.iugaza.edu.ps/musbahshaat/files/chapter10_handout... · 2013. 12. 3. · ECOM 2311- Discrete Mathematics Chapter # 10 : Graphs Fall, 2013/2014 ECOM 2311-

Shortest-Path ProblemsA Shortest-Path Algorithm

There are several different algorithms that find a shortest pathbetween two vertices in a weighted graph.

We will present a greedy algorithm discovered by the Dutchmathematician Edsger Dijkstra in 1959.

The version we will describe solves this problem in undirectedweighted graphs where all the weights are positive.

At the start of execution of the algorithm, each vertex u of G isgiven a label L(u), which indicates the current best estimate of thelength of the shortest path from a to u.

L(a) is initially set equal to 0 because the shortest path from a to ahas length zero.

The label L(u) of each vertex u other than a is initially set equal toa number, denoted ∞.

As execution of the algorithm progresses, the values of L(u) arechanged, eventually becoming the actual lengths of the shortestpaths from a to u in G.

ECOM 2311- Discrete Mathematics - Ch.10 Dr. Musbah Shaat 22 / 30

Page 23: Chapter # 10 : Graphssite.iugaza.edu.ps/musbahshaat/files/chapter10_handout... · 2013. 12. 3. · ECOM 2311- Discrete Mathematics Chapter # 10 : Graphs Fall, 2013/2014 ECOM 2311-

Shortest-Path ProblemsA Shortest-Path Algorithm

ECOM 2311- Discrete Mathematics - Ch.10 Dr. Musbah Shaat 23 / 30

Page 24: Chapter # 10 : Graphssite.iugaza.edu.ps/musbahshaat/files/chapter10_handout... · 2013. 12. 3. · ECOM 2311- Discrete Mathematics Chapter # 10 : Graphs Fall, 2013/2014 ECOM 2311-

Shortest-Path ProblemsA Shortest-Path Algorithm

ECOM 2311- Discrete Mathematics - Ch.10 Dr. Musbah Shaat 24 / 30

Page 25: Chapter # 10 : Graphssite.iugaza.edu.ps/musbahshaat/files/chapter10_handout... · 2013. 12. 3. · ECOM 2311- Discrete Mathematics Chapter # 10 : Graphs Fall, 2013/2014 ECOM 2311-

Shortest-Path ProblemsA Shortest-Path Algorithm

ECOM 2311- Discrete Mathematics - Ch.10 Dr. Musbah Shaat 25 / 30

Page 26: Chapter # 10 : Graphssite.iugaza.edu.ps/musbahshaat/files/chapter10_handout... · 2013. 12. 3. · ECOM 2311- Discrete Mathematics Chapter # 10 : Graphs Fall, 2013/2014 ECOM 2311-

Shortest-Path ProblemsA Shortest-Path Algorithm

Shortest path between A and Z is [a,c,b,d,e,z]

ECOM 2311- Discrete Mathematics - Ch.10 Dr. Musbah Shaat 26 / 30

Page 27: Chapter # 10 : Graphssite.iugaza.edu.ps/musbahshaat/files/chapter10_handout... · 2013. 12. 3. · ECOM 2311- Discrete Mathematics Chapter # 10 : Graphs Fall, 2013/2014 ECOM 2311-

Shortest-Path ProblemsA Shortest-Path Algorithm

Shortest path between A and Z is [s,a,b,t]

ECOM 2311- Discrete Mathematics - Ch.10 Dr. Musbah Shaat 27 / 30

Page 28: Chapter # 10 : Graphssite.iugaza.edu.ps/musbahshaat/files/chapter10_handout... · 2013. 12. 3. · ECOM 2311- Discrete Mathematics Chapter # 10 : Graphs Fall, 2013/2014 ECOM 2311-

Shortest-Path ProblemsA Shortest-Path Algorithm

Shortest path between A and Z is [a,c,d,e,g,z]

ECOM 2311- Discrete Mathematics - Ch.10 Dr. Musbah Shaat 28 / 30

Page 29: Chapter # 10 : Graphssite.iugaza.edu.ps/musbahshaat/files/chapter10_handout... · 2013. 12. 3. · ECOM 2311- Discrete Mathematics Chapter # 10 : Graphs Fall, 2013/2014 ECOM 2311-

Shortest-Path ProblemsA Shortest-Path Algorithm

Shortest path between A and Z is [o,a,b,e,d,t] or [o,a,b,d,t]

ECOM 2311- Discrete Mathematics - Ch.10 Dr. Musbah Shaat 29 / 30

Page 30: Chapter # 10 : Graphssite.iugaza.edu.ps/musbahshaat/files/chapter10_handout... · 2013. 12. 3. · ECOM 2311- Discrete Mathematics Chapter # 10 : Graphs Fall, 2013/2014 ECOM 2311-

End of Chapter # 10