42
Discrete Structures Graphs 1 (Ch. 10) Dr. Muhammad Humayoun Assistant Professor COMSATS Institute of Computer Science, Lahore. [email protected] https://sites.google.com/a/ciitlahore.edu.pk/dstruct / Modified slides of Dr. M. Atif 1

Discrete Structures Graphs 1 (Ch. 10) Dr. Muhammad Humayoun Assistant Professor COMSATS Institute of Computer Science, Lahore. [email protected]

Embed Size (px)

Citation preview

Page 1: Discrete Structures Graphs 1 (Ch. 10) Dr. Muhammad Humayoun Assistant Professor COMSATS Institute of Computer Science, Lahore. mhumayoun@ciitlahore.edu.pk

1

Discrete StructuresGraphs 1 (Ch. 10)

Dr. Muhammad HumayounAssistant Professor

COMSATS Institute of Computer Science, [email protected]

https://sites.google.com/a/ciitlahore.edu.pk/dstruct/Modified slides of Dr. M. Atif

Page 2: Discrete Structures Graphs 1 (Ch. 10) Dr. Muhammad Humayoun Assistant Professor COMSATS Institute of Computer Science, Lahore. mhumayoun@ciitlahore.edu.pk

2

Graphs

• What are Graphs?– A class of discrete structures useful for representing

relations among objects.– Vertices (nodes) connected by edges.– Theory about graphs can be used to solve a lot of

important problems

Page 3: Discrete Structures Graphs 1 (Ch. 10) Dr. Muhammad Humayoun Assistant Professor COMSATS Institute of Computer Science, Lahore. mhumayoun@ciitlahore.edu.pk

3

Perhaps the first graph you saw

Can we sent all the utilities to the three houses without crossing wires?

Not possible!

Page 4: Discrete Structures Graphs 1 (Ch. 10) Dr. Muhammad Humayoun Assistant Professor COMSATS Institute of Computer Science, Lahore. mhumayoun@ciitlahore.edu.pk

4

The first graph theory

The first graph theory paper by Leonhard EulerIn 1736: Seven bridges of KönigsbergA town with 7 bridges and 4 pieces of land…

Page 5: Discrete Structures Graphs 1 (Ch. 10) Dr. Muhammad Humayoun Assistant Professor COMSATS Institute of Computer Science, Lahore. mhumayoun@ciitlahore.edu.pk

5

The Origin of Graph Theory

Can we travel each bridge exactly once and return to the starting point?

Not possible!

Page 6: Discrete Structures Graphs 1 (Ch. 10) Dr. Muhammad Humayoun Assistant Professor COMSATS Institute of Computer Science, Lahore. mhumayoun@ciitlahore.edu.pk

6

Definition - Graphs

A graph G = (V, E) is defined by a set of vertices V, and a set of edges E consisting of ordered or unordered pairs of vertices from V.

Thus a graph G = (V, E)– V = set of vertices– E = set of edges = subset of V V– Thus |E| = O(|V|2)

Page 7: Discrete Structures Graphs 1 (Ch. 10) Dr. Muhammad Humayoun Assistant Professor COMSATS Institute of Computer Science, Lahore. mhumayoun@ciitlahore.edu.pk

7

Simple GraphsA graph in which each edge connects two

different vertices and where no two edges connect the same pair of vertices.

Page 8: Discrete Structures Graphs 1 (Ch. 10) Dr. Muhammad Humayoun Assistant Professor COMSATS Institute of Computer Science, Lahore. mhumayoun@ciitlahore.edu.pk

8

Example of a Simple Graph

Let V be the set of states in the far southeastern U.S.:– i.e., V={FL, GA, AL, MS, LA, SC, TN, NC}

Let E={{u,v}| u,v V and u adjoins v}∈

= {{FL,GA},{FL,AL},{FL,MS}, {FL,LA}, {GA,AL}, {AL,MS}, {MS,LA}, {GA,SC}, {GA,TN},

{SC,NC}, {NC,TN}, {MS,TN}, {MS,AL}}

Page 9: Discrete Structures Graphs 1 (Ch. 10) Dr. Muhammad Humayoun Assistant Professor COMSATS Institute of Computer Science, Lahore. mhumayoun@ciitlahore.edu.pk

9

Multigraphs

A multigraph: multiple edges connecting the same nodes

E.g., nodes are cities, edges are segments of major highways.

Page 10: Discrete Structures Graphs 1 (Ch. 10) Dr. Muhammad Humayoun Assistant Professor COMSATS Institute of Computer Science, Lahore. mhumayoun@ciitlahore.edu.pk

10

Pseudographs

Pseudograph: Like a multigraph, but edges connecting a node to itself are allowed.

Page 11: Discrete Structures Graphs 1 (Ch. 10) Dr. Muhammad Humayoun Assistant Professor COMSATS Institute of Computer Science, Lahore. mhumayoun@ciitlahore.edu.pk

Directed Graphs

A directed graph (V,E) consists of a set of vertices V and a set of directed edges E on V : ordered pairs of elements (u,v), u,v V.∈

Road networks between cities are typically undirected.

Street networks within cities are almost always directed because of one-way streets.

Most graphs of graph-theoretic interest are undirected.

11

Page 12: Discrete Structures Graphs 1 (Ch. 10) Dr. Muhammad Humayoun Assistant Professor COMSATS Institute of Computer Science, Lahore. mhumayoun@ciitlahore.edu.pk

12

Directed Multigraphs

A directed multigraph has directed parallel edges. E.g., V=web pages, E=hyperlinks. The WWW is

a directed multigraph...

Page 13: Discrete Structures Graphs 1 (Ch. 10) Dr. Muhammad Humayoun Assistant Professor COMSATS Institute of Computer Science, Lahore. mhumayoun@ciitlahore.edu.pk

13

Types of Graphs: Summary

Summary of the book’s definitions.Keep in mind this terminology is not fully

standardized across different authors...

Page 14: Discrete Structures Graphs 1 (Ch. 10) Dr. Muhammad Humayoun Assistant Professor COMSATS Institute of Computer Science, Lahore. mhumayoun@ciitlahore.edu.pk

14

Graph Models

• Graphs are used in a wide variety of models• We now describe some diverse graph models for

some interesting applications

Page 15: Discrete Structures Graphs 1 (Ch. 10) Dr. Muhammad Humayoun Assistant Professor COMSATS Institute of Computer Science, Lahore. mhumayoun@ciitlahore.edu.pk

15

SOCIAL NETWORKSAcquaintanceship Graphs

• Represent whether two people know each other, that is, whether they are acquainted.

• Each person in a particular group of people is represented by a vertex.

• Undirected edge is used to connect two people when these people know each other.

• No multiple edges are used.• Usually no loops are used. • (If we want to include the notion of self-

knowledge, we would include loops.)

Page 16: Discrete Structures Graphs 1 (Ch. 10) Dr. Muhammad Humayoun Assistant Professor COMSATS Institute of Computer Science, Lahore. mhumayoun@ciitlahore.edu.pk

16

Example

Page 17: Discrete Structures Graphs 1 (Ch. 10) Dr. Muhammad Humayoun Assistant Professor COMSATS Institute of Computer Science, Lahore. mhumayoun@ciitlahore.edu.pk

17

Page 18: Discrete Structures Graphs 1 (Ch. 10) Dr. Muhammad Humayoun Assistant Professor COMSATS Institute of Computer Science, Lahore. mhumayoun@ciitlahore.edu.pk

18

An influence graph

A directed edge (a, b) means a can influence b.

E.g. (Fred, Brian) means Fred can influence Brian.

Page 19: Discrete Structures Graphs 1 (Ch. 10) Dr. Muhammad Humayoun Assistant Professor COMSATS Institute of Computer Science, Lahore. mhumayoun@ciitlahore.edu.pk

19

Collaboration Graphs

• Academic• Non-Academic

Page 20: Discrete Structures Graphs 1 (Ch. 10) Dr. Muhammad Humayoun Assistant Professor COMSATS Institute of Computer Science, Lahore. mhumayoun@ciitlahore.edu.pk

20

COMMUNICATIONNETWORKSCall Graphs

Page 21: Discrete Structures Graphs 1 (Ch. 10) Dr. Muhammad Humayoun Assistant Professor COMSATS Institute of Computer Science, Lahore. mhumayoun@ciitlahore.edu.pk

21

Call Graphs (2)

• Call graphs that model actual calling activities can be huge. • For example, one call graph studied at AT&T, modeling calls

during 20 days, has about 290 million vertices and 4 billion edges

Page 22: Discrete Structures Graphs 1 (Ch. 10) Dr. Muhammad Humayoun Assistant Professor COMSATS Institute of Computer Science, Lahore. mhumayoun@ciitlahore.edu.pk

22

SOFTWARE DESIGN APPLICATIONSA Precedence Graph

Page 23: Discrete Structures Graphs 1 (Ch. 10) Dr. Muhammad Humayoun Assistant Professor COMSATS Institute of Computer Science, Lahore. mhumayoun@ciitlahore.edu.pk

23

TOURNAMENTSRound Robin Tournaments

• A tournament where every team plays every other team exactly once.

• Such tournaments can be modeled using directed graphs where each team is represented by a vertex.

• Note that (a, b) is an edge if team ‘a’ beats team ‘b’.

• This graph is a simple directed graph, containing no loops or multiple directed edges.

Page 24: Discrete Structures Graphs 1 (Ch. 10) Dr. Muhammad Humayoun Assistant Professor COMSATS Institute of Computer Science, Lahore. mhumayoun@ciitlahore.edu.pk

24

• Team 1 is undefeated in this tournament, and Team 3 is winless.

Page 25: Discrete Structures Graphs 1 (Ch. 10) Dr. Muhammad Humayoun Assistant Professor COMSATS Institute of Computer Science, Lahore. mhumayoun@ciitlahore.edu.pk

25

A Single-Elimination Tournament

Page 26: Discrete Structures Graphs 1 (Ch. 10) Dr. Muhammad Humayoun Assistant Professor COMSATS Institute of Computer Science, Lahore. mhumayoun@ciitlahore.edu.pk

26

Question

• Can you find a subject to which graph theory has not been applied?

Page 27: Discrete Structures Graphs 1 (Ch. 10) Dr. Muhammad Humayoun Assistant Professor COMSATS Institute of Computer Science, Lahore. mhumayoun@ciitlahore.edu.pk

27

10.2 Graph Terminology

Page 28: Discrete Structures Graphs 1 (Ch. 10) Dr. Muhammad Humayoun Assistant Professor COMSATS Institute of Computer Science, Lahore. mhumayoun@ciitlahore.edu.pk

28

Graph Terminology

Adjacency:Let G be an undirected graph with edge set E. Let e E be (or map to) the pair {u,v}.∈Then we say:u, v are adjacent / neighbors / connected.

Edge e is incident with vertices u and v.Edge e connects u and v.Vertices u and v are endpoints of edge e.

Page 29: Discrete Structures Graphs 1 (Ch. 10) Dr. Muhammad Humayoun Assistant Professor COMSATS Institute of Computer Science, Lahore. mhumayoun@ciitlahore.edu.pk

29

Neighborhood of a Vertex

Let G be an undirected graph, v V a vertex.∈The neighborhood of v, N(v), is the set of all

neighbors.

N(a) = {b, c}N(b) = {a, c}N(c) = {a, b, d}N(d) = {d}N(e) = {}

Page 30: Discrete Structures Graphs 1 (Ch. 10) Dr. Muhammad Humayoun Assistant Professor COMSATS Institute of Computer Science, Lahore. mhumayoun@ciitlahore.edu.pk

30

Degree of a Vertex

Let G be an undirected graph, v V a vertex.∈The degree of v, deg(v), is its number of

incident edges. (Note: self-loops are counted twice.)

deg(a) = 3deg(b) = 3 + 2 = 5deg(c) = 5deg(d) = 3 + 2 = 5deg(e) = 0 (isolated vertex)

Pendent vertex = with deg . 1

Page 31: Discrete Structures Graphs 1 (Ch. 10) Dr. Muhammad Humayoun Assistant Professor COMSATS Institute of Computer Science, Lahore. mhumayoun@ciitlahore.edu.pk

31

EXAMPLE

• What are the degrees and what are the neighborhoods of the vertices in the graph:

Page 32: Discrete Structures Graphs 1 (Ch. 10) Dr. Muhammad Humayoun Assistant Professor COMSATS Institute of Computer Science, Lahore. mhumayoun@ciitlahore.edu.pk

32

EXAMPLE

• The degrees:–deg(a) = 4, deg(b) = deg(e) = 6, deg(c) = 1, and

deg(d ) = 5.

• The neighborhoods–N(a) = {b, d, e}, N(b) = {a, b, c, d, e}, N(c) = {b},

N(d) = {a, b, e}, and N(e) = {a, b, d}.

Page 33: Discrete Structures Graphs 1 (Ch. 10) Dr. Muhammad Humayoun Assistant Professor COMSATS Institute of Computer Science, Lahore. mhumayoun@ciitlahore.edu.pk

33

The Handshaking Theorem

Let G be an undirected graph* with vertex set V and edge set E. Then

The sum of all the vertex degrees is an even number.

Vv

Ev 2)deg(

*(simple, multi, or pseudo)

Page 34: Discrete Structures Graphs 1 (Ch. 10) Dr. Muhammad Humayoun Assistant Professor COMSATS Institute of Computer Science, Lahore. mhumayoun@ciitlahore.edu.pk

34

Example

• deg(a)=3, deg(b)=5, deg(c)=5, deg(d)=5,

deg(e)=0

||218)deg()deg()deg()deg()deg()deg(},,,,{

Eedcbavedcbav

Page 35: Discrete Structures Graphs 1 (Ch. 10) Dr. Muhammad Humayoun Assistant Professor COMSATS Institute of Computer Science, Lahore. mhumayoun@ciitlahore.edu.pk

35

Example

• How many edges are there in a graph with 10 vertices each of degree six?

• deg(a) = deg(b) = deg(c) = … = deg(j) = 6

Vv

Ev 2)deg(

deg(a) + deg(b) + deg(c) + … + deg(j) = 2|E|10*6 = 2|E|

|E| = 60/2 = 30

Page 36: Discrete Structures Graphs 1 (Ch. 10) Dr. Muhammad Humayoun Assistant Professor COMSATS Institute of Computer Science, Lahore. mhumayoun@ciitlahore.edu.pk

36

The handshaking lemma• It is called the handshaking lemma because:– It tells us that if several people shake hands, then the

total number of hands shaken must be even – It is precisely because just two hands are involved in

each handshake.• Examples on board.– 2 vertices (deg(a)+deg(b)=2|E|)

• 1+1 = 2*|E|

– 3 vertices (deg(a)+deg(b)+deg(c)=2|E|) • 2+2+2=2*|E|• 1+1+0 = 2*|E|

– 4 vertices (deg(a)+deg(b)+deg(c)+deg(d)=2|E|)• 2+3+2+3 / 3+3+3+3 / 0+2+2+2

Page 37: Discrete Structures Graphs 1 (Ch. 10) Dr. Muhammad Humayoun Assistant Professor COMSATS Institute of Computer Science, Lahore. mhumayoun@ciitlahore.edu.pk

37

Handshaking Theorem (Corollary)

Corollary: Any undirected graph has an even number of vertices of odd degree.

In any undirected graph the number of vertices of odd degree is even.

Examples on board.1+1 = 23+3 =63+1+1+1+5+3 = 143+3+3+3 = 122+(3+1+1+1) = 6

Page 38: Discrete Structures Graphs 1 (Ch. 10) Dr. Muhammad Humayoun Assistant Professor COMSATS Institute of Computer Science, Lahore. mhumayoun@ciitlahore.edu.pk

38

Directed Graphs

Page 39: Discrete Structures Graphs 1 (Ch. 10) Dr. Muhammad Humayoun Assistant Professor COMSATS Institute of Computer Science, Lahore. mhumayoun@ciitlahore.edu.pk

39

Directed Degree

Let G be a directed graph, v a vertex of G.The in-degree of v, deg-(v), is the number of

edges going to v.The out-degree of v, deg+(v), is the number of

edges coming from v.The degree of v, deg(v):≡deg-(v)+deg+(v), is the

sum of v’s in-degree and out-degree.

Page 40: Discrete Structures Graphs 1 (Ch. 10) Dr. Muhammad Humayoun Assistant Professor COMSATS Institute of Computer Science, Lahore. mhumayoun@ciitlahore.edu.pk

40

Directed Degree

Determine in/out-degree of each nodedeg+(a)= 4 deg-(a)= 2deg+(b)= 1 deg-(b)= 2deg+(c)= 2 deg-(c)= 3deg+(d)= 2 deg-(d)= 2deg+(e)= 3 deg-(e)= 3 deg+(f)= 0 deg-(f)= 0

Page 41: Discrete Structures Graphs 1 (Ch. 10) Dr. Muhammad Humayoun Assistant Professor COMSATS Institute of Computer Science, Lahore. mhumayoun@ciitlahore.edu.pk

41

Directed Handshaking Theorem

Let G be a directed (possibly multi-) graph with vertex set V and edge set E. Then:

Note that the degree of a node is unchanged by whether we consider its edges to be directed or undirected.

Page 42: Discrete Structures Graphs 1 (Ch. 10) Dr. Muhammad Humayoun Assistant Professor COMSATS Institute of Computer Science, Lahore. mhumayoun@ciitlahore.edu.pk

42

END