Mid II
Mid II
c. Is 1R3, 2R2?
Solution:
c. Since (1, 3)∈R so 1R3.
Since (2, 2)∈R so 2R2.
Representing Relations Using Digraphs
Definition: A directed graph, or digraph, consists of a set V of
vertices (or nodes) together with a set E of ordered pairs of
elements of V called edges (or arcs). The vertex a is called the
initial vertex of the edge (a,b), and the vertex b is called the
terminal vertex of this edge.
An edge of the form (a,a) is called a loop.
More precisely, M is a
symmetric matrix i.e. M = M t
Accordingly, R is symmetric if the
elements in the ith row are the
same as the elements in the ith
column of the matrix M
representing R. More precisely, M
is a symmetric matrix
i.e. M = 𝑀𝑡
Symmetric Relations
EXAMPLE: Let A = {1, 2, 3, 4} and determine whether
relations R1, R2, R3, and R4 are Symmetric?
R1 = {(1, 1), (1, 3), (2, 4), (3, 1), (4,2)}
R2 = {(1, 1), (2, 2), (3, 3), (4, 4)}
R3 = {(2, 2), (2, 3), (3, 4)}
R4 = {(1, 1), (2, 2), (3, 3), (4, 3), (4, 4)}
Solution:
R1 is Symmetric, since (a, b) and (b, a) ∈R1 for all (a, b) ∈A.
R2 is also symmetric. We say it is vacuously true.
R3 is not symmetric, because (2,3) ∈ R3 but (3,2) ∉ R3.
R4 is not symmetric because (4,3) ∈ R4 but (3,4) ∉ R4.
Transitive Relations
Definition: A relation R on a set A is called transitive if
whenever (a,b) ∊ R and (b,c) ∊ R, then (a,c) ∊ R, for all a,b,c
∊ A. Written symbolically, R is transitive if and only if
∀a∀b ∀c[(a,b) ∊R ∧ (b,c) ∊ R ⟶ (a,c) ∊ R ]
For a transitive
directed graph,
whenever there is
an arrow going
from one point
to the second, and
from the second
to the third, there
is an arrow going
directly from the
first to the third.
Transitive Relations
EXAMPLE: Let A = {1, 2, 3, 4} and determine whether
relations R1, R2 and R3 are Transitive?
R1 = {(1, 1), (1, 2), (1, 3), (2, 3)}
R2 = {(1, 2), (1, 4), (2, 3), (3, 4)}
R3 = {(2, 1), (2, 4), (2, 3), (3,4)}
Solution:
R1 is transitive because (1, 1), (1, 2) are in R, then to be
transitive relation(1,2) must be there and it belongs to R.
R2 is not transitive since (1,2) and (2,3) ∈ R2 but (1,3) ∉ R2.
R3 is transitive.(check by definition)
Irreflexive Relations
Definition: R is irreflexive iff for all a∈A,(a,a) ∉R. That is,
R is irreflexive if no element in A is related to itself by R.
Written symbolically, R is irreflexive if and only if
∀a [(a ∊A) ⟶ (a , a)∉ R]
R is not irreflexive
iff there is an
element a∈A such
that (a,a) ∈R.
Irreflexive Relations
EXAMPLE: Let A = {1, 2, 3, 4} and determine whether
relations R1, R2 and R3 are Irreflexive?
R1 = {(1,3), (1,4), (2,3), (2,4), (3,1), (3,4)}
R2 = {(1,1), (1,2), (2,1), (2,2), (3,3), (4,4)}
R3= {(1,2), (2,3), (3,3), (3,4)}
Solution:
R1 is irreflexive since no element of A is related to itself in
R1. i.e. (1,1)∉ R1, (2,2) ∉ R1, (3,3) ∉ R1,(4,4) ∉ R1.
R2 is not irreflexive, since all elements of A are related to
themselves in R2.
R3 is not irreflexive since (3,3) ∈R3. Note that R3 is not
reflexive.
Antisymmetric Relations
Definition: A relation R on a set A such that for all a,b ∊ A
if (a,b) ∊ R and (b,a) ∊ R, then a = b is called
antisymmetric. Written symbolically, R is antisymmetric if
and only if ∀a∀b [(a,b) ∊R ∧ (b,a) ∊ R ⟶ a = b]
Note: (a,a) may be an element in R. Let R be an anti-
symmetric relation on a
set A = {a1, a2, …, an}.
Then if (ai, aj) ∈R for
i ≠ j then (ai, aj) ∉R.
Thus in the matrix
representation of R
there is a 1 in the ith row
and jth column
iff the jth row and ith
column contains 0 vice
versa.
Antisymmetric Relations
EXAMPLE: Let A = {1, 2, 3, 4} and determine whether relations R1,
R2, R3, and R4 are Antisymmetric?
R1 = {(1,1),(2,2),(3,3)}
R2 = {(1,2),(2,2), (2,3), (3,4), (4,1)}
R3={(1,3),(2,2), (2,4), (3,1), (4,2)}
R4={(1,3),(2,4), (3,1), (4,3)}
Solution:
R1 is anti-symmetric and symmetric.
R2 is anti-symmetric but not symmetric because (1,2) ∈ R2 but
(2,1) ∉ R2.
R3 is not anti-symmetric since (1,3) & (3,1) ∈ R3 but 1 ≠ 3. Note
that R3 is symmetric.
R4 is neither anti-symmetric because (1,3) & (3,1) ∈ R4 but 1 ≠ 3
nor symmetric because (2,4) ∈ R4 but (4,2) ∉R4.
Asymmetric Relations
Definition: R is Asymmetric iff for all (a,b) ∊R than (b ,a)∉R.
Written symbolically, R is Asymmetric if and only if
∀a ∀b[((a,b) ∊R)) ⟶ ((b , a)∉ R)]
Note:(a,a) cannot be an element in R.
Asymmetry =
Antisymmetry +
Irreflexivity
Asymmetric Relations
EXAMPLE: Let A = {1, 2, 3, 4} and determine whether
relations R1, R2 and R3 are Asymmetric?
R1 = {(1,1), (1,2), (2,1), (2,2), (3,4), (4,1), (4,4)}
R2 = {(1,2),(2,3),(3,4)}
R3 = {(2,3),(3,3),(3,4)}
Solution:
R1 is not Asymmetric since R1 is neither Antisymmetric
nor Irreflexive.
R2 is Asymmetric since R2 is both Antisymmetric and
Irreflexive.
R3 is not Asymmetric since it is Antisymmetric but not
irreflexive.
Activity Time
Consider the following relations on {1, 2, 3, 4}:
R1 = {(1, 1), (1, 2), (2, 1), (2, 2), (3, 4), (4, 1), (4, 4)},
R2 = {(1, 1), (1, 2), (2, 1)},
R3 = {(1, 1), (1, 2), (1, 4), (2, 1), (2, 2), (3, 3), (4, 1), (4, 4)},
R4 = {(2, 1), (3, 1), (3, 2), (4, 1), (4, 2), (4, 3)},
R5 = {(1, 1), (1, 2), (1, 3), (1, 4), (2, 2), (2, 3), (2, 4), (3, 3), (3, 4), (4, 4)},
R6 = {(3, 4)}.
R1∘ R2 = {(b,D),(b,B)}
Composition of Relations
What is the composite of the relations R and S, where
R is the relation from {1,2,3} to {1,2,3,4} with
R = {(1,1),(1,4),(2,3),(3,1),(3,4)}
S is the relation from {1,2,3,4} to {0,1,2} with
S = {(1,0),(1,2),(2,0),(3,1),(3,2),(4,1)}?
S o R = {(1,0),(1,2),(1,1), (2,2),(2,1), (3,0),(3,2),(3,1)}
INVERSE OF A RELATION
Let R be a relation from A to B. The inverse relation
𝑅−1 from B to A is defined as:
𝑅−1 = {(b,a) ∈B×A | (a,b) ∈R}
More simply, the inverse relation 𝑅−1 of R is obtained by
interchanging the elements of all the ordered pairs in R.
Example
X = {a, b, c} and Y={1, 2}
R = {(a, 1), (b, 2), (c, 1)}
𝑅 −1 = {(1, a), (2, b), (1, c)}
INVERSE OF A RELATION
The relation
R = {(2,2), (2,6), (2,8), (3,6), (4,8)} is
represented by the arrow diagram.
These properties all follow from the order axioms for the integers.
(See Appendix 1).
Partial Orderings (continued)
Example 2: Show that the divisibility relation (∣) is a
partial ordering on the set of integers.
Reflexivity: a ∣ a for all integers a. (see Example 9 in
Section 9.1)
Antisymmetry: If a and b are positive integers with a | b
and b | a, then a = b. (see Example 12 in Section 9.1)
Transitivity: Suppose that a divides b and b divides c.
Then there are positive integers k and l such that b = ak
and c = bl. Hence, c = a(kl), so a divides c. Therefore, the
relation is transitive.
(Z+, ∣) is a poset.
Partial Orderings (continued)
Example 3: Show that the inclusion relation (⊆) is a
partial ordering on the power set of a set S.
Reflexivity: A ⊆ A whenever A is a subset of S.
Antisymmetry: If A and B are positive integers with
A ⊆ B and B ⊆ A, then A = B.
Transitivity: If A ⊆ B and B ⊆ C, then A ⊆ C.
3. Let a = 1 and d = 2:
Arithmetic Sequences
EXAMPLE:
Find the 20th term of the arithmetic sequence
3, 9, 15, 21, …
SOLUTION:
Here a = first term = 3
d = common difference = 9 - 3 = 6
n = term number = 20
a20 = value of 20th term = ?
Since a = a + (n - 1) d; n ≥1
n
∴ a20 = 3 + (20 - 1) 6
= 3 + 114
= 117
Arithmetic Sequences
EXERCISE:
Find the 36th term of the arithmetic sequence whose 3rd term is
7 and 8th term is 17.
SOLUTION:
Let a be the first term and d be the common difference of the
arithmetic sequence.
Then an = a + (n - 1)d n ≥ 1
⇒ a3 = a + (3 - 1) d and a8 = a + (8 - 1) d
Given that a = 7 and a = 17. Therefore
3 8
7 = a + 2d……………………(1) and 17 = a +
7d………….………..(2)
Subtracting (1) from (2), we get,
10 = 5d ⇒d=2
Substituting d = 2 in (1) we have
7 = a + 2(2) which gives a = 3
Arithmetic Sequences
Thus, an = a + (n - 1) d
an = 3 + (n - 1) 2 (using values of a and d)
Hence the value of 36th term is
a36 = 3 + (36 - 1) 2
= 3 + 70
a36 = 73
Geometric Progression OR Sequence
A sequence in which every term after the first is
obtained from the preceding term by multiplying it
with a constant number is called a geometric
sequence or geometric progression (G.P.)
The constant number, being the ratio of any two
consecutive terms is called the common ratio of the
G.P. commonly denoted by “r”.
EXAMPLE:
1. 1, 2, 4, 8, 16, … (common ratio = 2)
2. 3, - 3/2, 3/4, - 3/8, … (common ratio = - 1/2)
3. 0.1, 0.01, 0.001, 0.0001, … (common ratio = 0.1 =
1/10)
GENERAL TERM OF A GEOMETRIC SEQUENCE:
Geometric Progression
Examples:
1. Let a = 1 and r = −1. Then:
Answer:
f2 = f1 + f0 = 1 + 0 = 1,
f3 = f2 + f1 = 1 + 1 = 2,
f4 = f3 + f2 = 2 + 1 = 3,
f5 = f4 + f3 = 3 + 2 = 5,
f6 = f5 + f4 = 5 + 3 = 8.
Iterative Solution Example
Method 1: Working upward, forward substitution
Let {an} be a sequence that satisfies the recurrence relation
an = an-1 + 3 for n = 2,3,4,…. and suppose that a1 = 2.
a2 = 2 + 3
a3 = (2 + 3) + 3 = 2 + 3 ∙ 2
a4 = (2 + 2 ∙ 3) + 3 = 2 + 3 ∙ 3
.
.
.
an = an-1 + 3 = (2 + 3 ∙ (n – 2)) + 3 = 2 + 3(n – 1)
Iterative Solution Example
Method 2: Working downward, backward substitution
Let {an} be a sequence that satisfies the recurrence relation
an = an-1 + 3 for n = 2,3,4,…. and suppose that a1 = 2.
an = an-1 + 3
= (an-2 + 3) + 3 = an-2 + 3 ∙ 2
= (an-3 + 3 )+ 3 ∙ 2 = an-3 + 3 ∙ 3
.
.
.
Later we
will prove
some of
these by
induction.
Proof in text
(requires calculus)
Chapter 10
Chapter 10
Chapter Summary
Graphs and Graph Models
Graph Terminology and Special Types of Graphs
Representing Graphs and Graph Isomorphism
Connectivity
Euler and Hamiltonian Graphs
Shortest-Path Problems
Planar Graphs
Graph Coloring
Section 10.1
Section Summary
Introduction to Graphs
Graph Taxonomy
Graph Models
Chapter 10 Graphs
Definition: A graph G = (V, E) consists of a
nonempty set V of vertices (or nodes) and a set E of
edges. Each edge has either one or two vertices
associated with it, called its endpoints. An edge is
said to connect its endpoints.
Basic Types of GRAPH
• Simple Graph
• Multi Graph
• Pseudo Graph
• Null Graph
• Complete Graph
• Regular Graph
Some Terminology
In a simple graph each edge connects two different vertices and no two
edges connect the same pair of vertices.
Multigraphs may have multiple edges connecting the same two vertices.
When m different edges connect the vertices u and v, we say that {u,v} is
an edge of multiplicity m.
An edge that connects a vertex to itself is called a loop.
A pseudograph may include loops, as well as multiple edges connecting
the same pair of vertices.
Remark:
Graphs where the end points of an edge are not
ordered are said to be undirected graphs.
Some Terminology (continued)
Example:
In this directed multigraph the a b
multiplicity of (a,b) is 1 and the
multiplicity of (b,c) is 2.
c
Graph Terminology: Summary
Solution:
G: deg(a) = 2, deg(b) = deg(c) = deg(f ) = 4, deg(d ) = 1, deg(e) = 3, deg(g) = 0.
N(a) = {b, f }, N(b) = {a, c, e, f }, N(c) = {b, d, e, f }, N(d) = {c},
N(e) = {b, c , f }, N(f) = {a, b, c, e}, N(g) = .
H: deg(a) = 4, deg(b) = deg(e) = 6, deg(c) = 1, deg(d) = 5.
N(a) = {b, d, e}, N(b) = {a, b, c, d, e}, N(c) = {b}, N(d) = {a, b, e},
N(e) = {a, b ,d}.
Handshaking Theorem
Theorem: If G is any graph, then the sum of the degrees of all the
vertices of G equals twice the number of edges of G.
Specifically, if the vertices of G are v1, v2, …, vn, where n is a positive
integer, then
the total degree of G = deg(v1) + deg(v2) + … + deg(vn)
= 2 . (the number of edges of G)
PROOF:
Each edge “e” of G connects its end points vi and vj. This edge,
therefore contributes 1 to the degree of vi and 1 to the degree of vj.
If “e” is a loop, then it is counted twice in computing the degree of
the vertex on which it is incident.
Accordingly, each edge of G contributes 2 to the total degree of G.
Thus, the total degree of G = 2. (the number of edges of G)
COROLLARY: The total degree of G is an even number
Degree of Vertices
Theorem: An undirected graph has an even number of
vertices of odd degree.
Proof: Let V1 be the vertices of even degree and V2 be the
vertices of odd degree in an undirected graph G = (V, E)
with m edges. Then
even
must be even since deg(v) is This sum must be even because 2m is even and
even for each v ∈ V1 the sum of the degrees of the vertices of even
degrees is also even. Because this is the sum of
the degrees of all vertices of odd degree in the
graph, there must be an even number of such
vertices.
Handshaking Theorem
We now give two examples illustrating the usefulness of the
handshaking theorem.
Example: How many edges are there in a graph with 10
vertices of degree six?
Solution: Because the sum of the degrees of the vertices is
6 10 = 60, the handshaking theorem tells us that 2m = 60.
So the number of edges m = 30.
Example:
Representation of Graphs:
Adjacency Matrices
Definition: Suppose that G = (V, E) is a simple graph
where |V| = n. Arbitrarily list the vertices of G as
v1, v2, … , vn. The adjacency matrix AG of G, with
respect to the listing of vertices, is the n × n zero-one
matrix with 1 as its (i, j)th entry when vi and vj are
adjacent, and 0 as its (i, j)th entry when they are not
adjacent.
In other words, if the graphs adjacency matrix is
AG = [aij], then
Adjacency Matrices (continued)
Example: When a graph is sparse,
that is, it has few edges
relatively to the total
number of possible edges,
The ordering
it is much more efficient
of vertices is
a, b, c, d. to represent the graph
using an adjacency list
than an adjacency matrix.
But for a dense graph,
The ordering
which includes a high
of vertices is
a, b, c, d. percentage of possible
edges, an adjacency
matrix is preferable.
Note: The adjacency matrix of a simple graph is symmetric, i.e., aij = aji
Also, since there are no loops, each diagonal entry aij for i = 1, 2, 3, …, n, is 0.
Adjacency Matrices (continued)
Adjacency matrices can also be used to represent graphs with
loops and multiple edges.
A loop at the vertex vi is represented by a 1 at the (i, j)th
position of the matrix.
When multiple edges connect the same pair of vertices vi and
vj, (or if multiple loops are present at the same vertex), the (i,
j)th entry equals the number of edges connecting the pair of
vertices.
Example: We give the adjacency matrix of the pseudograph
shown here using the ordering of vertices a, b, c, d.
Adjacency Matrices (continued)
Adjacency matrices can also be used to represent
directed graphs. The matrix for a directed graph G =
(V, E) has a 1 in its (i, j)th position if there is an edge
from vi to vj, where v1, v2, … vn is a list of the vertices.
In other words, if the graphs adjacency matrix is AG = [aij], then
Multigraph
Model of the
Bridges of
Kӧnigsberg
The 7 Bridges of Kӧnigsberg
Euler Paths and Circuits
Definition: An Euler circuit in a graph G is a simple circuit containing
every edge of G. An Euler path in G is a simple path containing every
edge of G.
Example: Which of the undirected graphs G1, G2, and G3 has a Euler
circuit? Of those that do not, which has an Euler path?
Solution: The graph G1 has an Euler circuit (e.g., a, e, c, d, e, b, a). But, as can
easily be verified by inspection, neither G2 nor G3 has an Euler circuit. Note
that G3 has an Euler path (e.g., a, c, d, e, b, d, a, b), but there is no Euler path
in G2, which can be verified by inspection.
Necessary Conditions for Euler Circuits and Paths
An Euler circuit begins with a vertex a and continues with an edge
incident with a, say {a, b}. The edge {a, b} contributes one to
deg(a).
Each time the circuit passes through a vertex it contributes two to
the vertex’s degree.
Finally, the circuit terminates where it started, contributing one to
deg(a). Therefore deg(a) must be even.
We conclude that the degree of every other vertex must also be
even.
By the same reasoning, we see that the initial vertex and the final
vertex of an Euler path have odd degree, while every other vertex
has even degree. So, a graph with an Euler path has exactly two
vertices of odd degree.
In the next slide we will show that these necessary conditions are
also sufficient conditions.
Sufficient Conditions for Euler Circuits and Paths
Suppose that G is a connected multigraph with ≥ 2 vertices, all of even
degree. Let x0 = a be a vertex of even degree. Choose an edge {x0, x1}
incident with a and proceed to build a simple path {x0, x1}, {x1, x2}, …, {xn-1,
xn} by adding edges one by one until another edge can not be added.
Because G is connected, H must have at least one vertex in common with the circuit that has been deleted.
Every vertex in H must have even degree because all the vertices in G have even degree and for
each vertex, pairs of edges incident with this vertex have been deleted. Beginning with the
shared vertex construct a path ending in the same vertex (as was done before). Then splice this
new circuit into the original circuit.
In the example, we end up with the circuit a, f, c, d, e, c, b, a.
Continue this process until all edges have been used. This produces an Euler circuit. Since every edge
is included and no edge is included more than once.
Similar reasoning can be used to show that a graph with exactly two vertices of odd degree must have
an Euler path connecting these two vertices of odd degree
Algorithm for Constructing an
Euler Circuits
In our proof we developed this algorithms for
constructing a Euler circuit in a graph with no vertices of
odd degree.
procedure Euler(G: connected multigraph with all vertices of even degree)
circuit := a circuit in G beginning at an arbitrarily chosen vertex with edges
successively added to form a path that returns to this vertex.
H := G with the edges of this circuit removed
while H has edges
subciruit := a circuit in H beginning at a vertex in H that also is
an endpoint of an edge in circuit.
H := H with edges of subciruit and all isolated vertices removed
circuit := circuit with subcircuit inserted at the appropriate vertex.
return circuit{circuit is an Euler circuit}
Necessary and Sufficient Conditions for
Euler Circuits and Paths (continued)
Theorem: A connected multigraph with at least two vertices
has an Euler circuit if and only if each of its vertices has an
even degree and it has an Euler path if and only if it has
exactly two vertices of odd degree.
G1 contains exactly two vertices of odd degree (b and d). Hence it has
an Euler path, e.g., d, a, b, c, d, b.
G2 has exactly two vertices of odd degree (b and d). Hence it has an
Euler path, e.g., b, a, g, f, e, d, c, g, b, c, f, d.
G3 has six vertices of odd degree. Hence, it does not have an Euler path.
Applications of Euler Paths and
Circuits
Euler paths and circuits can be used to solve many practical
problems such as finding a path or circuit that traverses
each
street in a neighborhood,
road in a transportation network,
connection in a utility grid,
link in a communications network.
Other applications are found in the
layout of circuits,
network multicasting,
molecular biology, where Euler paths are used in the
sequencing of DNA.
William Rowan
Hamilton
Hamilton Paths and Circuits (1805- 1865)
That is, a simple 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, and the simple circuit x0, x1, …, xn-1, xn,
x0 (with n > 0) is a Hamilton circuit if x0, x1, … , xn-
1, xn is a Hamilton path.
Hamilton Paths and Circuits
Example: Which of these simple graphs has a
Hamilton circuit or, if not, a Hamilton path?
Solution:
G1 does not have a Hamilton circuit (Why?), but does
have a Hamilton path : a, b ,e , c, d.
G2 has a Hamilton circuit: a, b, c, d, e, a.
G3 has a Hamilton circuit: a,b,e,d,c,a
Necessary Conditions for
Hamilton Circuits Gabriel Andrew Dirac
(1925-1984)
Unlike for an Euler circuit, no simple necessary and sufficient
conditions are known for the existence of a Hamiton circuit.
However, there are some useful necessary conditions. We
describe two of these now.
Dirac’s Theorem: If G is a simple graph with n ≥ 3 vertices such
that the degree of every vertex in G is ≥ n/2, then G has a
Hamilton circuit.
SOLUTION:
As both the graphs have the same number of vertices. But the
graph G has 7 edges and the graph G’ has only 6 edges. Therefore
the two graphs are not isomorphic.
Note: As the edges of both the graphs G and G’ are not same
then how the one-one correspondence is possible ,that the
reason the graphs G and G’ are not isomorphic.
Isomorphism of Graphs
EXAMPLE: Determine whether the graph G and G’ given
below are isomorphic.
SOLUTION:
Both the graphs have 5 vertices and 7 edges. The vertex q
of G’ has degree 5. However G does not have any vertex of
degree 5 (so one-one correspondence is not possible).
Hence, the two graphs are not isomorphic.
Isomorphism of Graphs
EXAMPLE: Determine whether the graph G and G’ given below
are isomorphic.
SOLUTION:
Clearly the vertices of both the graphs G and G’ have the same
degree (i.e “2”) and having the same number of vertices and
edges but isomorphism is not possible. As the graph G’ is a
connected graph but the graph G is not connected due to have
two components (eca and bdf ). Therefore the two graphs are non
isomorphic.
Isomorphism of Graphs
EXAMPLE: Determine whether the graph G and G’ given below
are isomorphic.
SOLUTION:
Clearly G has six vertices, G’ also has six vertices. And the graph G
has two simple circuits of length 3; one is abca and the other is
defd. But G’ does not have any simple circuit of length 3(as one
simple circuit in G’ is uxwvu of length 4).Therefore the two graphs
are non-isomorphic.
Note: A simple circuit is a circuit that does not have any other
repeated vertex except the first and last.
Isomorphism of Graphs
EXAMPLE: Determine whether the graph G and G’ given below
are isomorphic.
SOLUTION:
Both the graph G and G’ have 8 vertices and 12 edges and both are
also called regular graph(as each vertex has degree 3).The graph G
has two simple circuits of length 5; abcfea(i.e starts and ends at a)
and cdhgfc(i.e starts and ends at c). But G’ does not have any
simple circuit of length 5 (it has simple circuit tyxut,vwxuv of
length 4 etc). Therefore the two graphs are non-isomorphic.
Isomorphism of Graphs
EXAMPLE: Determine whether the given
graph G and H are isomorphic.
Solution:
Solution: The function f with
f(a) = u, f(b) = v, f(c) = y, f(d) = x, f(e) = w and
f(f) = z is a one-to-one correspondence
between G and H.
Note that adjacent vertices in G are a and b, b
and c, c and d, c and f, d and e, e and f and f
and a.
Each of the pairs f(a) = u and f(b) = v, f(b) = v
and f(c) = y , f(c) = y and f(d) = x , f(c) = y and
f(f) = z , f(d) = x and f(e) = w, f(e) = w and f(f)
= z and f(f) = z and f(a) = u consists of two
adjacent vertices in H.
Isomorphism of Graphs (cont.)
Example: Determine whether these two graphs are isomorphic.
They also both have four vertices of degree two and two of degree three.
The subgraphs of G and H consisting of all the vertices of degree two and the
edges connecting them are isomorphic. So, it is reasonable to try to find an
isomorphism f.
The function f with f(u1) = v6, f(u2) = v3, f(u3) = v4, and f(u4) = v5 , f(u5) = v1,
and f(u6) = v2 is a one-to-one correspondence between G and H. Showing
that this correspondence preserves edges is straightforward, so we will omit
the details here. Because f is an isomorphism, it follows that G and H are
isomorphic graphs.
Algorithms for Graph Isomorphism
The best algorithms known for determining whether two
graphs are isomorphic have exponential worst-case time
complexity (in the number of vertices of the graphs).
However, there are algorithms with linear average-case
time complexity.
You can use a public domain program called NAUTY to
determine in less than a second whether two graphs with as
many as 100 vertices are isomoprhic.
Graph isomorphism is a problem of special interest
because it is one of a few NP problems not known to be
either tractable or NP-complete (see Section 3.3).
Applications of Graph Isomorphism
The question whether graphs are isomorphic plays an
important role in applications of graph theory. For example,
chemists use molecular graphs to model chemical compounds.
Vertices represent atoms and edges represent chemical bonds.
When a new compound is synthesized, a database of molecular
graphs is checked to determine whether the graph representing
the new compound is isomorphic to the graph of a compound that
this already known.
Electronic circuits are modeled as graphs in which the vertices
represent components and the edges represent connections
between them. Graph isomorphism is the basis for
the verification that a particular layout of a circuit corresponds
to the design’s original schematics.
determining whether a chip from one vendor includes the
intellectual property of another vendor.
Shortest Paths
Weighted Graphs
Graphs that have a number assigned to
each edge are called weighted graphs. BOS
CHI NY
SF DEN
ATL
LA
MIA
Weighted Graphs
MILES
BOS
2534
1855 722 NY
CHI
SF DEN 908
957
349
ATL
LA 595
MIA
Weighted Graphs
FARES
BOS
$129
$39
$99 $59 NY
CHI
SF DEN
$89
$39
ATL
LA
MIA
Weighted Graphs
FLIGHT
TIMES
BOS
4:05
0:50
2:55 NY
CHI 1:50
SF DEN 2:10
2:20
1:15
ATL
LA
MIA
Weighted Graphs
A weighted graph is a graph in which each edge (u,
v) has a weight w(u, v). Each weight is a real number.
Weights can represent distance, cost, time, capacity,
etc.
The length of a path in a weighted graph is the sum
of the weights on the edges.
Dijkstra’s Algorithm finds the shortest path between
two vertices.
Dijkstra’s Algorithm
Dijkstra’s algorithm is used in problems relating to finding the shortest path.
Each node is given a temporary label denoting the length of the shortest
path from the start node so far.
Once it is certain that no other shorter paths can be found, the temporary
label becomes a permanent label.
At this point the shortest path is found by retracing the path backwards.
Dijkstra’s algorithm: example
D(v) D(w) D(x) D(y) D(z)
Step N'
0 u 7,u 3,u 5,u ∞ ∞
1 uw 6,w 5,u 11,w ∞
2 uwx 6,w 11,w 14,x
3 uwxv 10,v 14,x
4 uwxvy 12,y
5 uwxvyz x
9
notes: 5
4
7
construct shortest path tree by
8
tracing predecessor nodes
ties can exist (can be broken 3 w z
u y
arbitrarily) 2
3
7 4
v
Dijkstra’s algorithm: another example
Step N' D(v) D(w) D(x) D(y) D(z)
0 u 2,u 5,u 1,u ∞ ∞
1 ux 2,u 4,x 2,x ∞
2 uxy 2,u 3,y 4,y
3 uxyv 3,y 4,y
4 uxyvw 4,y
5 uxyvwz
5
v 3 w
2 5
u 2 1 z
3
1 2
x 1
y
Problem: shortest path from a to z
b 5 d 5 f
4 7
4 3 1
a 2 z
3 4
c 5 e 5 g
The Traveling Salesman Problem
K3,3
Planar Graphs
A graph is called planar if it can be drawn
in the plane without any edges crossing.
A crossing of edges is the intersection of the
lines or arcs representing them at a point
other than their common endpoint.
Such a drawing is called a planar
representation of the graph.
Example
A graph may be planar even if it is usually
drawn with crossings, since it may be
possible to draw it in another way without
crossings.
Example
A graph may be planar even if it represents a
3-dimensional object.
Planar Graphs
We can prove that a particular graph is
planar by showing how it can be drawn
without any crossings.
However, not all graphs are planar.
It may be difficult to show that a graph is
nonplanar. We would have to show that
there is no way to draw the graph without
any edges crossing.
Regions
Euler showed that all planar representations
of a graph split the plane into the same
number of regions, including an unbounded
region.
R4 R3 R2
R1
Regions
In any planar representation of K3,3, vertex
v1 must be connected to both v4 and v5, and
v2 also must be connected to both v4 and v5.
v1 v2 v3
v4 v5 v6
Regions
The four edges {v1, v4}, {v4, v2}, {v2, v5},
{v5, v1} form a closed curve that splits the
plane into two regions, R1 and R2.
v1 v5
R2 R1
v4 v2
Regions
Next, we note that v3 must be in either R1 or R2.
Assume v3 is in R2. Then the edges {v3, v4} and {v4, v5}
separate R2 into two subregions, R21 and R22.
v1 v5 v1 v5
R21
R2 R1 → v3
R22
v4 v2 v4 v2
Regions
Now there is no way to place vertex v6
without forcing a crossing:
If v6 is in R1 then {v6, v3} must cross an edge
If v6 is in R21 then {v6, v2} must cross an edge
If v6 is in R22 then {v6, v1} must cross an edge
v1 v5
R21
v3 R1
R22
v4 v2
Regions
Alternatively, assume v3 is in R1. Then the
edges {v3, v4} and {v4, v5} separate R1 into
two subregions, R11 and R12.
v1 v5
R11
R2 R12 v3
v4 v2
Regions
Now there is no way to place vertex v6 without forcing a
crossing:
If v6 is in R2 then {v6, v3} must cross an edge
If v6 is in R11 then {v6, v2} must cross an edge
If v6 is in R12 then {v6, v1} must cross an edge
v1 v5
R11
R2 R12 v3
v4 v2
Planar Graphs
Consequently, the graph K3,3 must be
nonplanar.
K3,3
Regions
Euler devised a formula for expressing the
relationship between the number of vertices,
edges, and regions of a planar graph.
These may help us determine if a graph can
be planar or not.
Euler’s Formula
Let G be a connected planar simple graph
with e edges and v vertices. Let r be the
number of regions in a planar
representation of G. Then r = e - v + 2.
R4 R3 R2
# of edges, e = 6
R1 # of vertices, v = 4
# of regions, r = e - v + 2 = 4
Euler’s Formula (Cont.)
Corollary 1: If G is a connected planar
simple graph with e edges and v vertices
where v 3, then e 3v - 6.
Is K5 planar?
K5
Euler’s Formula (Cont.)
K5 has 5 vertices and 10 edges.
We see that v 3.
So, if K5 is planar, it must be true that e 3v – 6.
3v – 6 = 3*5 – 6 = 15 – 6 = 9.
So e must be 9.
But e = 10.
So, K5 is nonplanar.
K5
Euler’s Formula (Cont.)
Corollary 2: If G is a connected planar
simple graph, then G must have a vertex of
degree not exceeding 5.
If G has one or two vertices, it is true;
thus, we assume that G has at least three vertices.
K3,3
Chapter 11
Chapter Summary
Introduction to Trees
Applications of Trees
Tree Traversal
Spanning Trees
Minimum Spanning
Section 11.1
Section Summary
Introduction to Trees
Rooted Trees
Trees as Models
Properties of Trees
Trees
Definition: A tree is a connected undirected graph with no
simple circuits.
Solution:
(i) The parent of c is b. The
children of g are h, i, and j.
The siblings of h are i and j.
The ancestors of e are c, b,
and a. The descendants of
b are c, d, and e.
Terminology for Rooted Trees
Example: In the rooted
tree T (with root a):
(i) Find all internal
vertices and all leaves.
Solution:
(i) The internal vertices
are a, b, c, g, h, and j.
The leaves are d, e, f, i,
k, l, and m.
Terminology for Rooted Trees
(i) What is the subtree
rooted at g?
Solution:
(i) We display the subtree
rooted at g.
Level of vertices and height of trees
When working with trees, we often want to have rooted
trees where the sub trees at each vertex contain paths of
approximately the same length.
To make this idea precise we need some definitions:
The level of a vertex v in a rooted tree is the length of the
unique path from the root to this vertex.
The height of a rooted tree is the maximum of the levels of
the vertices.
Level of vertices and height of trees
Example:
(i) Find the level of each vertex in
the tree to the right.
(ii) What is the height of the tree?
Solution:
(i) The root a is at level 0.
Vertices b, j, and k are at level 1.
Vertices c, e, f, and l are at level 2.
Vertices d, g, i, m, and n are at level 3.
Vertex h is at level 4.
procedure preorder
(T: ordered rooted
tree)
r := root of T
list r
for each child c of r
from left to right
T(c) := subtree with
c as root
preorder(T(c))
Inorder Traversal
Definition: Let T be an ordered rooted tree with root r. If
T consists only of r, then r is the inorder traversal of T.
Otherwise, suppose that T1, T2, …, Tn are the subtrees of r
from left to right in T. The inorder traversal begins by
traversing T1 in inorder, then visiting r, and continues by
traversing T2 in inorder, and so on, until Tn is traversed in
inorder.
Inorder Traversal (continued)
procedure
inorder (T: ordered
rooted tree)
r := root of T
if r is a leaf then list r
else
l := first child of r
from left to right
T(l) := subtree with l
as its root
inorder(T(l))
list(r)
for each child c of r
from left to right
T(c) := subtree
with c as root
inorder(T(c))
Postorder Traversal
Definition: Let T be an ordered rooted tree with root r. If
T consists only of r, then r is the postorder traversal of T.
Otherwise, suppose that T1, T2, …, Tn are the subtrees of r
from left to right in T. The postorder traversal begins by
traversing T1 in postorder, then T2 in postorder, and so on,
after Tn is traversed in postorder, r is visited.
Post order Traversal (continued)
procedure
postordered (T:
ordered rooted
tree)
r := root of T
for each child c of
r from left to right
T(c) := subtree
with c as root
postorder(T(c))
list r
Expression Trees
Complex expressions can be represented using ordered
rooted trees.
Consider the expression ((x + y) ↑ 2 ) + ((x − 4)/3).
A binary tree for the expression can be built from the
bottom up, as is illustrated here.
Infix Notation
An inorder traversal of the tree representing an expression produces
the original expression when parentheses are included except for unary
operations, which now immediately follow their operands.
We illustrate why parentheses are needed with an example that
displays three trees all yield the same infix representation.
Jan Łukasiewicz
(1878-1956)
Prefix Notation
When we traverse the rooted tree representation of an
expression in preorder, we obtain the prefix form of the
expression. Expressions in prefix form are said to be in Polish
notation, named after the Polish logician Jan Łukasiewicz.
Operators precede their operands in the prefix form of an
expression. Parentheses are not needed as the representation is
unambiguous.
The prefix form of ((x + y) ↑ 2 ) + ((x − 4)/3)
is + ↑ + x y 2 / − x 4 3.
Prefix expressions are evaluated by working from right to left.
When we encounter an operator, we perform the corresponding
operation with the two operations to the right.
Prefix Notation
Example: We show the steps used to evaluate a
particular prefix expression:
Postfix Notation
We obtain the postfix form of an expression by traversing its
binary trees in postorder. Expressions written in postfix
form are said to be in reverse Polish notation.
Parentheses are not needed as the postfix form is
unambiguous.
x y + 2 ↑ x 4 − 3 / + is the postfix form of ((x + y) ↑ 2 ) + ((x
− 4)/3).
A binary operator follows its two operands. So, to evaluate
an expression one works from left to right, carrying out an
operation represented by an operator on its preceding
operands.
Postfix Notation
Example: We show the steps used to evaluate a
particular postfix expression.
Section 11.4
Section Summary
Spanning Trees
Prim’s Algorithm
Kruskal Algorithm
Spanning Trees
Definition: Let G be a simple graph. A spanning tree of G is a
subgraph of G that is a tree containing every vertex of G.
MST COST = 23
KRUSKAL’S ALGORITHM
Minimal spanning tree (MST)
Example: Use Kruskal’s
algorithm to find a minimal
spanning tree for the graph
below. Indicate the order in
which edges are added to
form the tree.
MST COST = 23
Activity Time
Minimal spanning tree (MST)
Find the minimum spanning tree of the graph given
below using Prims and Kruskal's Algorithm.