1 Graphs Terminology By: Sandeep Tuli Astt. Prof. CSE.

16
1 Graphs Graphs Terminology Terminology By: By: Sandeep Tuli Sandeep Tuli Astt. Prof. Astt. Prof. CSE CSE

description

3 Introduction to Graphs Definition: A simple graph G = (V, E) consists of V, a nonempty set of vertices, and E, a set of unordered pairs of distinct elements of V called edges. For each e  E, e = {u, v} where u, v  V.

Transcript of 1 Graphs Terminology By: Sandeep Tuli Astt. Prof. CSE.

Page 1: 1 Graphs Terminology By: Sandeep Tuli Astt. Prof. CSE.

1

Graphs Graphs TerminologyTerminology

By:By:Sandeep TuliSandeep TuliAstt. Prof. CSEAstt. Prof. CSE

Page 2: 1 Graphs Terminology By: Sandeep Tuli Astt. Prof. CSE.

ApplicationsApplicationselectronic circuitselectronic circuits

networksnetworks (roads, (roads, flights, flights, communications)communications)

CS16CS16

LAXLAX

JFKJFK

LAXLAX

DFWDFW

STLSTLHNLHNL

FTLFTL

Page 3: 1 Graphs Terminology By: Sandeep Tuli Astt. Prof. CSE.

3

Introduction to GraphsIntroduction to GraphsDefinition: Definition: A A simple graphsimple graph G = (V, E) G = (V, E) consists of V, a nonempty set of vertices, and E, consists of V, a nonempty set of vertices, and E, a set of a set of unordered pairsunordered pairs of of distinctdistinct elements elements of V called edges.of V called edges.For each eFor each eE, e = {u, v} where u, v E, e = {u, v} where u, v V. V.

Page 4: 1 Graphs Terminology By: Sandeep Tuli Astt. Prof. CSE.

4

Introduction to GraphsIntroduction to GraphsDefinition: Definition: A A directed graph directed graph G = (V, E) G = (V, E) consists of a set V of vertices and a set E of consists of a set V of vertices and a set E of edges that are ordered pairs of elements in V.edges that are ordered pairs of elements in V.For each eFor each eE, e = (u, v) where u, v E, 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.

Page 5: 1 Graphs Terminology By: Sandeep Tuli Astt. Prof. CSE.

5

Graph ModelsGraph ModelsExample I: Example I: How can we represent a network of How can we represent a network of (bi-directional) railways connecting a set of cities?(bi-directional) railways connecting a set of cities?We should use a We should use a simple graphsimple graph with an edge {a, with an edge {a, b} indicating a direct train connection between b} indicating a direct train connection between cities a and b.cities a and b.

City DCity D

City BCity B

City CCity C

City ECity ECity ACity A

City FCity F

Page 6: 1 Graphs Terminology By: Sandeep Tuli Astt. Prof. CSE.

6

Graph ModelsGraph ModelsExample II: Example II: In a round-robin tournament, each In a round-robin 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 the How can we represent the results of the tournament (which team beats which other team)?tournament (which team beats which other team)?We should use a We should use a directed graphdirected graph with an edge (a, with an edge (a, b) indicating that team a beats team b.b) indicating that team a beats team b.

Team CTeam C

Team BTeam B

Team DTeam D

Team ATeam A

Page 7: 1 Graphs Terminology By: Sandeep Tuli Astt. Prof. CSE.

7

Graph TerminologyGraph TerminologyDefinitions: Definitions: An edge e is a An edge e is a looploop if e = {u, u} for some u if e = {u, u} for some uV. V. i.e. an edge having the same vertex as both of i.e. an edge having the same vertex as both of its end points.its end points.Graph is called Graph is called mixed graph mixed graph if it has some if it has some directed and some undirected edges. Otherwise directed and some undirected edges. Otherwise it is called it is called Simple graphSimple graph..A graph without any edge is called A graph without any edge is called null graphnull graph..A graph in which each vertex has same degree A graph in which each vertex has same degree is called is called regular graphregular graph..

Page 8: 1 Graphs Terminology By: Sandeep Tuli Astt. Prof. CSE.

8

Graph TerminologyGraph TerminologyDefinitions: Definitions: Two vertices u and v in an undirected graph G Two vertices u and v in an undirected graph G are called are called adjacentadjacent (or (or neighborsneighbors) in G if {u, ) in G if {u, v} is an edge in G.v} is an edge in G.If e = {u, v}, the edge e is called If e = {u, v}, the edge e is called incident withincident with the vertices u and v. The edge e is also said to the vertices u and v. The edge e is also said to connectconnect u and v. u and v.The vertices u and v are called The vertices u and v are called endpointsendpoints of the of the edge {u, v}.edge {u, v}.If more than one edges are associated with a If more than one edges are associated with a pair of vertices then such edges are k/a pair of vertices then such edges are k/a parallel parallel edges edges And the graph is And the graph is multi graphmulti graph..

Page 9: 1 Graphs Terminology By: Sandeep Tuli Astt. Prof. CSE.

9

Graph TerminologyGraph Terminology

Definition: Definition: The The degreedegree of a vertex in an of a vertex in an undirected graph is the number of edges undirected graph is the number of edges incident with it, except that a loop at a vertex incident with it, except that a loop at a vertex contributes twice to the degree of that vertex.contributes twice to the degree of that vertex.In other words, you can determine the degree In other words, you can determine the degree of a vertex in a displayed graph by of a vertex in a displayed graph by counting counting the linesthe lines that touch it. that touch it.The degree of the vertex v is denoted by The degree of the vertex v is denoted by deg(v).deg(v).

Page 10: 1 Graphs Terminology By: Sandeep Tuli Astt. Prof. CSE.

10

Graph TerminologyGraph Terminology

A vertex of degree 0 is called A vertex of degree 0 is called isolatedisolated, since it , since it is not adjacent to any vertex. is not adjacent to any vertex. Note:Note: A vertex with a A vertex with a looploop at it has at least at it has at least degree 2 and, by definition, is degree 2 and, by definition, is not isolatednot isolated, , even if it is not adjacent to any even if it is not adjacent to any otherother vertex. vertex.A vertex of degree 1 is called A vertex of degree 1 is called pendantpendant. It is . It is adjacent to exactly one other vertex.adjacent to exactly one other vertex.

Page 11: 1 Graphs Terminology By: Sandeep Tuli Astt. Prof. CSE.

11

Graph TerminologyGraph TerminologyExample: Example: Which vertices in the following graph Which vertices in the following graph are isolated, which are pendant, and what is are isolated, which are pendant, and what is the maximum degree? What type of graph is it?the maximum degree? What type of graph is it?

aa

bb cc

ddff hh

ggjjff

ee

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

Page 12: 1 Graphs Terminology By: Sandeep Tuli Astt. Prof. CSE.

12

Graph TerminologyGraph TerminologyLet us look at the same graph again and Let us look at the same graph again and determine the number of its edges and the sum determine the number of its edges and the sum of the degrees of all its vertices:of the degrees of all its vertices:

aa

bb cc

ddff hh

ggjjff

ee

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

Page 13: 1 Graphs Terminology By: Sandeep Tuli Astt. Prof. CSE.

13

Graph TerminologyGraph TerminologyDefinition:Definition: When (u, v) is an edge of the graph When (u, v) is an edge of the graph G with directed edges, u is said to be G with directed edges, u is said to be adjacent adjacent toto v, and v is said to be v, and v is said to be adjacent fromadjacent from u. u. The vertex u is called the The vertex u is called the initial vertexinitial vertex of (u, of (u, v), and v is called the v), and v is called the terminal vertexterminal vertex of (u, of (u, v).v).The initial vertex and terminal vertex of a loop The initial vertex and terminal vertex of a loop are the same.are the same.

Page 14: 1 Graphs Terminology By: Sandeep Tuli Astt. Prof. CSE.

14

Graph TerminologyGraph TerminologyDefinition:Definition: In a graph with directed edges, the In a graph with directed edges, the in-in-degreedegree of a vertex v, denoted by of a vertex v, denoted by degdeg--(v)(v), is the , is the number of edges with v as their number of edges with v as their terminal vertexterminal vertex..The The out-degreeout-degree of v, denoted by of 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 vertex How does adding a loop to a vertex change the in-degree and out-degree of that change the in-degree and out-degree of that vertex?vertex?Answer:Answer: It increases both the in-degree and the It increases both the in-degree and the out-degree by one.out-degree by one.

Page 15: 1 Graphs Terminology By: Sandeep Tuli Astt. Prof. CSE.

15

Graph TerminologyGraph TerminologyExample: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) = (a) = 11degdeg++(a) = (a) = 22

degdeg--(b) = (b) = 44degdeg++(b) = (b) = 22

degdeg--(d) = (d) = 22degdeg++(d) = (d) = 11

degdeg--(c) = (c) = 00degdeg++(c) = (c) = 22

Page 16: 1 Graphs Terminology By: Sandeep Tuli Astt. Prof. CSE.

16

TheTheEndEnd