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
Jan 05, 2016
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
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
3
Perhaps the first graph you saw
Can we sent all the utilities to the three houses without crossing wires?
Not possible!
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…
5
The Origin of Graph Theory
Can we travel each bridge exactly once and return to the starting point?
Not possible!
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)
7
Simple GraphsA graph in which each edge connects two
different vertices and where no two edges connect the same pair of vertices.
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}}
9
Multigraphs
A multigraph: multiple edges connecting the same nodes
E.g., nodes are cities, edges are segments of major highways.
10
Pseudographs
Pseudograph: Like a multigraph, but edges connecting a node to itself are allowed.
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
12
Directed Multigraphs
A directed multigraph has directed parallel edges. E.g., V=web pages, E=hyperlinks. The WWW is
a directed multigraph...
13
Types of Graphs: Summary
Summary of the book’s definitions.Keep in mind this terminology is not fully
standardized across different authors...
14
Graph Models
• Graphs are used in a wide variety of models• We now describe some diverse graph models for
some interesting applications
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.)
16
Example
17
18
An influence graph
A directed edge (a, b) means a can influence b.
E.g. (Fred, Brian) means Fred can influence Brian.
19
Collaboration Graphs
• Academic• Non-Academic
20
COMMUNICATIONNETWORKSCall Graphs
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
22
SOFTWARE DESIGN APPLICATIONSA Precedence Graph
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.
24
• Team 1 is undefeated in this tournament, and Team 3 is winless.
25
A Single-Elimination Tournament
26
Question
• Can you find a subject to which graph theory has not been applied?
27
10.2 Graph Terminology
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.
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) = {}
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
31
EXAMPLE
• What are the degrees and what are the neighborhoods of the vertices in the graph:
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}.
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)
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
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
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
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
38
Directed Graphs
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.
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
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.
42
END