View
26
Download
0
Category
Preview:
Citation preview
Gazi Zahirul Islam, Assistant Professor, Department of CSE, Daffodil International University, Dhaka 1
Relations:
DEFINITION 1:
Let A and B be sets. A binary relation from A to B is a subset of A × B.
Example 1:
Let A = {0, 1, 2} and B = {a, b}. Then {(0, a), (0, b), (1, a), (2, b)} is a relation from A to B. This means,
for instance, that 0 R a, but that 1 b. Relations can be represented graphically, as shown in Figure
1, using arrows to represent ordered pairs. Another way to represent this relation is to use a table,
which is also done in Figure 1.
Figure 1: Displaying the Ordered Pairs in the Relation R from Example 1.
Example 2:
Let A be the set {1, 2, 3, 4}. Which ordered pairs are in the relation R = {(a, b) | a divides b}?
Solution:
Because (a, b) is in R if and only if a and b are positive integers not exceeding 4 such that a divides b,
we see that
R = {(1, 1), (1, 2), (1, 3), (1, 4), (2, 2), (2, 4), (3, 3), (4, 4)}.
The pairs in this relation are displayed both graphically and in tabular form in Figure 2.
Gazi Zahirul Islam, Assistant Professor, Department of CSE, Daffodil International University, Dhaka 2
Figure 2: Displaying the Ordered Pairs in the Relation R from Example 2:
Example 3:
Consider these relations on the set of integers:
R1 = {(a, b) | a ≤ b},
R2 = {(a, b) | a > b},
R3 = {(a, b) | a = b or a = −b},
R4 = {(a, b) | a = b},
R5 = {(a, b) | a = b + 1},
R6 = {(a, b) | a + b ≤ 3}.
Which of these relations contain each of the pairs (1, 1), (1, 2), (2, 1), (1,−1), and (2, 2)?
Solution:
The pair (1, 1) is in R1, R3, R4, and R6; (1, 2) is in R1 and R6; (2, 1) is in R2, R5, and R6; (1,−1) is in R2,
R3, and R6; and finally, (2, 2) is in R1, R3, and R4.
DEFINITION 2:
A relation R on a set A is called reflexive if (a, a) ∈ R for every element a ∈ A.
Example 4:
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)},
Gazi Zahirul Islam, Assistant Professor, Department of CSE, Daffodil International University, Dhaka 3
R6 = {(3, 4)}.
Which of these relations are reflexive?
Solution:
The relations R3 and R5 are reflexive because they both contain all pairs of the form (a, a), namely,
(1, 1), (2, 2), (3, 3), and (4, 4). The other relations are not reflexive because they do not contain all of
these ordered pairs. In particular, R1, R2, R4, and R6 are not reflexive because (3, 3) is not in any of
these relations.
DEFINITION 3:
A relation R on a set A is called symmetric if (b, a) ∈ R whenever (a, b) ∈ R, for all a, b ∈ A. 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.
Example 5:
Which of the relations from Example 4 are symmetric and which are antisymmetric?
Solution:
The relations R2 and R3 are symmetric, because in each case (b, a) belongs to the relation whenever
(a, b) does. For R2, the only thing to check is that both (2, 1) and (1, 2) are in the relation. For R3, it is
necessary to check that both (1, 2) and (2, 1) belong to the relation, and (1, 4) and (4, 1) belong to
the relation. The reader should verify that none of the other relations is symmetric. This is done by
finding a pair (a, b) such that it is in the relation but (b, a) is not.
R4, R5, and R6 are all antisymmetric. For each of these relations there is no pair of elements a and b
with a ≠ b such that both (a, b) and (b, a) belong to the relation. The reader should verify that none
of the other relations is antisymmetric. This is done by finding a pair (a, b) with a ≠ b such that (a, b)
and (b, a) are both in the relation.
DEFINITION 4:
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.
Example 6:
Which of the relations in Example 4 are transitive?
Solution:
R4, R5, and R6 are transitive. For each of these relations, we can show that it is transitive by verifying
that if (a, b) and (b, c) belong to this relation, then (a, c) also does. For instance, R4 is transitive,
because (3, 2) and (2, 1), (4, 2) and (2, 1), (4, 3) and (3, 1), and (4, 3) and (3, 2) are the only such sets
of pairs, and (3, 1), (4, 1), and (4, 2) belong to R4. The reader should verify that R5 and R6 are
transitive.
Gazi Zahirul Islam, Assistant Professor, Department of CSE, Daffodil International University, Dhaka 4
R1 is not transitive because (3, 4) and (4, 1) belong to R1, but (3, 1) does not. R2 is not transitive
because (2, 1) and (1, 2) belong to R2, but (2, 2) does not. R3 is not transitive because (4, 1) and (1,
2) belong to R3, but (4, 2) does not.
Gazi Zahirul Islam, Assistant Professor, Department of CSE, Daffodil International University, Dhaka 5
Graphs:
DEFINITION 1:
A graph G = (V,E) consists of V, a nonempty set of vertices (or nodes) and E, a set of edges. Each
edge has either one or two vertices associated with it, called its endpoints. An edge is said to
connect its endpoints.
Simple graph:
A graph in which each edge connects two different vertices and where no two edges connect the
same pair of vertices is called a simple graph. Figure 1 shows a simple graph.
Figure 1: A computer network which is an example of simple graph
Multigraphs:
Graphs that may have multiple edges connecting the same vertices are called multigraphs. Figure 2
shows a Multigraph.
Figure 2: A computer network forms a multigraph
Pseudographs:
Graphs that may include loops are called pseudographs. Figure 3 shows a pseudograph.
Gazi Zahirul Islam, Assistant Professor, Department of CSE, Daffodil International University, Dhaka 6
Figure 3: A computer network forms a pseudograph
DEFINITION 2:
A directed graph (or digraph) (V ,E) consists of a nonempty set of vertices V and a set of directed
edges (or arcs) E. Each directed edge is associated with an ordered pair of vertices. The directed
edge associated with the ordered pair (u, v) is said to start at u and end at v. Figure 4 shows a simple
directed graph.
Figure 4: A communication network forms a simple directed graph
Directed Multigraph:
Directed graph that have multiple directed edges are called directed multigraph. Figure 5 shows a
directed multigraph.
Figure 5: A computer network forms a directed multigraph
Gazi Zahirul Islam, Assistant Professor, Department of CSE, Daffodil International University, Dhaka 7
Graph Overview:
Gazi Zahirul Islam, Assistant Professor, Department of CSE, Daffodil International University, Dhaka 8
Graph Terminology:
DEFINITION 1:
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).
EXAMPLE 1:
What are the degrees of the vertices in the graphs G and H displayed in Figure 1?
Solution:
In G, deg(a) = 2, deg(b) = deg(c) = deg(f ) = 4, deg(d ) = 1, deg(e) = 3, and deg(g) = 0.
In H, deg(a) = 4, deg(b) = deg(e) = 6, deg(c) = 1, and deg(d ) = 5.
A vertex of degree zero is called isolated. Vertex g in graph G in Example 1 is isolated.
A vertex is pendant if and only if it has degree one. Vertex d in graph G in Example 1 is pendant.
THEOREM 1: THE HANDSHAKING THEOREM
Let G = (V ,E) be an undirected graph with m edges. Then
EXAMPLE 2:
How many edges are there in a graph with 10 vertices each of degree six?
Solution:
Gazi Zahirul Islam, Assistant Professor, Department of CSE, Daffodil International University, Dhaka 9
Because the sum of the degrees of the vertices is 6 × 10 = 60, it follows that 2m = 60 where m is the
number of edges. Therefore, m = 30.
DEFINITION 2:
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.
EXAMPLE 3:
Find the in-degree and out-degree of each vertex in the graph G with directed edges shown in Figure
2.
Figure 2: The directed graph G
Solution:
The in-degrees in G are: deg− (a) = 2, deg− (b) = 2, deg− (c) = 3, deg− (d) = 2, deg− (e) = 3, and deg−
(f) = 0.
The out-degrees are deg+ (a) = 4, deg+ (b) = 1, deg+ (c) = 2, deg+ (d) = 2, deg+ (e) = 3, and deg+ (f ) =
0.
THEOREM 2:
Let G = (V ,E) be a graph with directed edges. Then
Some special simple graphs:
Complete Graphs:
A complete graph on n vertices, denoted by Kn, is a simple graph that contains exactly one edge
between each pair of distinct vertices. The graphs Kn, for n = 1, 2, 3, 4, 5, 6, are displayed in Figure 3.
Gazi Zahirul Islam, Assistant Professor, Department of CSE, Daffodil International University, Dhaka 10
Figure 3: The Graphs Kn for 1 ≤ n ≤ 6
Cycles:
A cycle Cn, n ≥ 3, consists of n vertices v1, v2, . . . , vn and edges {v1, v2}, {v2, v3}, . . . , {vn−1, vn}, and
{vn, v1}. The cycles C3, C4, C5, and C6 are displayed in Figure 4.
FIGURE 4: The Cycles C3, C4, C5, and C6
Wheels:
We obtain a wheel Wn when we add an additional vertex to a cycle Cn, for n ≥ 3, and connect this
new vertex to each of the n vertices in Cn, by new edges. The wheels W3, W4, W5, and W6 are
displayed in Figure 5.
FIGURE 5: The Wheels W3, W4, W5, and W6
DEFINITION 3:
A simple graph G is called bipartite if its vertex set V can be partitioned into two disjoint sets V1 and
V2 such that every edge in the graph connects a vertex in V1 and a vertex in V2.
EXAMPLE 4:
Gazi Zahirul Islam, Assistant Professor, Department of CSE, Daffodil International University, Dhaka 11
C6 is bipartite, as shown in Figure 6, because its vertex set can be partitioned into the two sets V1 =
{v1, v3, v5} and V2 = {v2, v4, v6}, and every edge of C6 connects a vertex in V1 and a vertex in V2.
FIGURE 6: Showing that C6 is bipartite
EXAMPLE 5:
Are the graphs G and H displayed in Figure 7 bipartite?
FIGURE 7: The Undirected Graphs G and H
Solution:
Graph G is bipartite because its vertex set is the union of two disjoint sets, {a, b, d} and {c, e, f, g},
and each edge connects a vertex in one of these subsets to a vertex in the other subset.
Graph H is not bipartite because its vertex set cannot be partitioned into two subsets so that edges
do not connect two vertices from the same subset.
Complete Bipartite Graphs:
A complete bipartite graph Km,n is a graph that has its vertex set partitioned into two subsets of m
and n vertices, respectively with an edge between two vertices if and only if one vertex is in the first
subset and the other vertex is in the second subset. The complete bipartite graphs K2,3, K3,3, K3,5,
and K2,6 are displayed in Figure 8.
Gazi Zahirul Islam, Assistant Professor, Department of CSE, Daffodil International University, Dhaka 12
Figure 8: Some Complete Bipartite Graphs
Gazi Zahirul Islam, Assistant Professor, Department of CSE, Daffodil International University, Dhaka 13
Representing Graphs:
There are two methods to represent graphs:
a. Adjacency list
b. Adjacency matrix
Example 1:
Use adjacency lists to describe the simple graph given in Figure 1.
Solution:
Table 1 lists those vertices adjacent to each of the vertices of the graph.
Example 2:
Use adjacency lists to describe the directed graph given in Figure 2.
Solution:
Table 2 represents the directed graph shown in Figure 2.
Example 3:
Use an adjacency matrix to represent the graph shown in Figure 3.
Gazi Zahirul Islam, Assistant Professor, Department of CSE, Daffodil International University, Dhaka 14
Figure 3: Simple Graph
Solution:
We order the vertices as a, b, c, d. The matrix representing this graph is
Example 4:
Draw a graph with the adjacency matrix
with respect to the ordering of vertices a, b, c, d.
Solution:
A graph with this adjacency matrix is shown in Figure 4.
Figure 4: Adjacency matrix of example 4
Example 5:
Recommended