Diese Präsentation wurde erfolgreich gemeldet.
Wir verwenden Ihre LinkedIn Profilangaben und Informationen zu Ihren Aktivitäten, um Anzeigen zu personalisieren und Ihnen relevantere Inhalte anzuzeigen. Sie können Ihre Anzeigeneinstellungen jederzeit ändern.
Nächste SlideShare
Wird geladen in …5
×

# Chapter 10 Graphs in Discrete Mathematics

7.786 Aufrufe

Veröffentlicht am

Introduction to Graphs
Simple Graph Example
Directed graph (digraph)
Degree Of Graph
Degree of Vertex
Regular Graph
Complete Bipartite graphs
Isomorphism of Graphs
Hamiltonian Graph

Veröffentlicht in: Bildung
• Full Name
Comment goes here.

Are you sure you want to Yes No
Your message goes here

Sind Sie sicher, dass Sie …  Ja  Nein
Ihre Nachricht erscheint hier

### Chapter 10 Graphs in Discrete Mathematics

1. 1. Discrete MathematicsDiscrete Mathematics and Itsand Its ApplicationsApplications Seventh EditionSeventh Edition Chapter 9Chapter 9 GraphGraph Lecture Slides By Adil AslamLecture Slides By Adil Aslam By Adil Aslam 1 Email Me : adilaslam5959@gmail.com
2. 2. Introduction to GraphsIntroduction to Graphs  AA graphgraph GG = (= (VV,, EE)) consists ofconsists of VV,, aa nonempty set ofnonempty set of verticesvertices (or(or nodesnodes)), and, and EE, a set of, a set of edgesedges..  Each edge has either one or two verticesEach edge has either one or two vertices associated with it, called itsassociated with it, called its endpointsendpoints. An. An edge is said toedge is said to connectconnect its endpoints.its endpoints. By Adil Aslam 2
3. 3. GraphGraph By Adil Aslam 3 v1 v2 v3 v4 v7 v6 G=(V, E), where V={v1,v2,…, v7} E={{v1,v2}, {v1,v3}, {v2,v3} {v3,v4}, {v4,v5}, {v4,v6} {v4,v7}, {v5,v6}, {v6,v7}} v5 Vertex Edge
4. 4. By Adil Aslam 4 Graph – mathematical object consisting of a set of:  V = nodes (vertices, points).  E = edges (links, arcs) between pairs of nodes.  Denoted by G = (V, E).  Captures pairwise relationship between objects.  Graph size parameters: n = |V|, m = |E|. V = { 1, 2, 3, 4, 5, 6, 7, 8 } E = { {1,2}, {1,3}, {2,3}, {2,4}, {2,5}, {3,5}, {3,7}, {3,8}, {4,5}, {5,6} } n = 8 m = 11
5. 5. Simple GraphsSimple Graphs A graph in which each edge connects twoA graph in which each edge connects two different vertices and where no two edgesdifferent vertices and where no two edges connect the same pair of vertices is called aconnect the same pair of vertices is called a simple graphsimple graph.. Multiple edgesMultiple edges between pairs of nodes andbetween pairs of nodes and self loopsself loops are not allowed in simple graphs.are not allowed in simple graphs. By Adil Aslam 5
6. 6. Simple Graph ExampleSimple Graph Example By Adil Aslam 6 Representation Example: G(V, E),Representation Example: G(V, E), V = {u, v, w},V = {u, v, w}, E = {{u, v}, {v, w}, {u, w}}E = {{u, v}, {v, w}, {u, w}} u v w
7. 7. Another ExampleAnother Example By Adil Aslam 7 0 1 3 4 2 5 Multiple Edges Self Loop
8. 8. MultigraphMultigraph Graphs that may haveGraphs that may have multiple edgesmultiple edges connecting the same vertices are calledconnecting the same vertices are called multigraphsmultigraphs.. simple graph + multiple edges (simple graph + multiple edges (multiedgesmultiedges)) By Adil Aslam 8 u v we1 e2 e3 Representation Example: V = {u, v, w}, E = {e1, e2, e3}
9. 9. Another ExampleAnother Example By Adil Aslam 9 V1 V2 V3 V4 V7 V5 V6
10. 10. PseudographsPseudographs  Graphs that may include loops, andGraphs that may include loops, and possibly multiple edges connecting thepossibly multiple edges connecting the same pair of vertices or a vertex to itself,same pair of vertices or a vertex to itself, are calledare called pseudographspseudographs..  simple graph +simple graph + multiedgemultiedge ++ looploop By Adil Aslam 10 A loop
11. 11. Another ExampleAnother Example By Adil Aslam 11 u v w e1 e2 e3 e4 Representation Example: V = {u, v, w}, E = {e1, e2, e3, e4}
12. 12. Directed graph (digraph)Directed graph (digraph) G(V, E), set of vertices V, and set of EdgesG(V, E), set of vertices V, and set of Edges E, that are ordered pair of elements of VE, that are ordered pair of elements of V (directed edges).(directed edges). Simple graph with each edge directed.Simple graph with each edge directed. By Adil Aslam 12 Note: Loop are allowed in a directed graph u w v
13. 13. Another ExampleAnother Example By Adil Aslam 13 0 1 3 4 2 5
14. 14. NoteNote By Adil Aslam 14 The two edges (u,v),(u,v) are multiedges The two edges (u,v),(v,u) are not multiedges.
15. 15. Directed MultigraphDirected Multigraph G(V,E), consists of set of vertices V, set ofG(V,E), consists of set of vertices V, set of Edges E and a function f from E to {{u, v}| u,Edges E and a function f from E to {{u, v}| u, v V}. The edges e1 and e2 are multiple edgeifv V}. The edges e1 and e2 are multiple edgeif f(e1) = f(e2).f(e1) = f(e2). Directed multigraph:Directed multigraph: digraph+multiedgesdigraph+multiedges By Adil Aslam 15 u u u e1 e2 e3 e4
16. 16. Graph TerminologyGraph Terminology By Adil Aslam 16 Type Edges Multiple Edges Allowed ? Loops Allowed ? Simple Graph undirected No No Multigraph undirected Yes No Pseudograph undirected Yes Yes Directed Graph directed No Yes Directed Multigraph directed Yes Yes
17. 17. Graph TerminologyGraph Terminology By Adil Aslam 17 Type Edges Multiple Edges Loops (simple) graph undirected edge: {u,v}   Multigraph   Pseudograph   Directed graph directed edge: (u,v)   Directed multigraph  
18. 18. Graph ModelsGraph Models Example 1.Example 1. (Niche Overlap graph)(Niche Overlap graph) We can use aWe can use a simple graphsimple graph to representto represent interaction of different species of animals.interaction of different species of animals. Each animal is represented by a vertex. AnEach animal is represented by a vertex. An undirected edge connectsundirected edge connects two vertices iftwo vertices if the two species represented by thesethe two species represented by these vertices competevertices compete.. By Adil Aslam 18
19. 19. Graph ModelGraph Model Example 2.Example 2. (Acquaintanceship graphs)(Acquaintanceship graphs) We can use aWe can use a simple graphsimple graph to representto represent whether two people know each other. Eachwhether two people know each other. Each person is represented by a vertex. Anperson is represented by a vertex. An undirected edge is used to connect twoundirected edge is used to connect two people when these people know each other.people when these people know each other. By Adil Aslam 19 JanJan PaulaPaula ToddTodd LilaLila LizdLizd SteveSteve KamleshKamlesh AmyAmy
20. 20. Graph ModelGraph Model Example 3.Example 3. (Influence graphs)(Influence graphs) In studies of group behavior it is observed thatIn studies of group behavior it is observed that certain people can influence the thinking ofcertain people can influence the thinking of others.others. Simple digraphSimple digraph ⇒⇒ Each person of the group isEach person of the group is represented by a vertex. There is a directed edgerepresented by a vertex. There is a directed edge from vertexfrom vertex aa to vertexto vertex bb when the personwhen the person aa influences the personinfluences the person bb.. By Adil Aslam 20 LindaLinda BrianBrian DeborahDeborah FredFred YvonneYvonne
21. 21. TerminologyTerminology – Undirected graphs– Undirected graphs u and v areu and v are adjacentadjacent if {u, v} is an edge, e isif {u, v} is an edge, e is calledcalled incidentincident with u and v. u and v arewith u and v. u and v are calledcalled endpointsendpoints of {u, v}.of {u, v}. Note :Note : adjacentadjacent: a vertex connected to a vertex: a vertex connected to a vertex incidentincident: a vertex connected to an edge: a vertex connected to an edge By Adil Aslam 21
22. 22. Degree Of GraphDegree Of Graph A vertex of degreeA vertex of degree 00 is calledis called isolatedisolated.. A vertex isA vertex is pendantpendant if and onlyif and only if it hasif it has degree one.degree one. By Adil Aslam 22
23. 23. By Adil Aslam 23 Graph TerminologyGraph Terminology A vertex of degree 0 is calledA vertex of degree 0 is called isolatedisolated, since it is, since it is not 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 if it 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 is adjacent to exactly one other vertex.adjacent to exactly one other vertex.
24. 24. By Adil Aslam 24 Graph TerminologyGraph Terminology Example:Example: Which vertices in the following graph areWhich vertices in the following graph are isolated, which are pendant, and what is theisolated, which are pendant, and what is the maximum degree? What type of graph is it?maximum degree? What type of graph is it? aa bb cc dd ff hh gg jjff 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).
25. 25. Degree of VertexDegree of Vertex TheThe degreedegree of a vertexof a vertex vv, denoted by, denoted by deg(deg(vv)),, in an undirected graph is the number ofin an undirected graph is the number of edges incident with it.edges incident with it. TheThe degreedegree of a node in an undirected graphof a node in an undirected graph is the number of edges incident to that node.is the number of edges incident to that node. Note:Note: A loop adds 2 to the degree.A loop adds 2 to the degree. Pendant Vertex:Pendant Vertex: deg (v) =1deg (v) =1 Isolated Vertex:Isolated Vertex: deg (v) = 0deg (v) = 0 By Adil Aslam 25
26. 26. ExampleExample By Adil Aslam 26 u k w v Representation Example: For V = {u, v, w} , E = { {u, w}, {u, w}, (u, v) }, deg (u) = 2, deg (v) = 1, deg (w) = 1, deg (k) = 0, w and v are pendant , k is isolated
27. 27. Another ExampleAnother Example What are the degrees of the verticesWhat are the degrees of the vertices in the graph H.in the graph H. By Adil Aslam 27 HH aa bb cc ee dd ff deg(a)=4 deg(b)=6 deg(c)=1 deg(d)=5 deg(e)=6 deg(f)=0
28. 28. Your TaskYour Task By Adil Aslam 28 0 1 3 4 2 5 What is the degree of node4? Of node 0? Of node 2?
29. 29. By Adil Aslam 29 Your Homework! Submitted this Work in the form of Assignment
30. 30. TerminologyTerminology –– Directed graphsDirected graphs For the edge (u, v),For the edge (u, v), u isu is adjacentadjacent toto v OR v isv OR v is adjacent fromadjacent from u, u –u, u – Initial vertexInitial vertex, v –, v – TerminalTerminal vertexvertex In-degree (degIn-degree (deg-- (u)):(u)): number of edges for which unumber of edges for which u is terminal vertexis terminal vertex Out-degree (degOut-degree (deg++ (u)):(u)): number of edges for which unumber of edges for which u is initial vertexis initial vertex Note: A loop contributes 1 to both in-degree andNote: A loop contributes 1 to both in-degree and out-degree (why?)out-degree (why?) By Adil Aslam 30
31. 31. ExampleExample Representation Example:Representation Example: For V = {u, v, w} ,For V = {u, v, w} , E= { (u, w), ( v, w), (u, v) }.E= { (u, w), ( v, w), (u, v) }. (u) = 0, deg(u) = 0, deg++ (u) = 2, deg(u) = 2, deg-- (v) = 1,(v) = 1, degdeg++ (v) = 1, and deg(v) = 1, and deg-- (w) = 2, deg(w) = 2, deg++ (u) = 0(u) = 0 By Adil Aslam 31 u w v
32. 32. By Adil Aslam 32 Graph TerminologyGraph Terminology Example:Example: What are the in-degrees and out-What are the in-degrees 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) = 2 degdeg++ (d) = 1(d) = 1 degdeg-- (c) = 0(c) = 0 degdeg++ (c) = 2(c) = 2
33. 33. By Adil Aslam 33 Your Homework!
34. 34. SolutionSolution By Adil Aslam 34 aa bb cc ee dd ff deg− (a)=2, deg+ (a)=4 deg− (b)=2, deg+ (b)=1 deg− (c)=3, deg+ (c)=2 deg− (d)=2, deg+ (d)=2 deg− (e)=3, deg+ (e)=3 deg− (f )=0, deg+ (f )=0
35. 35. By Adil Aslam 35 Graph TerminologyGraph Terminology The Handshaking Theorem:The Handshaking Theorem: Let G = (V, E) be anLet G = (V, E) be an undirected graph with e edges. Thenundirected graph with e edges. Then 2e =2e = ∑∑vv∈∈VV deg(v)deg(v) Example:Example: How many edges are there in a graphHow many edges are there in a graph with 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 66⋅⋅10 = 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.
36. 36. ExampleExample By Adil Aslam 36 HH aa bb cc ee dd ff The graph H has 11 edges, and ∑v∈V deg(v)=22
37. 37. Your TaskYour Task How many edges are there in a graphHow many edges are there in a graph with 10 vertices each of degree six?with 10 vertices each of degree six? Solution:Solution: By Adil Aslam 37 10 ⋅ 6 = 2e ⇒ e=30
38. 38. By Adil Aslam 38 Graph TerminologyGraph Terminology Theorem:Theorem: 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 of evenbe the set of vertices of even and odd degrees, respectively (Thus V1and odd degrees, respectively (Thus V1 ∩∩ V2 =V2 = ∅∅,, and V1and V1 ∪∪V2 = V).V2 = V). Then by Handshaking theoremThen by Handshaking theorem 2|E| =2|E| = ∑∑vv∈∈VV deg(v) =deg(v) = ∑∑vv∈∈V1V1 deg(v) +deg(v) + ∑∑vv∈∈V2V2 deg(v)deg(v) Since both 2|E| andSince both 2|E| and ∑∑vv∈∈V1V1 deg(v) are even,deg(v) are even, ∑∑vv∈∈V2V2 deg(v) must be even.deg(v) must be even. Since deg(v) if odd for all vSince deg(v) if odd for all v∈∈V2, |V2| must be even.V2, |V2| must be even.
39. 39. By Adil Aslam 39 Graph TerminologyGraph Terminology Theorem:Theorem: Let G = (V, E) be a graph with directedLet G = (V, E) be a graph with directed edges. Then:edges. Then: ∑∑vv∈∈VV degdeg-- (v) =(v) = ∑∑vv∈∈VV degdeg++ (v) = |E|(v) = |E| This is easy to see, because every new edgeThis is easy to see, because every new edge increases both the sum of in-degrees and the sumincreases both the sum of in-degrees and the sum of out-degrees by one.of out-degrees by one.
40. 40. Regular GraphRegular Graph A simple graphA simple graph GG=(=(VV,, EE)) is calledis called regularregular if every vertex of this graph has theif every vertex of this graph has the same degree. A regular graph is calledsame degree. A regular graph is called nn-regular-regular if deg(if deg(vv)=)=nn ,, ∀∀vv∈∈VV.. By Adil Aslam 40 is 3-regular
41. 41. Some Special Simple GraphsSome Special Simple Graphs Complete Graph:Complete Graph: TheThe complete graph oncomplete graph on nn verticesvertices, denoted by, denoted by KKnn, is the simple graph that contains exactly, is the simple graph that contains exactly one edge between each pair of distinctone edge between each pair of distinct Vertices.Vertices. By Adil Aslam 41 K1 K2 K3 K4
42. 42. CycleCycle TheThe cyclecycle CCnn,, nn≥≥3, consists of3, consists of nn verticesvertices vv11,, vv22, …,, …, vvnn and edgesand edges{{vv11,,vv22}, {}, {vv22,,vv33}, …,}, …, {v{vnn−−11,v,vnn}, {v}, {vnn,v,v11}}.. NoteNote CCnn isis 22-regular,-regular, ||VV((CCnn)| =)| = n,n, ||EE((CCnn)| =)| = nn By Adil Aslam 42 C5C3 C4
43. 43. WheelWheel We obtainedWe obtained the wheelthe wheel WWnn when we add anwhen we add an additional vertex to the cycleadditional vertex to the cycle CCnn,,forfor nn≥≥3,3, andand connect this new vertex to each of theconnect this new vertex to each of the nn vertices invertices in CCnn, by new edges., by new edges. By Adil Aslam 43 w3 w4
44. 44. Note thatNote that Note.Note. ||VV((WWnn)| =)| = nn + 1, |+ 1, |EE((WWnn)| = 2)| = 2n,n, WWnn is not a regular graph ifis not a regular graph if nn ≠≠ 3.3. By Adil Aslam 44
45. 45. N-cubesN-cubes TheThe nn-dimensional hypercube, or-dimensional hypercube, or nn-cube,-cube, denoted bydenoted by QQnn, is the graph that has vertices, is the graph that has vertices representing therepresenting the 22nn bit strings of lengthbit strings of length nn.. Two vertices are adjacent if and only if theTwo vertices are adjacent if and only if the bit strings that they represent differ inbit strings that they represent differ in exactly one bit position.exactly one bit position. 45 Q2 Q1 0 1 10 11 00 01 Q3 100 110 111 011 010 000 001 101 Note. Qn is n-regular, |V(Qn)| = 2n , |E(Qn)| = (2n n)/2 =2n−1 n
46. 46. Bipartite graphsBipartite graphs A simple graphA simple graph GG=(=(VV,,EE)) is calledis called bipartitebipartite ifif VV can be partitioned intocan be partitioned into VV11 andand VV22,, VV11∩∩VV22==∅∅,, such that every edge in the graph connect asuch that every edge in the graph connect a vertex invertex in VV11 and a vertex inand a vertex in VV22.. By Adil Aslam 46 v1 v3 v5 v 2 v4 v6 ∴ C6 is bipartite. V1 V2
47. 47. By Adil Aslam 47 Special GraphsSpecial Graphs Example I:Example I: Is CIs C33 bipartite?bipartite? vv11 vv22 vv33 No,No, because there is no way to partition thebecause there is no way to partition the vertices into two sets so that there are no edgesvertices into two sets so that there are no edges with both endpoints in the same set.with both endpoints in the same set. Example II:Example II: Is CIs C66 bipartite?bipartite? vv55 vv11 vv22 vv33 vv44 vv66 vv11 vv66 vv22vv55 vv33 vv44 Yes,Yes, becausebecause we can displaywe can display CC66 like this:like this:
48. 48. Your TaskYour Task Is it bipartite graph?Is it bipartite graph? By Adil Aslam 48 v1 v2 v3 v4 v5 v6 V1 V 2 Sol : Yes
49. 49. TheoremTheorem A simple graph is bipartite if and only if it isA simple graph is bipartite if and only if it is possible to assign one of two different colorspossible to assign one of two different colors to each vertex of the graph so that no twoto each vertex of the graph so that no two adjacent vertices are assigned the sameadjacent vertices are assigned the same color.color. By Adil Aslam 49 2 2 2 2 1 Theorem to show that G is bipartite.
50. 50. Complete Bipartite graphsComplete Bipartite graphs KKm,nm,n is the graph that has its vertex setis the graph that has its vertex set portioned into two subsets of m and n vertices,portioned into two subsets of m and n vertices, respectively There is an edge between tworespectively There is an edge between two vertices if and only if one vertex is in the firstvertices if and only if one vertex is in the first subset and the other vertex is in the secondsubset and the other vertex is in the second subset.subset. By Adil Aslam 50 K2,3 K3,3
51. 51. Note thatNote that Note.Note. ||VV((KKm,nm,n)| =)| = m+n,m+n, ||EE((KKm,nm,n)| =)| = mn,mn, KKm,nm,n is regular if and only ifis regular if and only if m=n.m=n. By Adil Aslam 51
52. 52. SubgraphsSubgraphs A subgraph of a graph G = (V, E) is aA subgraph of a graph G = (V, E) is a graph H =(V’, E’) where V’ is a subset ofgraph H =(V’, E’) where V’ is a subset of V and E’ is a subset of E.V and E’ is a subset of E. Representation example: V = {u, v, w},Representation example: V = {u, v, w}, E = ({u, v}, {v, w}, {w, u}}, HE = ({u, v}, {v, w}, {w, u}}, H11 , H, H22 52 u v w uu wv v G H1 H2
53. 53. Another ExampleAnother Example By Adil Aslam 53 subgraph of K5 a b c e
54. 54. Union of Two graphUnion of Two graph TheThe unionunion of two simple graphsof two simple graphs GG11=(=(VV11,, EE11)) andand GG22=(=(VV22,, EE22)) is the simple graphis the simple graph GG11∪∪GG22=(=(VV11∪∪VV22,, EE11∪∪EE22)) 54 a b c d e f G1∪G2 a b c d f a b c d e G1 G2
55. 55. By Adil Aslam 55 Your TaskYour Task Find the union of G1 and G2.Find the union of G1 and G2. The union of GThe union of G11 and Gand G22 is denoted byis denoted by GG11 ∪∪ GG22.. GG11 GG22 GG11  GG22 = K= K55
57. 57. By Adil Aslam 57 Representing GraphsRepresenting Graphs Definition:Definition: Let G = (V, E) be an undirected graphLet G = (V, E) be an undirected graph with |V| = n. Suppose that the vertices and edgeswith |V| = n. Suppose that the vertices and edges of G are listed in arbitrary order as vof G are listed in arbitrary order as v11, v, v22, …, v, …, vnn andand ee11, e, e22, …, e, …, emm, respectively., respectively. TheThe incidence matrixincidence matrix of G with respect to thisof G with respect to this listing of the vertices and edges is the nlisting of the vertices and edges is the n××m zero-m 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 ejj is 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 ejj is incident with vis incident with vii mmijij = 0 otherwise.= 0 otherwise.
58. 58. Representation- Incidence MatrixRepresentation- Incidence Matrix By Adil Aslam 58 Representation Example: G = (V, E)Representation Example: G = (V, E) v w u e1 e2 e3 v 1 0 1 u 1 1 0 w 0 1 1 e1 e2 e3
59. 59. By Adil Aslam 59 Representing GraphsRepresenting Graphs Example:Example: What is the incidenceWhat is the incidence matrix M for the followingmatrix M for the following graph G based on the order ofgraph G based on the order of vertices 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 000101 010011 M Note:Note: Incidence matrices of directed graphs contain two 1s perIncidence matrices of directed graphs contain two 1s per column for edges connecting two vertices and one 1 per column forcolumn for edges connecting two vertices and one 1 per column for loops.loops. aa bb cc dd 11 22 44 5533 66
60. 60. By Adil Aslam 60 Representing GraphsRepresenting Graphs Definition:Definition: Let G = (V, E) be a simple graph with |V|Let G = (V, E) be a simple graph with |V| = n. Suppose that the vertices of G are listed in= n. Suppose that the vertices of G are listed in arbitrary 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 respect to this listing of the vertices, is the nto this listing of the vertices, is the n××n zero-onen zero-one matrix with 1 as its (i, j)th entry when vmatrix with 1 as its (i, j)th entry when vii and vand vjj areare adjacent, 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, vjj} is an edge of G} is an edge of G aaijij = 0= 0 otherwiseotherwise
61. 61. Representation- Adjacency MatrixRepresentation- Adjacency Matrix By Adil Aslam 61 Example: Undirected Graph G (V, E)Example: Undirected Graph G (V, E) v u w v 0 1 1 u 1 0 1 w 1 1 0 u v w
62. 62. By Adil Aslam 62 Representing GraphsRepresenting Graphs aa bb cc dd Example:Example: What is the adjacencyWhat is the adjacency matrix Amatrix AGG for the followingfor the following graph G based on the order ofgraph G based on the order of vertices a, b, c, d ?vertices a, b, c, d ? Solution:Solution:             = 0111 1001 1001 1110 GA Note:Note: Adjacency matrices of undirected graphsAdjacency matrices of undirected graphs are always symmetric.are always symmetric.
63. 63. Representation- Adjacency MatrixRepresentation- Adjacency Matrix By Adil Aslam 63 Example: directed Graph G (V, E)Example: directed Graph G (V, E) v u w v 0 1 0 u 0 0 1 w 1 0 0 u v w
64. 64. Representing Graphs andRepresenting Graphs and Graph IsomorphismGraph Isomorphism Adjacency listAdjacency list By Adil Aslam 64 Example 1Example 1.. Use adjacency lists to describe the simpleUse adjacency lists to describe the simple graph given below.graph given below. b a e d c Verte x Adjacent Vertices a b,c,e b a c a,d,e d c,e e a,c,d Sol : Each node (vertex) has a list of which nodes (vertex) it is adjacent
65. 65. Example 2Example 2 By Adil Aslam 65 (digraph)(digraph) a b e d c Initial vertex Terminal vertices a b,c,d,e b b,d c a,c,e d e b,c,d
66. 66. Representation- Adjacency ListRepresentation- Adjacency List Your Task!Your Task! By Adil Aslam 66 Each node (vertex) has a list of which nodes (vertex) it is adjacentEach node (vertex) has a list of which nodes (vertex) it is adjacent Example: undirectd graph G (V, E)Example: undirectd graph G (V, E) u v w node Adjacency List u v , w v w, u w u , v
67. 67. By Adil Aslam 67 Representing GraphsRepresenting Graphs aa bb cc dd aa bb cc dd a, da, dbb a, da, dcc a, b, ca, b, cdd b, c, db, c, daa AdjacentAdjacent VerticesVertices VertexVertex aabb cc a, b, ca, b, cdd ccaa TerminalTerminal VerticesVertices InitialInitial VertexVertex
68. 68. By Adil Aslam 68 Example 5Example 5 (Pseudograph)(Pseudograph) ((Matrix may not be 0,1 matrix.Matrix may not be 0,1 matrix.)) If A=[aij] is the adjacency matrix for the directed graph, then             = 0212 2110 1103 2030 A a b c d a b c d aij= 1 , if 0 , otherwise (So the matrix is not necessarily symmetrical) a b cd vi vj
69. 69. By Adil Aslam 69 Your Homework! Submitted this work
70. 70. Isomorphism of GraphsIsomorphism of Graphs G1 = (V1, E2) and G2 = (V2, E2) areG1 = (V1, E2) and G2 = (V2, E2) are isomorphic if:isomorphic if: There is a one-to-one and onto function fThere is a one-to-one and onto function f from V1 to V2 with the property thatfrom V1 to V2 with the property that – a and b are adjacent in G1 if and only if f (a)a and b are adjacent in G1 if and only if f (a) and f (b) are adjacent in G2, for all a and b inand f (b) are adjacent in G2, for all a and b in V1.V1. Function f is called isomorphismFunction f is called isomorphism By Adil Aslam 70
71. 71. ExampleExample By Adil Aslam 71 Representation example: G1 = (V1, E1) ,Representation example: G1 = (V1, E1) , G2 = (V2, E2)G2 = (V2, E2) f(uf(u11) = v) = v11, f(u, f(u22) = v) = v44, f(u, f(u33) = v) = v33, f(u, f(u44) = v) = v22,, u1 u3 u4 u2 v3 v4 v1 v2
72. 72. Another ExampleAnother Example By Adil Aslam 72 u1 G H u3 u2 u4 v2 v4 v1 v3 G is isomorphic to H
73. 73. By Adil Aslam 73 Isomorphism of GraphsIsomorphism of Graphs Example 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 can be arranged to look, they are isomorphic, because they can be arranged to look identical. You can see this if in the right graph you move vertex b to the leftidentical. You can see this if in the right graph you move vertex b to the left of the edge {a, c}. Then the isomorphism f from the left to the right graphof the edge {a, c}. Then the isomorphism f from the left to the right graph is: f(a) = e, f(b) = a,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.
74. 74. By Adil Aslam 74 Isomorphism of GraphsIsomorphism of Graphs Example II:Example II: How about these two graphs?How about these two graphs? dd aa bb cc ee dd aa bb cc ee Solution:Solution: NoNo, they are not isomorphic, because they, they are not isomorphic, because they differ in the degrees of their vertices.differ in the degrees of their vertices. Vertex d in right graph is of degree one, but there isVertex d in right graph is of degree one, but there is no such vertex in the left graph.no such vertex in the left graph.
75. 75. Your Task!Your Task! By Adil Aslam 75 Show thatShow that GG andand HH are isomorphic.are isomorphic. The function f with f(u1) = v1,f(u2) = v4, f(u3) = v3, and f(u4) = v2 is a one-to-one correspondence between V(G) and V(H). Isomorphism graphs there will be: (1) The same number of points (2) The same number of edges (3) The same number of degree u1 G H u3 u2 u4 v2 v4 v1 v3 Sol.
76. 76. By Adil Aslam 76 ExampleExample Determine whetherDetermine whether GG andand HH are isomorphic.are isomorphic. HG a b d c e h f g s v t u w x z y Sol : In∵ G, deg(a)=2, which must correspond to either t, u, x, or y in H degree Each of these four vertices in H is adjacent to another vertex of degree two in H, which is not true for a in G ∴ G and H are not isomorphic.
77. 77. By Adil Aslam 77 ExampleExample Determine whether the graphsDetermine whether the graphs GG andand HH are isomorphic.are isomorphic. G Hu1 u2 u4 u3 u5 u6 v1 v2 v3 v4 v5 v6 Sol: f(u1)=v6, f(u2)=v3, f(u3)=v4, f(u4)=v5, f(u5)=v1, f(u6)=v2 ⇒Yes
78. 78. ConnectivityConnectivity Basic Idea: In a Graph Reachability amongBasic Idea: In a Graph Reachability among vertices by traversing the edgesvertices by traversing the edges Application Example:Application Example: - In a city to city road-network, if one city- In a city to city road-network, if one city can be reached from another city.can be reached from another city. - Problems if determining whether a- Problems if determining whether a message can be sent between twomessage can be sent between two computer using intermediate linkscomputer using intermediate links - Efficiently planning routes for data- Efficiently planning routes for data delivery in the Internetdelivery in the Internet By Adil Aslam 78
79. 79. Connectivity – PathConnectivity – Path AA PathPath is a sequence of edges thatis a sequence of edges that begins at a vertex of a graph andbegins at a vertex of a graph and travels along edges of the graph, alwaystravels along edges of the graph, always connecting pairs of adjacent vertices.connecting pairs of adjacent vertices. Representation example: G = (V, E), Path PRepresentation example: G = (V, E), Path P represented, from u to v isrepresented, from u to v is {{u, 1}, {1, 4}, {4, 5}, {5, v}}{{u, 1}, {1, 4}, {4, 5}, {5, v}} By Adil Aslam 79 1 u 3 4 5 2 v
80. 80. Connectivity – PathConnectivity – Path In an undirected graph, aIn an undirected graph, a path of lengthpath of length nn fromfrom uu toto vv is a sequence ofis a sequence of nn+1+1 adjacent vertices going fromadjacent vertices going from vertexvertex uu to vertexto vertex vv. (e.g.,. (e.g., PP:: u=xu=x00, x, x11, x, x22, …,, …, xxnn=v.=v.)) (( PP hashas nn edges.)edges.) path:path: Points and edges in unrepeatablePoints and edges in unrepeatable trailtrail:: Allows duplicate path (not repeatable)Allows duplicate path (not repeatable) walkwalk:: Allows point and duplicate pathAllows point and duplicate path By Adil Aslam 80 u v w x y path: u, v, y trail: u, v, w, y, v, x, y walk: u, v, w, v, x, v, y
81. 81. Connectivity – PathConnectivity – Path cyclecycle: path with: path with u=vu=v circuitcircuit: trail with: trail with u=vu=v closed walkclosed walk: walk with: walk with u=vu=v By Adil Aslam 81 G u v w x y cycle: u, v, y, x, u trail: u, v, w, y, v, x, u walk: u, v, w, v, x, v, y, x, u Example
82. 82. Connectivity – ConnectednessConnectivity – Connectedness Undirected GraphUndirected Graph An undirected graph is connected if thereAn undirected graph is connected if there exists is a simple path between every pair ofexists is a simple path between every pair of verticesvertices Connected componentConnected component Maximal connected subgraph. (Maximal connected subgraph. (An unconnectedAn unconnected graph will have severalgraph will have several component)component) By Adil Aslam 82
83. 83. Connectivity – ConnectednessConnectivity – Connectedness By Adil Aslam 83 Example What are the connected components of the graph H? a b c d e h g f H
84. 84. By Adil Aslam 84 Your TaskYour Task Example:Example: What are the connected components inWhat are the connected components in the following graph?the following graph? aa bb cc dd ff hh gg jjff ee Solution:Solution: The connected components are theThe connected components are the graphs 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}.
85. 85. By Adil Aslam 85 ConnectivityConnectivity Example:Example: Are the following graphs connected?Are the following graphs connected? dd aa bb cc ee Yes.Yes. dd aabb cc ee No.No. dd aa bb cc ee Yes.Yes. dd aabb cc ee ff No.No.
86. 86. Connectivity – ConnectednessConnectivity – Connectedness Undirected GraphUndirected Graph AA cut vertexcut vertex separates one connectedseparates one connected component into several components if it iscomponent into several components if it is removed.removed. AA cut edgecut edge separates one connectedseparates one connected component into two components if it iscomponent into two components if it is removed.removed. By Adil Aslam 86
87. 87. Connectivity – ConnectednessConnectivity – Connectedness ExampleExample Find the cut vertices and cutFind the cut vertices and cut edges in the graphedges in the graph GG.. By Adil Aslam 87 b a c d e h gf G cut vertices: b, c, e cut edges: {a, b}, {c, e} Sol:
88. 88. Connectivity – ConnectednessConnectivity – Connectedness A directed graph isA directed graph is strongly connectedstrongly connected ifif there is a path fromthere is a path from aa toto bb for any twofor any two verticesvertices a,a, bb.. A directed graph isA directed graph is weakly connectedweakly connected ifif there is a path between every two vertices inthere is a path between every two vertices in the underlying undirected graphs.the underlying undirected graphs. By Adil Aslam 88
89. 89. Connectivity – ConnectednessConnectivity – Connectedness By Adil Aslam 89 Example Are the directed graphs G and H strongly connected or weakly connected? e a d b G c H e a d b c strongly connected weakly connected
90. 90. Another ExampleAnother Example By Adil Aslam 90 Directed GraphDirected Graph Representation example: G1 (Strong component), G2 (Weak Component),Representation example: G1 (Strong component), G2 (Weak Component), G3 is undirected graph representation of G2 or G1G3 is undirected graph representation of G2 or G1 G1 G2 G3
91. 91. By Adil Aslam 91 Your TaskYour Task Example:Example: Are the following directed graphsAre the following directed graphs strongly 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 path from b to d.from b to d. aa bb cc dd Strongly connectedStrongly connected, because, because there are paths between allthere are paths between all possible pairs of vertices.possible pairs of vertices.
92. 92. Connectivity – ConnectednessConnectivity – Connectedness Directed GraphDirected Graph Strongly connected Components:Strongly connected Components: subgraphs of a Graph G that are stronglysubgraphs of a Graph G that are strongly connectedconnected Representation example: G2 is the stronglyRepresentation example: G2 is the strongly connected component in G1connected component in G1 By Adil Aslam 92 G1 G2
93. 93. Paths and IsomorphismPaths and Isomorphism A isomorphic invariant for simpleA isomorphic invariant for simple graphs is the existence of a simplegraphs is the existence of a simple circuit of length k , k is an integer > 2circuit of length k , k is an integer > 2 Representation example: G1 and G2 areRepresentation example: G1 and G2 are isomorphic since we have the invariants,isomorphic since we have the invariants, similarity in degree of nodes, number ofsimilarity in degree of nodes, number of edges, length of circuitsedges, length of circuits By Adil Aslam 93 G1 G2
94. 94. Your TaskYour Task By Adil Aslam 94 Example Determine whether the graphs G and H are isomorphic. G u1 u2 u3 u4 u5 u6 H v1 v2 v3 v4 v5 v6 Sol: No, Because G has no simple circuit of length three, but H does
95. 95. Euler - definitionsEuler - definitions AnAn Eulerian pathEulerian path ((Eulerian trailEulerian trail,, Euler walkEuler walk)) in a graph is a path that uses each edgein a graph is a path that uses each edge precisely once. If such a path exists, theprecisely once. If such a path exists, the graph is calledgraph is called traversabletraversable.. AnAn Eulerian cycleEulerian cycle ((Eulerian circuitEulerian circuit,, EulerEuler tourtour)) in a graph is a cycle that uses eachin a graph is a cycle that uses each edge precisely once. If such a cycle exists,edge precisely once. If such a cycle exists, the graph is calledthe graph is called EulerianEulerian (also(also unicursalunicursal).). By Adil Aslam 95
96. 96. ExampleExample Representation example: G1 has EulerRepresentation example: G1 has Euler path a, c, d, e, b, d, a, bpath a, c, d, e, b, d, a, b By Adil Aslam 96 a b c d e
97. 97. Euler-ExampleEuler-Example By Adil Aslam 97 Example Which of the following graphs have an Euler circuit or an Euler path? a b G1 c e d a b G2 c e d a b G3 c ed Euler circuit Euler pathnone
98. 98. Euler - theoremsEuler - theorems A connected graph G is Eulerian if and only ifA connected graph G is Eulerian if and only if G is connected and has no vertices of oddG is connected and has no vertices of odd degreedegree 2.2. A connected graph G is has an Euler trailA connected graph G is has an Euler trail from nodefrom node aa to some other node bto some other node b if andif and only ifonly if G is connected and aG is connected and a ≠≠ b are theb are the only two nodes of odd degreeonly two nodes of odd degree By Adil Aslam 98
99. 99. Hamiltonian GraphHamiltonian Graph AA Hamilton pathHamilton path is a path thatis a path that traverses eachtraverses each vertexvertex in a graphin a graph GG exactly once.exactly once. AA Hamilton circuitHamilton circuit is a circuit thatis a circuit that traverses each vertex intraverses each vertex in GG exactlyexactly once.once. By Adil Aslam 99
100. 100. Hamiltonian GraphHamiltonian Graph By Adil Aslam 100 Example Which of the following graphs have a Hamilton circuit or a Hamilton path? a b G2 cd Hamilton circuit: G1 a b G1 c d e a b G3 d ec g f Hamilton path: G1,G2
101. 101. Any QuestionAny Question ?? By Adil Aslam 101
102. 102. Thank YouThank You  By Adil Aslam 102