SlideShare ist ein Scribd-Unternehmen logo
1 von 26
Graph Theory
Graphs are discrete structures consisting of vertices
and edges that connects these vertices. There are
several types of graphs that differ with respect to the
kind and number of edges that can connect a pair of
vertices.
A simple graph G = (V, E) consists of V, a nonempty
set of vertices, and E, a set of unordered pairs of
distinct elements V called edges.
A multigraph G = (V, E) consists of a set V of
vertices, a set of E of edges, and a function f from E to
{{u, v} | u, v є V, u ≠ v}. The edges e1 and e2 are called
multiple or parallel edges if f(e1) = f(e2).
A pseudograph G = (V, E) consists of a set V of
vertices, a set E of edges, and a function f from E to
{{u, v} | u, v є V}. An edge is loop of f(e) = {u, u} = {u}
for some u є V.
A directed graph (V, E) consists of a set of vertices V
and a set of edges E that are ordered pairs of
elements V.
A directed multigraph G = (V, E) consists of a set of
vertices V and a set of edges E, and d function f from
E to {(u, v) | u, v ε V}. The edges e1 and e2 are multiple
edges if f(e1) = f(e2).
Summary
Graph Terminology
Type

Edges

Multiple Loops
edges

Simple Graph

Undirected

No

No

Multigraph

Undirected

Yes

No

Pseudograph

Undirected

Yes

Yes

Directed Graph

Directed

No

Yes

Directed multigraph

Directed

Yes

Yes
Basic Terminology
Two vertices u and v in an undirected graph G are
called adjacent (or neighbors) in G if {u, v} is an
edge of G. If e = {u, v}, the edge e is called incident
with the vertices u and v. The edge e is also said to
connect u and v. The vertices u and v are called
endpoints of the edge {u, v}
The degree of a vertex in an undirected graph is the
number of edges incident with it, except that a loop at
a vertex contributes twice to the degree of that
vertex. The degree of the vertex v is denoted by
deg(v).
A vertex of degree 0 is called isolated.
A vertex is pendant if and only if it has degree 1.
Example: What are the degrees of the vertices in
graphs G and H.
b

G
a

c

b

H
e

g

e

f
a

d

d

c
Theorem 1
The Handshaking Theorem Let G = (V, E) be an
undirected graph with e edges. Then

2e = ∑ deg( v )
vεV

Example: How many edges are there in a graph with
10 vertices each of degree 6.
2e = (10)(6)
2e = 60
e = 30
Theorem 2
An undirected graph has an even number of vertices
of odd degree.
When (u, v) is an edge of the graph G with directed
edges, u is said to adjacent to u and v is said to be
adjacent from u. The vertex u is called the initial
vertex of (u, v), and v is called the terminal or end
vertex of (u, v). The initial vertex and terminal vertex
of a loop are the same.
In a graph with directed edges the in-degree of a
vertex v, denoted by deg – (v), is the number of edges
with v as their terminal vertex. The out-degree of v,
denoted by deg + (v), is the number of edges with v
as their initial vertex. (Note that a loop at a vertex
contributes 1 to both the in-degree and the outdegree of this vertex.)
Let G = (V, E) be a graph with directed edges. Then
−

+

∑ deg ( v ) = ∑ deg ( v ) = E

vεV

vεV
Example: Find the in-degree and out-degree of each
vertex in the graph shown below with directed edges.
a

b
c

f
e

d
Cycles – the cycle Cn, n ≥ 3, consists of n vertices v1,
v2,…., vn and edges {v1, v2}, {v2, v3},…, {vn-1, vn}, and
{vn, v1}.

C3

C4

C5

C6
Wheels – we obtain the wheel Wn when we add an
additional vertex to the cycle Cn, for n ≥ 3, and
connect this new vertex to each of the n vertices C n,
by new edges.

W3

W4

W5

W6
Representing Graphs
Adjacency lists – is used to represent a graph with
no multiple edges which specify the vertices that are
adjacent to each vertex of the graph.
B
A
E

B
C

A

D

C
E

D

Vertex Adjacent
Vertices

Vertex Adjacent
Vertices

A
B
C
D
E

A
B
C
D
E

B, C, E
A
A, D, E
C, E
A, C, D

B, C, D, E
B, D
A, C, E
B, C, D
Adjacency matrix (Ag), with respect to this listing of
the vertices, is the n x n zero-one matrix with 1 as its
(i, j)th entry when vi and vj are adjacent, and 0 as its
(i, j) entry when they are not adjacent. In other words,
if its adjacency matrix is A = [aij], then

1
aij = 
0

a
c

If {vi, vj} is an edge of G,
otherwise.

0
b 
1

1
d 
1

1
0
1
0

1
1
0
0

1

0
0

0

a
d

0
b
1

1
c
0

1
0
0
1

1
0
0
1

0

1
1

0
Adjacency matrices can also be used to represent
undirected graphs with loops and with multiple
edges. A loop at the vertex ai is represented by 1 at
the (i, j)th position of the adjacency matrix. When
multiple edges are present, the adjacency matrix is
no longer zero-one matrix, since the (i, j) entry of this
matrix equals the number of edges that are
associated to {ai, aj}. All undirected graphs, including
multigraphs and pseudographs, have symmetric
adjacency matrices
0 3 0 2
a
b


d

c

3 0 0 1

0 0 1 2


2 1 2 0
Incidence matrices – Let G = (V, E) be an
undirected graph. Suppose that v1, v2, …, vn are the
vertices and e1, e2, …., em are the edges of G. Then
the incidence matrix with respect to this ordering of V
and E is the n x m matrix M = [mij], where

1
mij = 
0
v1
e1
v4

e3
e2

when edge ej is incident with vi,
otherwise.

v 2 e6
e4
v5

v3
e5

1
0

0

1
0


1 0 0 0 0

0 1 1 0 1
0 0 0 1 1

0 1 0 0 0
1 0 1 1 0

Exercises: I. Represent the following
adjacency and incidence matrix.
e1
e2
b
a
a
b
1.
2.
e3
e3
e1
e4
e4 e5
e
c

e2

d

d
e9

a
3. e1
d
e11

e7
e5
e2 e3
e6
e8

e10

b
e4

c
e12

e6
e7

e8

5

c

using
II. Draw the graph represented by the given
adjacency matrix.

1 0 1 1 2 0
0 0 1 

4.
 5.2 0 2
1 1 1 0 2 1 

 


1
2
6.
0

1

2 0 1

0 3 0
3 1 1

0 1 0

III. Draw the graph and represent it using adjacency
matrix.
7. K4

8. K6

9. C10 10. W6
Shortest Path Problems
Applications: mileage, flight times, fares, distance,
response time, least rates, and so on.
Weighted graphs are graphs that have a number
assigned to each edge.
The length of a path in a weighted graph is the sum
of the weights of the edges of this path.
Dijktra’s Algorithm (a shortest path algorithm)
Theorem 1
Dijktra’s algorithm finds the length of a shortest path
between two vertices in a connected simple undirected
weighted graph.
Theorem 2
Dijktra’s algorithm uses O(n2) operations (additions
and comparisons) to find the length of the shortest
path between two vertices in a connected simple
undirected weighted graph.
Find the length of the shortest path between a and z
in the given weighted graph.
b

d

5

f

5

7

4
3

2

a

1

2

z

3

4
c

6

e

5

g
The traveling salesman problem
It asks for the circuit of minimum total weigh in a
weighted, complete, undirected graph that visits each
vertex exactly once and returns to its starting point.
Saginaw
113
Ground
Rapids
56

137

142

98

147
167
Detroit

135
Kalamazoo

58

133
Toledo
Route

Total distance
(miles)

D–T–G–S–K–D
D–T–G–K–S–D
D–T–K–S–G–D
D–T–K–G–S–D
D–T–S–K–G–D
D–T–S–G–K–D
D–S–T–G–K–D
D–S–T–K–G–D
D–S–K–T–G–D
D–S–G–T–K–D
D–G–S–T–K–D
D–G–T–S–K–D

610
516
588
458
540
504
598
576
682
646
670
728
Euler and Hamilton Paths
An Euler circuit in a graph G is s simple circuit
containing every edge of G. An Euler path in G is a
simple path containing every edge of G.
Theorem 1
A connected multigraph has an Euler circuit if and only
if each of its vertices has even degree.
Theorem 2
A connected multigraph has an Euler path but not
Euler circuit if and only if it has exactly two vertices of
odd degree.
A path x0, x1, …., xn-1, xn in the graph G = (V, E) is
called a Hamilton path if V = {x0, x1, …, xn-1, xn} and xi
≠ xj for 0 ≤ i , j ≤ n. A circuit x0, x1, …, xn-1, x0 (with n >
1) in a graph G = (V, E) is called Hamilton circuit if
x0, x1, …, xn-1, xn is a Hamilton path.
Theorem 3
If G is connected simple graph with n vertices where
n ≥ 3, then G has a Hamilton circuit if the degree of
each vertex is at least n/2.
Exercises:
1. Find the shortest path from a to z and a to x.
d
30

a

20

42

b
35

75
40

x

c
55

75

85

e
45
z
2. Solve the traveling salesman problem for the
following graph by finding the total weight of all the
circuits and determining a circuit with minimum total
weight.
3

a

b

7

10
2

8
5

e
1

4

c
9

d

6

Weitere ähnliche Inhalte

Was ist angesagt?

Matrix Representation Of Graph
Matrix Representation Of GraphMatrix Representation Of Graph
Matrix Representation Of Graph
Abhishek Pachisia
 

Was ist angesagt? (20)

Introduction to Graph Theory
Introduction to Graph TheoryIntroduction to Graph Theory
Introduction to Graph Theory
 
Graph Theory Introduction
Graph Theory IntroductionGraph Theory Introduction
Graph Theory Introduction
 
Metric dimesion of circulsnt graphs
Metric dimesion of circulsnt graphsMetric dimesion of circulsnt graphs
Metric dimesion of circulsnt graphs
 
MATCHING GRAPH THEORY
MATCHING GRAPH THEORYMATCHING GRAPH THEORY
MATCHING GRAPH THEORY
 
Graph Theory: Trees
Graph Theory: TreesGraph Theory: Trees
Graph Theory: Trees
 
Graphs - Discrete Math
Graphs - Discrete MathGraphs - Discrete Math
Graphs - Discrete Math
 
Chapter 5 Graphs (1).ppt
Chapter 5 Graphs (1).pptChapter 5 Graphs (1).ppt
Chapter 5 Graphs (1).ppt
 
Ppt of graph theory
Ppt of graph theoryPpt of graph theory
Ppt of graph theory
 
Graph theory
Graph theoryGraph theory
Graph theory
 
Matrix Representation Of Graph
Matrix Representation Of GraphMatrix Representation Of Graph
Matrix Representation Of Graph
 
Cs6702 graph theory and applications 2 marks questions and answers
Cs6702 graph theory and applications 2 marks questions and answersCs6702 graph theory and applications 2 marks questions and answers
Cs6702 graph theory and applications 2 marks questions and answers
 
graph theory
graph theory graph theory
graph theory
 
Lecture-9.pptx
Lecture-9.pptxLecture-9.pptx
Lecture-9.pptx
 
Applications of graph theory
                      Applications of graph theory                      Applications of graph theory
Applications of graph theory
 
Graph Theory
Graph TheoryGraph Theory
Graph Theory
 
Euler graph
Euler graphEuler graph
Euler graph
 
Introduction to Graph Theory
Introduction to Graph TheoryIntroduction to Graph Theory
Introduction to Graph Theory
 
Graph theory concepts complex networks presents-rouhollah nabati
Graph theory concepts   complex networks presents-rouhollah nabatiGraph theory concepts   complex networks presents-rouhollah nabati
Graph theory concepts complex networks presents-rouhollah nabati
 
Matrices
MatricesMatrices
Matrices
 
Graphs in data structure
Graphs in data structureGraphs in data structure
Graphs in data structure
 

Andere mochten auch

Graph representation
Graph representationGraph representation
Graph representation
Tech_MX
 
Graphs In Data Structure
Graphs In Data StructureGraphs In Data Structure
Graphs In Data Structure
Anuj Modi
 
Zato my iz_zato
Zato my iz_zatoZato my iz_zato
Zato my iz_zato
marymam
 
Zato my iz_zato
Zato my iz_zatoZato my iz_zato
Zato my iz_zato
marymam
 
Alimentacióny nutrición alejandrina ibarra avila
Alimentacióny nutrición alejandrina ibarra avilaAlimentacióny nutrición alejandrina ibarra avila
Alimentacióny nutrición alejandrina ibarra avila
cynthiardzb
 
Safe Routes to School - Elise Bremer-Nei
Safe Routes to School - Elise Bremer-NeiSafe Routes to School - Elise Bremer-Nei
Safe Routes to School - Elise Bremer-Nei
njbikeped
 
Arus bolak balik klompok 4
Arus bolak balik klompok 4Arus bolak balik klompok 4
Arus bolak balik klompok 4
FITRIA NENGSIH
 
Bali island
Bali islandBali island
Bali island
AIZZY118
 
Kurchatow
KurchatowKurchatow
Kurchatow
marymam
 
PRESENTACIÓN DEL IIEP _ NC
PRESENTACIÓN DEL IIEP _ NCPRESENTACIÓN DEL IIEP _ NC
PRESENTACIÓN DEL IIEP _ NC
nadiamjiiep
 
зато мы из ЗАТО
зато мы из ЗАТОзато мы из ЗАТО
зато мы из ЗАТО
marymam
 

Andere mochten auch (18)

Graph representation
Graph representationGraph representation
Graph representation
 
Graphs In Data Structure
Graphs In Data StructureGraphs In Data Structure
Graphs In Data Structure
 
Graph theory1234
Graph theory1234Graph theory1234
Graph theory1234
 
Graph theory
Graph theoryGraph theory
Graph theory
 
Zato my iz_zato
Zato my iz_zatoZato my iz_zato
Zato my iz_zato
 
Zato my iz_zato
Zato my iz_zatoZato my iz_zato
Zato my iz_zato
 
MD Grand Akashu Riau
MD Grand Akashu RiauMD Grand Akashu Riau
MD Grand Akashu Riau
 
Metadata & brokering - a modern approach #2
Metadata & brokering - a modern approach #2Metadata & brokering - a modern approach #2
Metadata & brokering - a modern approach #2
 
Alimentacióny nutrición alejandrina ibarra avila
Alimentacióny nutrición alejandrina ibarra avilaAlimentacióny nutrición alejandrina ibarra avila
Alimentacióny nutrición alejandrina ibarra avila
 
Safe Routes to School - Elise Bremer-Nei
Safe Routes to School - Elise Bremer-NeiSafe Routes to School - Elise Bremer-Nei
Safe Routes to School - Elise Bremer-Nei
 
Arus bolak balik klompok 4
Arus bolak balik klompok 4Arus bolak balik klompok 4
Arus bolak balik klompok 4
 
Bali island
Bali islandBali island
Bali island
 
UCL of Slideshare
UCL of SlideshareUCL of Slideshare
UCL of Slideshare
 
Hazyl Joan Amellos
Hazyl Joan AmellosHazyl Joan Amellos
Hazyl Joan Amellos
 
Strat Plan May 31 2014
Strat Plan May 31 2014Strat Plan May 31 2014
Strat Plan May 31 2014
 
Kurchatow
KurchatowKurchatow
Kurchatow
 
PRESENTACIÓN DEL IIEP _ NC
PRESENTACIÓN DEL IIEP _ NCPRESENTACIÓN DEL IIEP _ NC
PRESENTACIÓN DEL IIEP _ NC
 
зато мы из ЗАТО
зато мы из ЗАТОзато мы из ЗАТО
зато мы из ЗАТО
 

Ähnlich wie Graph theory

1. Graph and Graph Terminologiesimp.pptx
1. Graph and Graph Terminologiesimp.pptx1. Graph and Graph Terminologiesimp.pptx
1. Graph and Graph Terminologiesimp.pptx
swapnilbs2728
 

Ähnlich wie Graph theory (20)

graph ASS (1).ppt
graph ASS (1).pptgraph ASS (1).ppt
graph ASS (1).ppt
 
graph.ppt
graph.pptgraph.ppt
graph.ppt
 
graph.ppt
graph.pptgraph.ppt
graph.ppt
 
Graph ASS DBATU.pptx
Graph ASS DBATU.pptxGraph ASS DBATU.pptx
Graph ASS DBATU.pptx
 
Graphs.pdf
Graphs.pdfGraphs.pdf
Graphs.pdf
 
Elements of Graph Theory for IS.pptx
Elements of Graph Theory for IS.pptxElements of Graph Theory for IS.pptx
Elements of Graph Theory for IS.pptx
 
LEC 1.pptx
LEC 1.pptxLEC 1.pptx
LEC 1.pptx
 
Ass. (3)graph d.m
Ass. (3)graph d.mAss. (3)graph d.m
Ass. (3)graph d.m
 
1. Graph and Graph Terminologiesimp.pptx
1. Graph and Graph Terminologiesimp.pptx1. Graph and Graph Terminologiesimp.pptx
1. Graph and Graph Terminologiesimp.pptx
 
Tn 110 lecture 8
Tn 110 lecture 8Tn 110 lecture 8
Tn 110 lecture 8
 
Graphs
GraphsGraphs
Graphs
 
Graph
GraphGraph
Graph
 
graph.pptx
graph.pptxgraph.pptx
graph.pptx
 
graph theory
graph theorygraph theory
graph theory
 
Graph Theory,Graph Terminologies,Planar Graph & Graph Colouring
Graph Theory,Graph Terminologies,Planar Graph & Graph ColouringGraph Theory,Graph Terminologies,Planar Graph & Graph Colouring
Graph Theory,Graph Terminologies,Planar Graph & Graph Colouring
 
Unit 2: All
Unit 2: AllUnit 2: All
Unit 2: All
 
Graph-theory.ppt
Graph-theory.pptGraph-theory.ppt
Graph-theory.ppt
 
Graph.ppt
Graph.pptGraph.ppt
Graph.ppt
 
DIGITAL TEXT BOOK
DIGITAL TEXT BOOKDIGITAL TEXT BOOK
DIGITAL TEXT BOOK
 
Ch08.ppt
Ch08.pptCh08.ppt
Ch08.ppt
 

Kürzlich hochgeladen

Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 

Kürzlich hochgeladen (20)

Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu SubbuApidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
A Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source MilvusA Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source Milvus
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 

Graph theory

  • 1. Graph Theory Graphs are discrete structures consisting of vertices and edges that connects these vertices. There are several types of graphs that differ with respect to the kind and number of edges that can connect a pair of vertices. A simple graph G = (V, E) consists of V, a nonempty set of vertices, and E, a set of unordered pairs of distinct elements V called edges. A multigraph G = (V, E) consists of a set V of vertices, a set of E of edges, and a function f from E to {{u, v} | u, v є V, u ≠ v}. The edges e1 and e2 are called multiple or parallel edges if f(e1) = f(e2).
  • 2. A pseudograph G = (V, E) consists of a set V of vertices, a set E of edges, and a function f from E to {{u, v} | u, v є V}. An edge is loop of f(e) = {u, u} = {u} for some u є V. A directed graph (V, E) consists of a set of vertices V and a set of edges E that are ordered pairs of elements V. A directed multigraph G = (V, E) consists of a set of vertices V and a set of edges E, and d function f from E to {(u, v) | u, v ε V}. The edges e1 and e2 are multiple edges if f(e1) = f(e2).
  • 3. Summary Graph Terminology Type Edges Multiple Loops edges Simple Graph Undirected No No Multigraph Undirected Yes No Pseudograph Undirected Yes Yes Directed Graph Directed No Yes Directed multigraph Directed Yes Yes
  • 4. Basic Terminology Two vertices u and v in an undirected graph G are called adjacent (or neighbors) in G if {u, v} is an edge of G. If e = {u, v}, the edge e is called incident with the vertices u and v. The edge e is also said to connect u and v. The vertices u and v are called endpoints of the edge {u, v} The degree of a vertex in an undirected graph is the number of edges incident with it, except that a loop at a vertex contributes twice to the degree of that vertex. The degree of the vertex v is denoted by deg(v). A vertex of degree 0 is called isolated. A vertex is pendant if and only if it has degree 1.
  • 5. Example: What are the degrees of the vertices in graphs G and H. b G a c b H e g e f a d d c
  • 6. Theorem 1 The Handshaking Theorem Let G = (V, E) be an undirected graph with e edges. Then 2e = ∑ deg( v ) vεV Example: How many edges are there in a graph with 10 vertices each of degree 6. 2e = (10)(6) 2e = 60 e = 30
  • 7. Theorem 2 An undirected graph has an even number of vertices of odd degree. When (u, v) is an edge of the graph G with directed edges, u is said to adjacent to u and v is said to be adjacent from u. The vertex u is called the initial vertex of (u, v), and v is called the terminal or end vertex of (u, v). The initial vertex and terminal vertex of a loop are the same.
  • 8. In a graph with directed edges the in-degree of a vertex v, denoted by deg – (v), is the number of edges with v as their terminal vertex. The out-degree of v, denoted by deg + (v), is the number of edges with v as their initial vertex. (Note that a loop at a vertex contributes 1 to both the in-degree and the outdegree of this vertex.) Let G = (V, E) be a graph with directed edges. Then − + ∑ deg ( v ) = ∑ deg ( v ) = E vεV vεV
  • 9. Example: Find the in-degree and out-degree of each vertex in the graph shown below with directed edges. a b c f e d
  • 10. Cycles – the cycle Cn, n ≥ 3, consists of n vertices v1, v2,…., vn and edges {v1, v2}, {v2, v3},…, {vn-1, vn}, and {vn, v1}. C3 C4 C5 C6
  • 11. Wheels – we obtain the wheel Wn when we add an additional vertex to the cycle Cn, for n ≥ 3, and connect this new vertex to each of the n vertices C n, by new edges. W3 W4 W5 W6
  • 12. Representing Graphs Adjacency lists – is used to represent a graph with no multiple edges which specify the vertices that are adjacent to each vertex of the graph. B A E B C A D C E D Vertex Adjacent Vertices Vertex Adjacent Vertices A B C D E A B C D E B, C, E A A, D, E C, E A, C, D B, C, D, E B, D A, C, E B, C, D
  • 13. Adjacency matrix (Ag), with respect to this listing of the vertices, is the n x n zero-one matrix with 1 as its (i, j)th entry when vi and vj are adjacent, and 0 as its (i, j) entry when they are not adjacent. In other words, if its adjacency matrix is A = [aij], then 1 aij =  0 a c If {vi, vj} is an edge of G, otherwise. 0 b  1  1 d  1 1 0 1 0 1 1 0 0 1  0 0  0 a d 0 b 1  1 c 0 1 0 0 1 1 0 0 1 0  1 1  0
  • 14. Adjacency matrices can also be used to represent undirected graphs with loops and with multiple edges. A loop at the vertex ai is represented by 1 at the (i, j)th position of the adjacency matrix. When multiple edges are present, the adjacency matrix is no longer zero-one matrix, since the (i, j) entry of this matrix equals the number of edges that are associated to {ai, aj}. All undirected graphs, including multigraphs and pseudographs, have symmetric adjacency matrices 0 3 0 2 a b   d c 3 0 0 1  0 0 1 2   2 1 2 0
  • 15. Incidence matrices – Let G = (V, E) be an undirected graph. Suppose that v1, v2, …, vn are the vertices and e1, e2, …., em are the edges of G. Then the incidence matrix with respect to this ordering of V and E is the n x m matrix M = [mij], where 1 mij =  0 v1 e1 v4 e3 e2 when edge ej is incident with vi, otherwise. v 2 e6 e4 v5 v3 e5 1 0  0  1 0  1 0 0 0 0  0 1 1 0 1 0 0 0 1 1  0 1 0 0 0 1 0 1 1 0 
  • 16. Exercises: I. Represent the following adjacency and incidence matrix. e1 e2 b a a b 1. 2. e3 e3 e1 e4 e4 e5 e c e2 d d e9 a 3. e1 d e11 e7 e5 e2 e3 e6 e8 e10 b e4 c e12 e6 e7 e8 5 c using
  • 17. II. Draw the graph represented by the given adjacency matrix. 1 0 1 1 2 0 0 0 1   4.  5.2 0 2 1 1 1 0 2 1      1 2 6. 0  1 2 0 1  0 3 0 3 1 1  0 1 0 III. Draw the graph and represent it using adjacency matrix. 7. K4 8. K6 9. C10 10. W6
  • 18. Shortest Path Problems Applications: mileage, flight times, fares, distance, response time, least rates, and so on. Weighted graphs are graphs that have a number assigned to each edge. The length of a path in a weighted graph is the sum of the weights of the edges of this path.
  • 19. Dijktra’s Algorithm (a shortest path algorithm) Theorem 1 Dijktra’s algorithm finds the length of a shortest path between two vertices in a connected simple undirected weighted graph. Theorem 2 Dijktra’s algorithm uses O(n2) operations (additions and comparisons) to find the length of the shortest path between two vertices in a connected simple undirected weighted graph.
  • 20. Find the length of the shortest path between a and z in the given weighted graph. b d 5 f 5 7 4 3 2 a 1 2 z 3 4 c 6 e 5 g
  • 21. The traveling salesman problem It asks for the circuit of minimum total weigh in a weighted, complete, undirected graph that visits each vertex exactly once and returns to its starting point. Saginaw 113 Ground Rapids 56 137 142 98 147 167 Detroit 135 Kalamazoo 58 133 Toledo
  • 23. Euler and Hamilton Paths An Euler circuit in a graph G is s simple circuit containing every edge of G. An Euler path in G is a simple path containing every edge of G. Theorem 1 A connected multigraph has an Euler circuit if and only if each of its vertices has even degree. Theorem 2 A connected multigraph has an Euler path but not Euler circuit if and only if it has exactly two vertices of odd degree.
  • 24. A path x0, x1, …., xn-1, xn in the graph G = (V, E) is called a Hamilton path if V = {x0, x1, …, xn-1, xn} and xi ≠ xj for 0 ≤ i , j ≤ n. A circuit x0, x1, …, xn-1, x0 (with n > 1) in a graph G = (V, E) is called Hamilton circuit if x0, x1, …, xn-1, xn is a Hamilton path. Theorem 3 If G is connected simple graph with n vertices where n ≥ 3, then G has a Hamilton circuit if the degree of each vertex is at least n/2.
  • 25. Exercises: 1. Find the shortest path from a to z and a to x. d 30 a 20 42 b 35 75 40 x c 55 75 85 e 45 z
  • 26. 2. Solve the traveling salesman problem for the following graph by finding the total weight of all the circuits and determining a circuit with minimum total weight. 3 a b 7 10 2 8 5 e 1 4 c 9 d 6