18 Graphs 1

51
CMSC 203 - Discrete Structures 1 Let us switch to a new topic: Let us switch to a new topic: Graphs Graphs

Transcript of 18 Graphs 1

8/8/2019 18 Graphs 1

http://slidepdf.com/reader/full/18-graphs-1 1/51

CMSC 203 - Discrete Structures 1

Let us switch to a new topic:Let us switch to a new topic:

GraphsGraphs

8/8/2019 18 Graphs 1

http://slidepdf.com/reader/full/18-graphs-1 2/51

CMSC 203 - Discrete Structures 2

Introduction to GraphsIntroduction to Graphs

Definition:Definition: A A simple graphsimple graph G = (V, E) consists of V,G = (V, E) consists of V,a nonempty set of vertices, and E, a set ofa nonempty set of vertices, and E, a set ofunordered pairsunordered pairs ofof distinctdistinct elements of V calledelements of V callededges.edges.

For each eFor each eE, e = {u, v} where u, vE, e = {u, v} where u, v V.V.

An undirected graph (not simple) may contain loops.An undirected graph (not simple) may contain loops.An edge e is a loop if e = {u, u} for some uAn edge e is a loop if e = {u, u} for some uV.V.

8/8/2019 18 Graphs 1

http://slidepdf.com/reader/full/18-graphs-1 3/51

CMSC 203 - Discrete Structures 3

Introduction to GraphsIntroduction to Graphs

Definition:Definition: A A directed graph directed graph G = (V, E) consists ofG = (V, E) consists ofa set V of vertices and a set E of edges that area set V of vertices and a set E of edges that areordered pairs of elements in V.ordered pairs of elements in V.

For each eFor each eE, e = (u, v) where u, vE, e = (u, v) where u, v V.V.

An edge e is a loop if e = (u, u) for some uAn edge e is a loop if e = (u, u) for some uV.V.

A simple graph is just like a directed graph, butA simple graph is just like a directed graph, butwith no specified direction of its edges.with no specified direction of its edges.

8/8/2019 18 Graphs 1

http://slidepdf.com/reader/full/18-graphs-1 4/51

CMSC 203 - Discrete Structures 4

Graph ModelsGraph ModelsExample I:Example I: How can we represent a network ofHow can we represent a network of

(bi(bi--directional) railways connecting a set of cities?directional) railways connecting a set of cities?We should use aWe should use a simple graphsimple graph with an edge {a, b}with an edge {a, b}indicating a direct train connection between citiesindicating a direct train connection between citiesa and b.a and b.

New YorkNew York

BostonBoston

WashingtonWashington

LLüübeckbeckTorontoToronto

HamburgHamburg

8/8/2019 18 Graphs 1

http://slidepdf.com/reader/full/18-graphs-1 5/51

CMSC 203 - Discrete Structures 5

Graph ModelsGraph ModelsExample II:Example II: In a roundIn a round--robin tournament, eachrobin tournament, each

team plays against each other team exactly once.team plays against each other team exactly once.How can we represent the results of theHow can we represent the results of thetournament (which team beats which other team)?tournament (which team beats which other team)?

We should use aWe should use a directed graphdirected graph with an edge (a, b)with an edge (a, b)indicating that team a beats team b.indicating that team a beats team b.

PenguinsPenguins

BruinsBruins

LLüübeck Giantsbeck Giants

Maple LeafsMaple Leafs

8/8/2019 18 Graphs 1

http://slidepdf.com/reader/full/18-graphs-1 6/51

CMSC 203 - Discrete Structures 6

Graph TerminologyGraph Terminology

Definition:Definition: Two vertices u and v in an undirectedTwo vertices u and v in an undirectedgraph G are calledgraph G are called adjacentadjacent (or(or neighborsneighbors) in G if) in G if{u, v} is an edge in G.{u, v} is an edge in G.

If e = {u, v}, the edge e is calledIf e = {u, v}, the edge e is called incident withincident with thethevertices u and v. The edge e is also said tovertices u and v. The edge e is also said to connectconnectu and v.u and v.

The vertices u and v are calledThe vertices u and v are called endpointsendpoints of theof the

edge {u, v}.edge {u, v}.

8/8/2019 18 Graphs 1

http://slidepdf.com/reader/full/18-graphs-1 7/51

CMSC 203 - Discrete Structures 7

Graph TerminologyGraph Terminology

Definition:Definition: TheThe degreedegree of a vertex in anof a vertex in anundirected graph is the number of edges incidentundirected graph is the number of edges incidentwith it, except that a loop at a vertex contributeswith it, except that a loop at a vertex contributestwice to the degree of that vertex.twice to the degree of that vertex.

In other words, you can determine the degree of aIn other words, you can determine the degree of avertex in a displayed graph byvertex in a displayed graph by counting the linescounting the linesthat touch it.that touch it.

The degree of the vertex v is denoted byThe degree of the vertex v is denoted by deg(v).deg(v).

8/8/2019 18 Graphs 1

http://slidepdf.com/reader/full/18-graphs-1 8/51

CMSC 203 - Discrete Structures 8

Graph TerminologyGraph Terminology

A vertex of degree 0 is calledA vertex of degree 0 is called isolatedisolated, since it is, since it isnot adjacent to any vertex.not adjacent to any vertex.

Note:Note: A vertex with aA vertex with a looploop at it has at leastat it has at least

degree 2 and, by definition, isdegree 2 and, by definition, is not isolatednot isolated, even if, even ifit is not adjacent to anyit is not adjacent to any otherother vertex.vertex.

A vertex of degree 1 is calledA vertex of degree 1 is called pendantpendant. It is. It isadjacent to exactly one other vertex.adjacent to exactly one other vertex.

8/8/2019 18 Graphs 1

http://slidepdf.com/reader/full/18-graphs-1 9/51

CMSC 203 - Discrete Structures 9

Graph TerminologyGraph Terminology

Example:Example: Which vertices in the following graph areWhich vertices in the following graph areisolated, which are pendant, and what is theisolated, which are pendant, and what is themaximum degree? What type of graph is it?maximum degree? What type of graph is it?

aa

bb cc

dd

ff hh

gg j jff

ee

Solution:Solution: Vertex f is isolated, and vertices a, d andVertex f is isolated, and vertices a, d and j are pendant. The maximum degree is deg(g) = 5. j are pendant. The maximum degree is deg(g) = 5.This graph is a pseudograph (undirected, loops).This graph is a pseudograph (undirected, loops).

8/8/2019 18 Graphs 1

http://slidepdf.com/reader/full/18-graphs-1 10/51

CMSC 203 - Discrete Structures 10

Graph TerminologyGraph Terminology

Let us look at the same graph again and determineLet us look at the same graph again and determinethe number of its edges and the sum of thethe number of its edges and the sum of thedegrees of all its vertices:degrees of all its vertices:

aa

bb cc

dd

ff hh

gg j jff

ee

Result:Result: There are 9 edges, and the sum of allThere are 9 edges, and the sum of alldegrees is 18. This is easy to explain: Each newdegrees is 18. This is easy to explain: Each newedge increases the sum of degrees by exactly two.edge increases the sum of degrees by exactly two.

8/8/2019 18 Graphs 1

http://slidepdf.com/reader/full/18-graphs-1 11/51

CMSC 203 - Discrete Structures 11

Graph TerminologyGraph TerminologyT he Handshaking T heorem:T he Handshaking T heorem: Let G = (V, E) be anLet G = (V, E) be an

undirected graph with e edges. Thenundirected graph with e edges. Then2e =2e = §§vvVV deg(v)deg(v)

Example:Example: How many edges are there in a graphHow many edges are there in a graphwith 10 vertices, each of degree 6?with 10 vertices, each of degree 6?

Solution:Solution: The sum of the degrees of the vertices isThe sum of the degrees of the vertices is

6610 = 60. According to the Handshaking Theorem,10 = 60. According to the Handshaking Theorem,it follows that 2e = 60, so there are 30 edges.it follows that 2e = 60, so there are 30 edges.

8/8/2019 18 Graphs 1

http://slidepdf.com/reader/full/18-graphs-1 12/51

CMSC 203 - Discrete Structures 12

Graph TerminologyGraph TerminologyT heorem:T heorem: An undirected graph has an even numberAn undirected graph has an even number

of vertices of odd degree.of vertices of odd degree.Proof:Proof: Let V1 and V2Let V1 and V2 be the set of vertices ofbe the set of vertices ofeven and odd degrees, respectively (Thus V1even and odd degrees, respectively (Thus V1 V2 =V2 =, and V1, and V1 V2 = V).V2 = V).

Then by Handshaking theoremThen by Handshaking theorem

2|E| =2|E| = §§vvVV deg(v) =deg(v) = §§vvV1V1 deg(v) +deg(v) + §§vvV2V2 deg(v)deg(v)

Since both 2|E| andSince both 2|E| and §§vvV1V1 deg(v) are even,deg(v) are even,

§§vvV2V2 deg(v) must be even.deg(v) must be even.Since deg(v) if odd for all vSince deg(v) if odd for all vV2, |V2| must be even.V2, |V2| must be even.

QEDQED

8/8/2019 18 Graphs 1

http://slidepdf.com/reader/full/18-graphs-1 13/51

CMSC 203 - Discrete Structures 13

Graph TerminologyGraph Terminology

Definition:Definition: When (u, v) is an edge of the graph GWhen (u, v) is an edge of the graph Gwith directed edges, u is said to bewith directed edges, u is said to be adjacent toadjacent to v,v,and v is said to beand v is said to be adjacent fromadjacent from u.u.

The vertex u is called theThe vertex u is called the initial vertexinitial vertex of (u, v),of (u, v),and v is called theand v is called the terminal vertexterminal vertex of (u, v).of (u, v).

The initial vertex and terminal vertex of a loop areThe initial vertex and terminal vertex of a loop arethe same.the same.

8/8/2019 18 Graphs 1

http://slidepdf.com/reader/full/18-graphs-1 14/51

CMSC 203 - Discrete Structures 14

Graph TerminologyGraph TerminologyDefinition:Definition: In a graph with directed edges, theIn a graph with directed edges, the inin--

degreedegree of a vertex v, denoted byof a vertex v, denoted by degdeg--(v)(v), is the, is thenumber of edges with v as theirnumber of edges with v as their terminal vertexterminal vertex..

TheThe outout--degreedegree of v, denoted byof v, denoted by degdeg++(v)(v), is the, is the

number of edges with v as their initial vertex.number of edges with v as their initial vertex.Question:Question: How does adding a loop to a vertexHow does adding a loop to a vertexchange the inchange the in--degree and outdegree and out--degree of thatdegree of that

vertex?vertex?Answer:Answer: It increases both the inIt increases both the in--degree and thedegree and theoutout--degree by one.degree by one.

8/8/2019 18 Graphs 1

http://slidepdf.com/reader/full/18-graphs-1 15/51

CMSC 203 - Discrete Structures 15

Graph TerminologyGraph TerminologyExample:Example: What are the inWhat are the in--degrees and outdegrees and out--

degrees of the vertices a, b, c, d in this graph:degrees of the vertices a, b, c, d in this graph:

aa bb

ccdd

degdeg--(a) = 1(a) = 1

degdeg++(a) = 2(a) = 2

degdeg--(b) = 4(b) = 4

degdeg++(b) = 2(b) = 2

degdeg--(d) = 2(d) = 2degdeg++(d) = 1(d) = 1

degdeg--(c) = 0(c) = 0degdeg++(c) = 2(c) = 2

8/8/2019 18 Graphs 1

http://slidepdf.com/reader/full/18-graphs-1 16/51

CMSC 203 - Discrete Structures 16

Graph TerminologyGraph Terminology

T heorem:T heorem: Let G = (V, E) be a graph with directedLet G = (V, E) be a graph with directededges. Then:edges. Then:

§§vvVV degdeg--(v) =(v) = §§vvVV degdeg++(v) = |E|(v) = |E|

This is easy to see, because every new edgeThis is easy to see, because every new edgeincreases both the sum of inincreases both the sum of in--degrees and the sumdegrees and the sumof outof out--degrees by one.degrees by one.

8/8/2019 18 Graphs 1

http://slidepdf.com/reader/full/18-graphs-1 17/51

CMSC 203 - Discrete Structures 17

Special GraphsSpecial Graphs

Definition:Definition: TheThe complete graphcomplete graph on n vertices,on n vertices,denoted by Kdenoted by Knn, is the simple graph that contains, is the simple graph that containsexactly one edge between each pair of distinctexactly one edge between each pair of distinctvertices.vertices.

KK11 KK22 KK33 KK44 KK55

8/8/2019 18 Graphs 1

http://slidepdf.com/reader/full/18-graphs-1 18/51

8/8/2019 18 Graphs 1

http://slidepdf.com/reader/full/18-graphs-1 19/51

CMSC 203 - Discrete Structures 19

Special GraphsSpecial Graphs

Definition:Definition: We obtain theWe obtain the wheelwheel WWnn when we addwhen we addan additional vertex to the cycle Can additional vertex to the cycle Cnn, for n, for n uu 3, and3, andconnect this new vertex to each of the n verticesconnect this new vertex to each of the n verticesin Cin Cnn by adding new edges.by adding new edges.

WW33 WW44 WW55 WW66

8/8/2019 18 Graphs 1

http://slidepdf.com/reader/full/18-graphs-1 20/51

CMSC 203 - Discrete Structures 20

Special GraphsSpecial GraphsDefinition:Definition: TheThe nn--cube,cube, denoted by Qdenoted by Qnn, is the, is the

graph that has vertices representing the 2graph that has vertices representing the 2nn bitbitstrings of length n. Two vertices are adjacent ifstrings of length n. Two vertices are adjacent ifand only if the bit strings that they representand only if the bit strings that they representdiffer in exactly one bit position.differ in exactly one bit position.

QQ11 QQ22 QQ33

00 11

0000 0101

11111010

000000 001001

101101100100

010010 011011

111111110110

8/8/2019 18 Graphs 1

http://slidepdf.com/reader/full/18-graphs-1 21/51

CMSC 203 - Discrete Structures 21

Special GraphsSpecial GraphsDefinition:Definition: A simple graph is calledA simple graph is called bipartitebipartite if itsif its

vertex set V can be partitioned into two disjointvertex set V can be partitioned into two disjointnonempty sets Vnonempty sets V11 and Vand V22 such that every edge insuch that every edge inthe graph connects a vertex in Vthe graph connects a vertex in V11 with a vertex inwith a vertex inVV22 (so that no edge in G connects either two(so that no edge in G connects either twovertices in Vvertices in V

11or two vertices in Vor two vertices in V

22).).

For example, consider a graph that representsFor example, consider a graph that representseach person in a village by a vertex and eacheach person in a village by a vertex and eachmarriage by an edge.marriage by an edge.

This graph isThis graph is bipartitebipartite, because each edge, because each edgeconnects a vertex in theconnects a vertex in the subset of malessubset of males with awith avertex in thevertex in the subset of femalessubset of females (if we think of(if we think oftraditional marriages).traditional marriages).

8/8/2019 18 Graphs 1

http://slidepdf.com/reader/full/18-graphs-1 22/51

CMSC 203 - Discrete Structures 22

Special GraphsSpecial Graphs

Example I:

Example I:

I

s CI

s C33 bipartite?bipartite?vv11

vv22

vv33

No,No, because there is no way tobecause there is no way topartition the vertices into two setspartition the vertices into two setsso that there are no edges withso that there are no edges with

both endpoints in the same set.both endpoints in the same set.

Example II:Example II: Is CIs C66 bipartite?bipartite?

vv55

vv11

vv22

vv33 vv44

vv66vv11 vv66

vv22vv55

vv33vv44

Yes,Yes, becausebecausewe can displaywe can displayCC66 like this:like this:

8/8/2019 18 Graphs 1

http://slidepdf.com/reader/full/18-graphs-1 23/51

CMSC 203 - Discrete Structures 23

Special GraphsSpecial Graphs

Definition:Definition: TheThe complete bipartite graphcomplete bipartite graph KKm,nm,n

isisthe graph that has its vertex set partitioned intothe graph that has its vertex set partitioned intotwo subsets of m and n vertices, respectively. Twotwo subsets of m and n vertices, respectively. Twovertices are connected if and only if they are invertices are connected if and only if they are indifferent subsets.different subsets.

KK3,23,2 KK3,43,4

8/8/2019 18 Graphs 1

http://slidepdf.com/reader/full/18-graphs-1 24/51

CMSC 203 - Discrete Structures 24

Operations on GraphsOperations on Graphs

Definition:Definition:A

 A

 subgraphsubgraph of a graph G = (V, E) is aof a graph G = (V, E) is agraph H = (W, F) where Wgraph H = (W, F) where WV and FV and FE.E.

Note:Note: Of course, H is a valid graph, so we cannotOf course, H is a valid graph, so we cannotremove any endpoints of remaining edges whenremove any endpoints of remaining edges when

creating H.creating H.Example:Example:

KK55 subgraph of Ksubgraph of K55

8/8/2019 18 Graphs 1

http://slidepdf.com/reader/full/18-graphs-1 25/51

CMSC 203 - Discrete Structures 25

Operations on GraphsOperations on Graphs

Definition:Definition: TheThe unionunion of two simple graphs Gof two simple graphs G11 ==(V(V11, E, E11) and G) and G22 = (V= (V22, E, E22) is the simple graph with) is the simple graph withvertex set Vvertex set V11 VV22 and edge set Eand edge set E11 EE22..

The union of GThe union of G11 and Gand G22 is denoted byis denoted by GG11 GG22..

GG11 GG22 GG11GG22 = K= K55

8/8/2019 18 Graphs 1

http://slidepdf.com/reader/full/18-graphs-1 26/51

CMSC 203 - Discrete Structures 26

Representing GraphsRepresenting Graphsaa

bb

cc

dd

aa

bb

cc

dd

a, da, dbba, da, dcc

a, b, ca, b, cdd

b, c, db, c, daa

AdjacentAdjacentVerticesVertices

VertexVertex

aabbcc

a, b, ca, b, cdd

ccaa

TerminalTerminalVerticesVertices

InitialInitialVertexVertex

8/8/2019 18 Graphs 1

http://slidepdf.com/reader/full/18-graphs-1 27/51

CMSC 203 - Discrete Structures 27

Representing GraphsRepresenting Graphs

Definition:Definition: Let G = (V, E) be a simple graph withLet G = (V, E) be a simple graph with|V| = n. Suppose that the vertices of G are listed in|V| = n. Suppose that the vertices of G are listed inarbitrary order as varbitrary order as v11, v, v22, «, v, «, vnn..

TheThe adjacency matrixadjacency matrix A (or AA (or AGG) of G, with respect) of G, with respectto this listing of the vertices, is the nto this listing of the vertices, is the nvvn zeron zero--oneonematrix with 1 as its (i, j)th entry when vmatrix with 1 as its (i, j)th entry when vii and vand v j j areareadjacent, and 0 otherwise.adjacent, and 0 otherwise.

In other words, for an adjacency matrix A = [aIn other words, for an adjacency matrix A = [aijij],],aaijij = 1= 1 if {vif {vii, v, v j j} is an edge of G,} is an edge of G,aaijij = 0= 0 otherwise.otherwise.

8/8/2019 18 Graphs 1

http://slidepdf.com/reader/full/18-graphs-1 28/51

CMSC 203 - Discrete Structures 28

Representing GraphsRepresenting Graphs

aabb

cc

dd

Example:Example: What is the adjacencyWhat is the adjacencymatrix Amatrix AGG for the followingfor the followinggraph G based on the order ofgraph G based on the order ofvertices a, b, c, d ?vertices a, b, c, d ?

Solution:Solution:

¼¼¼¼

½

»

¬¬¬¬

-

«

!

0111

1001

1001

1110

G A

Note:Note: Adjacency matrices of undirected graphsAdjacency matrices of undirected graphsare always symmetric.are always symmetric.

8/8/2019 18 Graphs 1

http://slidepdf.com/reader/full/18-graphs-1 29/51

CMSC 203 - Discrete Structures 29

Representing GraphsRepresenting Graphs

Definition:Definition: Let G = (V, E) be an undirected graphLet G = (V, E) be an undirected graphwith |V| = n. Suppose that the vertices and edgeswith |V| = n. Suppose that the vertices and edgesof G are listed in arbitrary order as vof G are listed in arbitrary order as v11, v, v22, «, v, «, vnn andandee11, e, e22, «, e, «, emm, respectively., respectively.

TheThe incidence matrixincidence matrix of G with respect to thisof G with respect to thislisting of the vertices and edges is the nlisting of the vertices and edges is the nvvm zerom zero--one matrix with 1 as its (i, j)th entry when edge eone matrix with 1 as its (i, j)th entry when edge e j jis incident with vis incident with vii, and 0 otherwise., and 0 otherwise.

In other words, for an incidence matrix M = [mIn other words, for an incidence matrix M = [mijij],],mmijij = 1= 1 if edge eif edge e j j is incident with vis incident with viimmijij = 0= 0 otherwise.otherwise.

8/8/2019 18 Graphs 1

http://slidepdf.com/reader/full/18-graphs-1 30/51

CMSC 203 - Discrete Structures 30

Representing GraphsRepresenting GraphsExample:Example: What is the incidenceWhat is the incidence

matrix M for the followingmatrix M for the followinggraph G based on the order ofgraph G based on the order ofvertices a, b, c, d and edges 1, 2,vertices a, b, c, d and edges 1, 2,3, 4, 5, 6?3, 4, 5, 6?

Solution:Solution:

¼¼¼¼

½

»

¬¬¬¬

-

«

!

001110

111000

000101010011

 M 

Note:Note: Incidence matrices of directed graphsIncidence matrices of directed graphscontain two 1s per column for edges connectingcontain two 1s per column for edges connectingtwo vertices and one 1 per column for loops.two vertices and one 1 per column for loops.

aabb

cc

dd

1122

445533

66

8/8/2019 18 Graphs 1

http://slidepdf.com/reader/full/18-graphs-1 31/51

CMSC 203 - Discrete Structures 31

Isomorphism of GraphsIsomorphism of Graphs

Definition:Definition: The simple graphs GThe simple graphs G11 = (V= (V11, E, E11) and G) and G22 ==(V(V22, E, E22) are) are isomorphicisomorphic if there is a bijection (anif there is a bijection (anoneone--toto--one and onto function) f from Vone and onto function) f from V11 to Vto V22 withwiththe property that a and b are adjacent in Gthe property that a and b are adjacent in G11 if andif and

only if f(a) and f(b) are adjacent in Gonly if f(a) and f(b) are adjacent in G22, for all a and, for all a andb in Vb in V11..

Such a function f is called anSuch a function f is called an isomorphismisomorphism..

In other words, GIn other words, G11 and Gand G22 are isomorphic if theirare isomorphic if theirvertices can be ordered in such a way that thevertices can be ordered in such a way that theadjacency matrices Madjacency matrices MGG11

and Mand MGG22are identical.are identical.

8/8/2019 18 Graphs 1

http://slidepdf.com/reader/full/18-graphs-1 32/51

CMSC 203 - Discrete Structures 32

Isomorphism of GraphsIsomorphism of Graphs

From a visual standpoint, GFrom a visual standpoint, G11 and Gand G22 are isomorphicare isomorphicif they can be arranged in such a way that theirif they can be arranged in such a way that theirdisplays are identicaldisplays are identical (of course without changing(of course without changingadjacency).adjacency).

Unfortunately, for two simple graphs, each with nUnfortunately, for two simple graphs, each with nvertices, there arevertices, there are n! possible isomorphismsn! possible isomorphisms thatthatwe have to check in order to show that thesewe have to check in order to show that thesegraphs are isomorphic.graphs are isomorphic.

However, showing that two graphs areHowever, showing that two graphs are notnotisomorphic can be easy.isomorphic can be easy.

8/8/2019 18 Graphs 1

http://slidepdf.com/reader/full/18-graphs-1 33/51

CMSC 203 - Discrete Structures 33

Isomorphism of GraphsIsomorphism of GraphsFor this purpose we can checkFor this purpose we can check inv ariantsinv ariants, that is,, that is,properties that two isomorphic simple graphs mustproperties that two isomorphic simple graphs mustboth have.both have.

For example, they must haveFor example, they must have

the same number of vertices,the same number of vertices, the same number of edges, andthe same number of edges, and

the same degrees of vertices.the same degrees of vertices.

Note that two graphs thatNote that two graphs that differdiffer in any of thesein any of theseinvariants are not isomorphic, but two graphs thatinvariants are not isomorphic, but two graphs thatmatchmatch in all of them are not necessarily isomorphic.in all of them are not necessarily isomorphic.

8/8/2019 18 Graphs 1

http://slidepdf.com/reader/full/18-graphs-1 34/51

CMSC 203 - Discrete Structures 34

Isomorphism of GraphsIsomorphism of GraphsExample I:Example I: Are the following two graphs isomorphic?Are the following two graphs isomorphic?

dd

aa

bb

cc

ee

dd

aa

bb

cc

ee

Solution:Solution: YesYes, they are isomorphic, because they, they are isomorphic, because theycan be arranged to look identical. You can see thiscan be arranged to look identical. You can see this

if in the right graph you move vertex b to the leftif in the right graph you move vertex b to the leftof the edge {a, c}. Then the isomorphism f fromof the edge {a, c}. Then the isomorphism f fromthe left to the right graph is: f(a) = e, f(b) = a,the left to the right graph is: f(a) = e, f(b) = a,f(c) = b, f(d) = c, f(e) = d.f(c) = b, f(d) = c, f(e) = d.

8/8/2019 18 Graphs 1

http://slidepdf.com/reader/full/18-graphs-1 35/51

CMSC 203 - Discrete Structures 35

Isomorphism of GraphsIsomorphism of GraphsExample II:Example II: How about these two graphs?How about these two graphs?

dd

aabb

cc

ee

dd

aa

bb

cc

ee

Solution:Solution: NoNo, they are not isomorphic, because, they are not isomorphic, because

they differ in the degrees of their vertices.they differ in the degrees of their vertices.Vertex d in right graph is of degree one, but thereVertex d in right graph is of degree one, but thereis no such vertex in the left graph.is no such vertex in the left graph.

8/8/2019 18 Graphs 1

http://slidepdf.com/reader/full/18-graphs-1 36/51

CMSC 203 - Discrete Structures 36

ConnectivityConnectivity

Definition:Definition: A A pathpath of length n from u to v, where nof length n from u to v, where nis a positive integer, in anis a positive integer, in an undirected graphundirected graph is ais asequence of edges esequence of edges e11, e, e22, «, e, «, enn of the graph suchof the graph suchthat ethat e11 = {x= {x00, x, x11}, e}, e22 = {x= {x11, x, x22}, «, e}, «, enn = {x= {xnn--11, x, xnn},},

where xwhere x00 = u and x= u and xnn = v.= v.When the graph is simple, we denote this path byWhen the graph is simple, we denote this path byitsits vertex sequencevertex sequence xx00, x, x11, «, x, «, xnn, since it uniquely, since it uniquelydetermines the path.determines the path.

The path is aThe path is a circuitcircuit if it begins and ends at theif it begins and ends at thesame vertex, that is, if u = v.same vertex, that is, if u = v.

8/8/2019 18 Graphs 1

http://slidepdf.com/reader/full/18-graphs-1 37/51

CMSC 203 - Discrete Structures 37

ConnectivityConnectivity

Definition (continued):Definition (continued): The path or circuit is saidThe path or circuit is saidtoto pass throughpass through or traverse xor traverse x11, x, x22, «, x, «, xnn--11..

A path or circuit isA path or circuit is simplesimple if it does not contain theif it does not contain the

same edge more than once.same edge more than once.

8/8/2019 18 Graphs 1

http://slidepdf.com/reader/full/18-graphs-1 38/51

CMSC 203 - Discrete Structures 38

ConnectivityConnectivity

Let us now look at something new:Let us now look at something new:

Definition:Definition: An undirected graph is calledAn undirected graph is called connectedconnectedif there is a path between every pair of distinctif there is a path between every pair of distinctvertices in the graph.vertices in the graph.

For example, any two computers in a network canFor example, any two computers in a network cancommunicate if and only if the graph of thiscommunicate if and only if the graph of thisnetwork is connected.network is connected.

Note:Note: A graph consisting of only one vertex isA graph consisting of only one vertex isalways connected, because it does not contain anyalways connected, because it does not contain anypair of distinct vertices.pair of distinct vertices.

8/8/2019 18 Graphs 1

http://slidepdf.com/reader/full/18-graphs-1 39/51

8/8/2019 18 Graphs 1

http://slidepdf.com/reader/full/18-graphs-1 40/51

CMSC 203 - Discrete Structures 40

ConnectivityConnectivity

Definition:Definition: A graph that is not connected is theA graph that is not connected is theunion of two or more connected subgraphs, eachunion of two or more connected subgraphs, eachpair of which has no vertex in common. Thesepair of which has no vertex in common. Thesedisjoint connected subgraphs are called thedisjoint connected subgraphs are called the

connected componentsconnected components of the graph.of the graph.

8/8/2019 18 Graphs 1

http://slidepdf.com/reader/full/18-graphs-1 41/51

CMSC 203 - Discrete Structures 41

ConnectivityConnectivity

Example:Example: What are the connected components inWhat are the connected components inthe following graph?the following graph?

aa

bb cc

ddff hh

gg j jff

ee

Solution:Solution: The connected components are theThe connected components are thegraphs with vertices {a, b, c, d}, {e}, {f}, {f, g, h, j}.graphs with vertices {a, b, c, d}, {e}, {f}, {f, g, h, j}.

8/8/2019 18 Graphs 1

http://slidepdf.com/reader/full/18-graphs-1 42/51

CMSC 203 - Discrete Structures 42

ConnectivityConnectivity

Definition:Definition: An directed graph isAn directed graph is stronglystronglyconnectedconnected if there is a path from a to b and from bif there is a path from a to b and from bto a whenever a and b are vertices in the graph.to a whenever a and b are vertices in the graph.

Definition:Definition: An directed graph isAn directed graph is weakly connectedweakly connectedif there is a path between any two vertices in theif there is a path between any two vertices in theunderlying undirected graph.underlying undirected graph.

8/8/2019 18 Graphs 1

http://slidepdf.com/reader/full/18-graphs-1 43/51

CMSC 203 - Discrete Structures 43

ConnectivityConnectivityExample:Example: Are the following directed graphsAre the following directed graphsstrongly or weakly connected?strongly or weakly connected?

aa

bb

cc

dd

Weakly connectedWeakly connected, because,, because,

for example, there is no pathfor example, there is no pathfrom b to d.from b to d.

aa

bb

cc

ddStrongly connectedStrongly connected, because, becausethere are paths between allthere are paths between allpossible pairs of vertices.possible pairs of vertices.

8/8/2019 18 Graphs 1

http://slidepdf.com/reader/full/18-graphs-1 44/51

CMSC 203 - Discrete Structures 44

Shortest Path ProblemsShortest Path ProblemsWe can assign weights to the edges of graphs, forWe can assign weights to the edges of graphs, forexample to represent the distance between citiesexample to represent the distance between citiesin a railway network:in a railway network:

ChicagoChicago

TorontoToronto

New YorkNew York

BostonBoston

600600

700700

200200

650650

8/8/2019 18 Graphs 1

http://slidepdf.com/reader/full/18-graphs-1 45/51

CMSC 203 - Discrete Structures 45

Shortest Path ProblemsShortest Path ProblemsSuch weighted graphs can also be used to modelSuch weighted graphs can also be used to modelcomputer networks with response times or costscomputer networks with response times or costsas weights.as weights.

One of the most interesting questions that we canOne of the most interesting questions that we can

investigate with such graphs is:investigate with such graphs is:What is theWhat is the shortest pathshortest path between two verticesbetween two verticesin the graph, that is, the path with thein the graph, that is, the path with the minimal minimal sum of weightssum of weights along the way?along the way?

This corresponds to the shortest train connectionThis corresponds to the shortest train connectionor the fastest connection in a computer network.or the fastest connection in a computer network.

8/8/2019 18 Graphs 1

http://slidepdf.com/reader/full/18-graphs-1 46/51

CMSC 203 - Discrete Structures 46

Dijkstra·s AlgorithmDijkstra·s Algorithm

Dijkstra·s algorithm is an iterative procedure that

Dijkstra·s algorithm is an iterative procedure thatfinds the shortest path between to vertices a andfinds the shortest path between to vertices a and

z in a weighted graph.z in a weighted graph.

It proceeds by finding the length of the shortestIt proceeds by finding the length of the shortest

path from a to successive vertices and addingpath from a to successive vertices and addingthese vertices to a distinguished set of vertices S.these vertices to a distinguished set of vertices S.

The algorithm terminates once it reaches theThe algorithm terminates once it reaches the

vertex z.vertex z.

8/8/2019 18 Graphs 1

http://slidepdf.com/reader/full/18-graphs-1 47/51

CMSC 203 - Discrete Structures 47

The Traveling Salesman ProblemThe Traveling Salesman ProblemTheThe traveling salesman problemtraveling salesman problem is one of theis one of the

classical problems in computer science.classical problems in computer science.A traveling salesman wants to visit a number ofA traveling salesman wants to visit a number ofcities and then return to his starting point. Ofcities and then return to his starting point. Of

course he wants to save time and energy, so hecourse he wants to save time and energy, so hewants to determine thewants to determine the shortest pathshortest path for his trip.for his trip.

We can represent the cities and the distancesWe can represent the cities and the distancesbetween them by a weighted, complete, undirectedbetween them by a weighted, complete, undirected

graph.graph.The problem then is to find theThe problem then is to find the circuit of minimumcircuit of minimumtotal weight that visits each vertex exactly onetotal weight that visits each vertex exactly one..

8/8/2019 18 Graphs 1

http://slidepdf.com/reader/full/18-graphs-1 48/51

CMSC 203 - Discrete Structures 48

The Traveling Salesman ProblemThe Traveling Salesman ProblemExample:Example: What path would the traveling salesmanWhat path would the traveling salesman

take to visit the following cities?take to visit the following cities?

ChicagoChicago

TorontoToronto

New YorkNew York

BostonBoston

600600

700700

200200

650650 550550700700

Solution:Solution: The shortest path is Boston, New York,The shortest path is Boston, New York,Chicago, Toronto, Boston (2,000 miles).Chicago, Toronto, Boston (2,000 miles).

8/8/2019 18 Graphs 1

http://slidepdf.com/reader/full/18-graphs-1 49/51

CMSC 203 - Discrete Structures 49

The Traveling Salesman ProblemThe Traveling Salesman ProblemQuestion:Question: Given n vertices, how many differentGiven n vertices, how many different

cycles Ccycles Cnn can we form by connecting these verticescan we form by connecting these verticeswith edges?with edges?

Solution:Solution: We first choose a starting point. Then weWe first choose a starting point. Then we

have (nhave (n ²² 1) choices for the second vertex in the1) choices for the second vertex in thecycle, (ncycle, (n ²² 2) for the third one, and so on, so there2) for the third one, and so on, so thereare (nare (n ²² 1)! choices for the whole cycle.1)! choices for the whole cycle.

However, this number includes identical cycles thatHowever, this number includes identical cycles that

were constructed inwere constructed in opposite directionsopposite directions..Therefore, the actual number of different cyclesTherefore, the actual number of different cyclesCCnn isis (n(n ²² 1)!/21)!/2..

8/8/2019 18 Graphs 1

http://slidepdf.com/reader/full/18-graphs-1 50/51

CMSC 203 - Discrete Structures 50

The Traveling Salesman ProblemThe Traveling Salesman Problem

Unfortunately, no algorithm solving the travelingUnfortunately, no algorithm solving the travelingsalesman problem with polynomial worstsalesman problem with polynomial worst--case timecase timecomplexity has been devised yet.complexity has been devised yet.

This means that for large numbers of vertices,This means that for large numbers of vertices,

solving the traveling salesman problem issolving the traveling salesman problem isimpractical.impractical.

In these cases, we can use efficientIn these cases, we can use efficient approximationapproximationalgorithmsalgorithms that determine a path whose length maythat determine a path whose length maybe slightly larger than the traveling salesman·sbe slightly larger than the traveling salesman·spath, butpath, but

8/8/2019 18 Graphs 1

http://slidepdf.com/reader/full/18-graphs-1 51/51

CMSC 203 - Discrete Structures 51

TheTheEndEnd