0% found this document useful (0 votes)
19 views

Lecture 12 Graph

This document discusses discrete structures and graph theory. It begins by defining what a graph is - a mathematical structure used to model pairwise relations between objects. It then provides a brief history of graph theory, tracing it back to Leonhard Euler's work on the Konigsberg bridge problem in 1736. The document goes on to define different types of graphs like simple graphs, directed graphs, and multigraphs. It also provides examples of how graphs can be used to model real-world problems and applications in areas like social networks, computer networks, and software design.

Uploaded by

jaffar bikat
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views

Lecture 12 Graph

This document discusses discrete structures and graph theory. It begins by defining what a graph is - a mathematical structure used to model pairwise relations between objects. It then provides a brief history of graph theory, tracing it back to Leonhard Euler's work on the Konigsberg bridge problem in 1736. The document goes on to define different types of graphs like simple graphs, directed graphs, and multigraphs. It also provides examples of how graphs can be used to model real-world problems and applications in areas like social networks, computer networks, and software design.

Uploaded by

jaffar bikat
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 57

Discrete Structures

MUHAMMAD JAFFAR KHAN (MS Electrical Engineering)


MASTER IN COMPUTER SCIENCE-1
FEDERAL URDU UNIVERSITY, ISLAMABAD (Campus).
WHAT IS GRAPH THEORY?
• Graph theory is the study of mathematical structures
called graphs that are used to model pair wise
relations between objects from a certain collection.

• The origin of graph theory can be traced back to


Leonard Euler's (German) work on the “Konigsberg
bridge problem” on 1736.
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

4
Perhaps the first graph you
saw
 Can we sent all the utilities to the three
houses without crossing wires?

Not possible!

5
The first graph theory
Königsberg
City in Germany
 The first graph theory paper by Leonhard Euler
 In 1736: Seven bridges of Königsberg
 A town with 7 bridges and 4 pieces of land…

The (Eulerian) path


should cross over each
of the seven bridges
exactly once
The Origin of Graph Theory
 Can we travel each bridge exactly once and
return to the starting point?
The (Eulerian) path should cross over each of the
seven bridges exactly once

Not possible!

7
THE Bridges of the Konigsberg
This can be pictured as follows:

e1 e2 e4
B e3 D

e5 e6 e7
C

•Vertices
The question is whether
are V={A,B,C,D} a person
and edges are E=can plan a walk in
{e1,e2,e3,e4,e5,e6,e7}.
e1 such
and e2a way that hewith
is associated will the
cross each ofpair
unordered these bridges
(A,B), e5 and e6 is
once but
associated not(B,C),
with more e3than once. with (B,D), e4 is associated
is associated
with (A,D) and e7 is associated with (C,D) and so on.
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)

9
Vertex Edge Graph

Vertex Edge Graph - A collection of points some


of which are joined by line segments or curves.

This graph has 6 vertices and 7 edges


Each point is a vertex and each line is an edge
11
Simple Graphs
 A graph in which each edge connects two
different vertices and where no two edges
connect the same pair of vertices.
 Note: Multiple edges between pair of nodes;
Self Loops are not allowed

12
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}}
13
Multigraphs
 A multigraph:
 multiple edges connecting same nodes

Simple Graph + Multiple Edges (Multiedges)


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

14
Pseudographs
 Pseudograph:
 Like a multigraph, but edges connecting a node to itself are
allowed.
 Simple Graph+ multiedge+ loop

15
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.
 Note: loop are allowed in a directed graph.

 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.
16
17
Directed Multigraphs
 A directed multigraph has directed parallel edges.
 Directed Multigraph=Directed Graph+ Multiedges
 E.g.,
 V=web pages,
 E=hyperlinks.
 The WWW is a directed multigraph...

18
Types of Graphs: Summary
 Summary of the book’s definitions.
 Keep in mind this terminology is not fully
standardized across different authors...

19
Graph Models
• Graphs are used in a wide variety of models
• We now describe some diverse graph models for
some interesting applications

20
Graph Theory Application
1. Assignment of jobs to employees of an organization
2. The outcomes of round-robin tournaments.
3. To model acquaintanceship between people
4. Telephone calls between telephone numbers, and links
between websites.
5. To walk down all the streets in a city without going down a
street twice
6. Circuit board.
7. Two chemical compounds with the same molecular formula but
different structures using graphs.
8. Computer networks.
22
Graph Models: Social Networks
• Graphs can be used to model social structures based on
different kinds of relationships between people or groups.
• In a social network, vertices represent individuals or
organizations and edges represent relationships between
them.
• Useful graph models of social networks include:
 friendship graphs - undirected graphs where two people are
connected if they are friends (in the real world, on Facebook, or in a
particular virtual world, and so on.)
 collaboration graphs - undirected graphs where two people are
connected if they collaborate in a specific way
 influence graphs - directed graphs where there is an edge from one
person to another if the first person can influence the second person
23
SOCIAL NETWORKS
Acquaintanceship 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.) 24
Example

25
26
An influence graph
 A directed edge (a, b) means a can influence b.
 E.g. (Fred, Brian) means Fred can influence
Brian.

27
Collaboration Graphs
• Academic
• Non-Academic

28
Graph Models:
Computer Networks
• In all these graph models, the vertices represent data
centers and the edges represent communication links.
• To model a computer network where we are only
concerned whether two data centers are connected by
a communications link, we use a simple graph.
 This is the appropriate type of graph when we only care
whether two data centers are directly linked (and not how
many links there may be) and all communications links work in
both directions.

29
Graph Models:
Computer Networks
• To model a computer network where we care about the
number of links between data centers,
 we use a multigraph.

30
Graph Models:
Computer Networks
• To model a computer network with diagnostic
links at data centers,
we use a pseudograph, as loops are needed.

31
Graph Models:
Computer Networks
• To model a network with multiple one-way links,
we use a directed multigraph.
• Note that
we could use a directed graph without multiple edges
 if we only care whether there is at least one link from
a data center to another data center.

32
Call Graphs

33
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
34
SOFTWARE DESIGN APPLICATIONS
A Precedence Graph
• The dependencies between the seven modules in the design of a
web browser are represented by this module dependency graph.
• We can use a directed graph called a precedence graph to represent
which statements must have already been executed before we
execute each statement.
• Vertices represent statements in a computer program
• There is a directed edge from a vertex to a second vertex if the
second vertex cannot be executed before the first
Which statements must be executed before S6 is executed in the program?

The model says that statements for which there are


edges to S6 must be executed before S6 , namely the
statements S1, S2 , S3 , S4 and S5.

35
TOURNAMENTS
Round 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.
36
• Team 1 is undefeated in this tournament, and
Team 3 is winless.
37
A Single-Elimination Tournament

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

39
10.2 Graph Terminology

40
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.

41
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, b, c}
N(c) = {a, b, d}
N(d) = {d, c}
N(e) = {}

42
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 and have degree 2.)
deg(a) = 3
deg(b) = 3 + 2 = 5
deg(c) = 5
deg(d) = 3 + 2 = 5
deg(e) = 0 (isolated vertex)

Pendent vertex = with degree 143


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

44
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}.
45
46
47
48
The Handshaking Theorem

 Let G be an undirected graph* with vertex set V and edge


set E. Then
 deg(v)  2 E
vV
Where,
 |E| is the (cardinality of Edges) number of edges.
 is the sum of the degrees of the vertices , means
Total Degree of Graph.

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

*
(simple, multi, or pseudo) 49
Example

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

 deg(v)  deg(a)  deg(b)  deg(c)  deg(d )  deg(e)  18  2 | E |


v{ a ,b ,c , d ,e}

50
EXAMPLE 3 at
Page# 653
• How many edges are there in a graph with 10
vertices each of degree six?
• deg(a) = deg(b) = deg(c) = … = deg(j) = 6
According to Handshaking Theorem,
 deg(v)  2 E
vV

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


10*6 = 2|E|
|E| = 60/2 = 30
There are 30 edges in a graph.
51
The handshaking Theorem Cont.
• It is called the handshaking theorem 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|) 52
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 = 2
 3+3 =6
 3+1+1+1+5+3 = 14
 3+3+3+3 = 12
 2+(3+1+1+1) = 6

53
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. ( v <----- )

 The out-degree of v, deg+(v), is the number of


edges coming out from v. ( v -----> )

 The degree of v, deg(v):≡deg-(v)+deg+(v), is the


sum of v’s in-degree and out-degree.
54
Example# 4 at Page# 654
 Determine out/in-degree of each node

deg+(a)= 4 deg-(a)= 2
deg+(b)= 1 deg-(b)= 2
deg+(c)= 2 deg-(c)= 3
deg+(d)= 2 deg-(d)= 2
deg+(e)= 3 deg-(e)= 3
deg+(f)= 0 deg-(f)= 0

55
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.
56
END

57

You might also like