Skip to main content
Logo image

Applied Discrete Structures

Section 6.4 Matrices of Relations

We have discussed two of the many possible ways of representing a relation, namely as a digraph or as a set of ordered pairs. In this section we will discuss the representation of relations by matrices.

Subsection 6.4.1 Representing a Relation with a Matrix

Definition 6.4.1. Adjacency Matrix.

Let \(A = \{a_1,a_2,\ldots , a_m\}\) and \(B= \{b_1,b_2,\ldots , b_n\}\) be finite sets of cardinality \(m\) and \(n\text{,}\) respectively. Let \(r\) be a relation from \(A\) into \(B\text{.}\) Then \(r\) can be represented by the \(m\times n\) matrix \(R\) defined by
\begin{equation*} R_{ij}= \left\{ \begin{array}{cc} 1 & \textrm{ if } a_i r b_j \\ 0 & \textrm{ otherwise} \\ \end{array}\right. \end{equation*}
\(R\) is called the adjacency matrix (or the relation matrix) of \(r\text{.}\)
Let \(A = \{2, 5, 6\}\) and let \(r\) be the relation \(\{(2, 2), (2, 5), (5, 6), (6, 6)\}\) on \(A\text{.}\) Since \(r\) is a relation from \(A\) into the same set \(A\) (the \(B\) of the definition), we have \(a_1= 2\text{,}\) \(a_2=5\text{,}\) and \(a_3=6\text{,}\) while \(b_1= 2\text{,}\) \(b_2=5\text{,}\) and \(b_3=6\text{.}\) Next, since
  • \(2 r 2\text{,}\) we have \(R_{11}= 1\)
  • \(2 r 5\text{,}\) we have \(R_{12}= 1\)
  • \(5 r 6\text{,}\) we have \(R_{23}= 1\)
  • \(6 r 6\text{,}\) we have \(R_{33}= 1\)
All other entries of \(R\) are zero, so
\begin{equation*} R =\left( \begin{array}{ccc} 1 & 1 & 0 \\ 0 & 0 & 1 \\ 0 & 0 & 1 \\ \end{array} \right) \end{equation*}

Subsection 6.4.2 Composition as Matrix Multiplication

From the definition of \(r\) and of composition, we note that
\begin{equation*} r^2 = \{(2, 2), (2, 5), (2, 6), (5, 6), (6, 6)\} \end{equation*}
The adjacency matrix of \(r^2\) is
\begin{equation*} R^2 =\left( \begin{array}{ccc} 1 & 1 & 1 \\ 0 & 0 & 1 \\ 0 & 0 & 1 \\ \end{array} \right)\text{.} \end{equation*}
We do not write \(R^2\) only for notational purposes. In fact, \(R^2\) can be obtained from the matrix product \(R R\text{;}\) however, we must use a slightly different form of arithmetic.

Definition 6.4.3. Boolean Arithmetic.

Boolean arithmetic is the arithmetic defined on \(\{0,1\}\) using Boolean addition and Boolean multiplication, defined by
Table 6.4.4.
\(0 + 0 = 0\) \(0+1 = 1 + 0=1\) \(1 + 1 = 1\)
\(0\cdot 0=0\) \(0 \cdot 1 = 1 \cdot 0 = 0\) \(1 \cdot 1 = 1\)
Notice that from Chapter 3, this is the “arithmetic of logic,” where \(+\) replaces “or” and \(\cdot\) replaces “and.”
Suppose that \(R=\left( \begin{array}{cccc} 0 & 1 & 0 & 0 \\ 1 & 0 & 1 & 0 \\ 0 & 1 & 0 & 1 \\ 0 & 0 & 1 & 0 \\ \end{array} \right)\) and \(S=\left( \begin{array}{cccc} 0 & 1 & 1 & 1 \\ 0 & 0 & 1 & 1 \\ 0 & 0 & 0 & 1 \\ 0 & 0 & 0 & 0 \\ \end{array} \right)\text{.}\) Then using Boolean arithmetic, \(R S =\left( \begin{array}{cccc} 0 & 0 & 1 & 1 \\ 0 & 1 & 1 & 1 \\ 0 & 0 & 1 & 1 \\ 0 & 0 & 0 & 1 \\ \end{array} \right)\) and \(S R=\left( \begin{array}{cccc} 1 & 1 & 1 & 1 \\ 0 & 1 & 1 & 1 \\ 0 & 0 & 1 & 0 \\ 0 & 0 & 0 & 0 \\ \end{array} \right)\text{.}\)
Remark: A convenient help in constructing the adjacency matrix of a relation from a set \(A\) into a set \(B\) is to write the elements from \(A\) in a column preceding the first column of the adjacency matrix, and the elements of \(B\) in a row above the first row. Initially, \(R\) in Example 2 would be
\begin{equation*} \begin{array}{cc} & \begin{array}{ccc} 2 & 5 & 6 \\ \end{array} \\ \begin{array}{c} 2 \\ 5 \\ 6 \\ \end{array} & \left( \begin{array}{ccc} & & \\ & & \\ & & \\ \end{array} \right) \\ \end{array} \end{equation*}
To fill in the matrix, \(R_{ij}\) is 1 if and only if \(\left(a_i,b_j\right) \in r\text{.}\) So that, since the pair \((2, 5) \in r\text{,}\) the entry of \(R\) corresponding to the row labeled 2 and the column labeled 5 in the matrix is a 1.
This final example gives an insight into how relational data base programs can systematically answer questions pertaining to large masses of information. Matrices \(R\) (on the left) and \(S\) (on the right) define the relations \(r\) and \(s\) where \(a r b\) if software \(a\) can be run with operating system \(b\text{,}\) and \(b s c\) if operating system \(b\) can run on computer \(c\text{.}\)
\begin{equation*} \begin{array}{cc} \begin{array}{cc} & \begin{array}{cccc} \text{OS1} & \text{OS2} & \text{OS3} & \text{OS4} \end{array} \\ \begin{array}{c} \text{P1} \\ \text{P2} \\ \text{P3} \\ \text{P4} \end{array} & \left( \begin{array}{cccc} 1 & 0 & 1 & 0 \\ 1 & 1 & 0 & 0 \\ 0 & 0 & 0 & 1 \\ 0 & 0 & 1 & 1 \end{array} \right) \end{array} \begin{array}{cc} & \begin{array}{ccc} \text{C1} & \text{C2} & \text{C3} \end{array} \\ \begin{array}{c} \text{OS1} \\ \text{OS2} \\ \text{OS3} \\ \text{OS4} \\ \end{array} & \left( \begin{array}{ccc} 1 & 1 & 0 \\ 0 & 1 & 0 \\ 0 & 0 & 1 \\ 0 & 1 & 1 \end{array} \right) \end{array} \end{array} \end{equation*}
Although the relation between the software and computers is not implicit from the data given, we can easily compute this information. The matrix of \(rs\) is \(RS\text{,}\) which is
\begin{equation*} \begin{array}{cc} & \begin{array}{ccc} \text{C1} & \text{C2} & \text{C3} \end{array} \\ \begin{array}{c} \text{P1} \\ \text{P2} \\ \text{P3} \\ \text{P4} \end{array} & \left( \begin{array}{ccc} 1 & 1 & 1 \\ 1 & 1 & 0 \\ 0 & 1 & 1 \\ 0 & 1 & 1 \end{array} \right) \end{array} \end{equation*}
This matrix tells us at a glance which software will run on the computers listed. In this case, all software will run on all computers with the exception of program P2, which will not run on the computer C3, and programs P3 and P4, which will not run on the computer C1.

Exercises 6.4.3 Exercises

1.

Let \(A_1 = \{1,2, 3, 4\}\text{,}\) \(A_2 = \{4, 5, 6\}\text{,}\) and \(A_3 = \{6, 7, 8\}\text{.}\) Let \(r_1\) be the relation from \(A_1\) into \(A_2\) defined by \(r_1 = \{(x, y) \mid y - x = 2\}\text{,}\) and let \(r_2\) be the relation from \(A_2\) into \(A_3\) defined by \(r_2 = \{(x, y) \mid y - x = 1\}\text{.}\)
  1. Determine the adjacency matrices of \(r_1\) and \(r_2\text{.}\)
  2. Use the definition of composition to find \(r_1r_2\text{.}\)
  3. Verify the result in part b by finding the product of the adjacency matrices of \(r_1\) and \(r_2\text{.}\)
Answer.
  1. \(\begin{array}{cc} & \begin{array}{ccc} 4 & 5 & 6 \\ \end{array} \\ \begin{array}{c} 1 \\ 2 \\ 3 \\ 4 \\ \end{array} & \left( \begin{array}{ccc} 0 & 0 & 0 \\ 1 & 0 & 0 \\ 0 & 1 & 0 \\ 0 & 0 & 1 \\ \end{array} \right) \\ \end{array}\) and \(\begin{array}{cc} & \begin{array}{ccc} 6 & 7 & 8 \\ \end{array} \\ \begin{array}{c} 4 \\ 5 \\ 6 \\ \end{array} & \left( \begin{array}{ccc} 0 & 0 & 0 \\ 1 & 0 & 0 \\ 0 & 1 & 0 \\ \end{array} \right) \\ \end{array}\)
  2. \(\displaystyle r_1r_2 =\{(3,6),(4,7)\}\)
  3. \(\displaystyle \begin{array}{cc} & \begin{array}{ccc} 6 & 7 & 8 \\ \end{array} \\ \begin{array}{c} 1 \\ 2 \\ 3 \\ 4 \\ \end{array} & \left( \begin{array}{ccc} 0 & 0 & 0 \\ 0 & 0 & 0 \\ 1 & 0 & 0 \\ 0 & 1 & 0 \\ \end{array} \right) \\ \end{array}\)

2.

  1. Determine the adjacency matrix of each relation given via the digraphs in Exercise 3 of Section 6.3.
  2. Using the matrices found in part (a) above, find \(r^2\) of each relation in Exercise 3 of Section 6.3.
  3. Find the digraph of \(r^2\) directly from the given digraph and compare your results with those of part (b).

3.

Suppose that the matrices in Example 6.4.5 are relations on \(\{1, 2, 3, 4\}\text{.}\) What relations do \(R\) and \(S\) describe?
Answer.
Table 6.4.8.
R : \(x r y\) if and only if \(\lvert x -y \rvert = 1\)
S : \(x s y\) if and only if \(x\) is less than \(y\text{.}\)

4.

Let \(D\) be the set of weekdays, Monday through Friday, let \(W\) be a set of employees \(\{1, 2, 3\}\) of a tutoring center, and let \(V\) be a set of computer languages for which tutoring is offered, \(\{A(PL), B(asic), C(++), J(ava), L(isp), P(ython)\}\text{.}\) We define \(s\) (schedule) from \(D\) into \(W\) by \(d s w\) if \(w\) is scheduled to work on day \(d\text{.}\) We also define \(r\) from \(W\) into \(V\) by \(w r l\) if \(w\) can tutor students in language \(l\text{.}\) If \(s\) and \(r\) are defined by matrices
\begin{equation*} S = \begin{array}{cc} & \begin{array}{ccc} 1 & 2 & 3 \\ \end{array} \\ \begin{array}{c} M \\ T \\ W \\ R \\ F \\ \end{array} & \left( \begin{array}{ccc} 1 & 0 & 1 \\ 0 & 1 & 1 \\ 1 & 0 & 1 \\ 0 & 1 & 0 \\ 1 & 1 & 0 \\ \end{array} \right) \\ \end{array} \textrm{ and }R= \begin{array}{cc} & \begin{array}{cccccc} A & B & C & J & L & P \\ \end{array} \\ \begin{array}{c} 1 \\ 2 \\ 3 \\ \end{array} & \left( \begin{array}{cccccc} 0 & 1 & 1 & 0 & 0 & 1 \\ 1 & 1 & 0 & 1 & 0 & 1 \\ 0 & 1 & 0 & 0 & 1 & 1 \\ \end{array} \right) \\ \end{array} \end{equation*}
  1. compute \(S R\) using Boolean arithmetic and give an interpretation of the relation it defines, and
  2. compute \(S R\) using regular arithmetic and give an interpretation of what the result describes.

5.

How many different reflexive, symmetric relations are there on a set with three elements?
Hint.
Consider the possible matrices.
Answer.
The diagonal entries of the matrix for such a relation must be 1. When the three entries above the diagonal are determined, the entries below are also determined. Therefore, there are \(2^3\) fitting the description.

6.

Let \(A = \{a, b, c, d\}\text{.}\) Let \(r\) be the relation on \(A\) with adjacency matrix \(\begin{array}{cc} & \begin{array}{cccc} a & b & c & d \\ \end{array} \\ \begin{array}{c} a \\ b \\ c \\ d \\ \end{array} & \left( \begin{array}{cccc} 1 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 \\ 1 & 1 & 1 & 0 \\ 0 & 1 & 0 & 1 \\ \end{array} \right) \\ \end{array}\)
  1. Explain why \(r\) is a partial ordering on \(A\text{.}\)
  2. Draw its Hasse diagram.

7.

Define relations \(p\) and \(q\) on \(\{1, 2, 3, 4\}\) by \(p = \{(a, b) \mid \lvert a-b\rvert=1\}\) and \(q=\{(a,b) \mid a-b \textrm{ is even}\}\text{.}\)
  1. Represent \(p\) and \(q\) as both graphs and matrices.
  2. Determine \(p q\text{,}\) \(p^2\text{,}\) and \(q^2\text{;}\) and represent them clearly in any way.
Answer.
  1. \(\begin{array}{cc} & \begin{array}{cccc} 1 & 2 & 3 & 4 \\ \end{array} \\ \begin{array}{c} 1 \\ 2 \\ 3 \\ 4 \\ \end{array} & \left( \begin{array}{cccc} 0 & 1 & 0 & 0 \\ 1 & 0 & 1 & 0 \\ 0 & 1 & 0 & 1 \\ 0 & 0 & 1 & 0 \\ \end{array} \right) \\ \end{array}\) and \(\begin{array}{cc} & \begin{array}{cccc} 1 & 2 & 3 & 4 \\ \end{array} \\ \begin{array}{c} 1 \\ 2 \\ 3 \\ 4 \\ \end{array} & \left( \begin{array}{cccc} 1 & 0 & 1 & 0 \\ 0 & 1 & 0 & 1 \\ 1 & 0 & 1 & 0 \\ 0 & 1 & 0 & 1 \\ \end{array} \right) \\ \end{array}\)
  2. \(P Q= \begin{array}{cc} & \begin{array}{cccc} 1 & 2 & 3 & 4 \\ \end{array} \\ \begin{array}{c} 1 \\ 2 \\ 3 \\ 4 \\ \end{array} & \left( \begin{array}{cccc} 0 & 1 & 0 & 0 \\ 1 & 0 & 1 & 0 \\ 0 & 1 & 0 & 1 \\ 0 & 0 & 1 & 0 \\ \end{array} \right) \\ \end{array}\) \(P^2 =\text{ } \begin{array}{cc} & \begin{array}{cccc} 1 & 2 & 3 & 4 \\ \end{array} \\ \begin{array}{c} 1 \\ 2 \\ 3 \\ 4 \\ \end{array} & \left( \begin{array}{cccc} 1 & 0 & 1 & 0 \\ 0 & 1 & 0 & 1 \\ 1 & 0 & 1 & 0 \\ 0 & 1 & 0 & 1 \\ \end{array} \right) \\ \end{array}\)\(=Q^2\)

8.

  1. Prove that if \(r\) is a transitive relation on a set \(A\text{,}\) then \(r^2 \subseteq r\text{.}\)
  2. Find an example of a transitive relation for which \(r^2\neq r\text{.}\)

9.

We define \(\leq\) on the set of all \(n\times n\) relation matrices by the rule that if \(R\) and \(S\) are any two \(n\times n\) relation matrices, \(R \leq S\) if and only if \(R_{ij} \leq S_{ij}\) for all \(1 \leq i, j \leq n\text{.}\)
  1. Prove that \(\leq\) is a partial ordering on all \(n\times n\) relation matrices.
  2. Prove that \(R \leq S \Rightarrow R^2\leq S^2\) , but the converse is not true.
  3. If \(R\) and \(S\) are matrices of equivalence relations and \(R \leq S\text{,}\) how are the equivalence classes defined by \(R\) related to the equivalence classes defined by \(S\text{?}\)
Answer.
  1. Reflexive: \(R_{ij}=R_{ij}\) for all \(i,j\text{,}\) therefore \(R_{ij}\leq R_{ij}\)
    Antisymmetric: Assume \(R_{ij}\leq S_{ij}\) and \(S_{ij}\leq R_{ij}\) for all \(1\leq i,j\leq n\text{.}\) Therefore, \(R_{ij} = S_{ij}\) for all \(1\leq i,j\leq n\) and so \(R=S\)
    Transitive: Assume \(R, S,\) and \(T\) are matrices where \(R_{ij}\leq S_{ij}\) and \(S_{ij}\leq T_{ij}\text{,}\) for all \(1\leq i,j\leq n\text{.}\) Then \(R_{ij}\leq T_{ij}\) for all \(1\leq i,j\leq n\text{,}\) and so \(R\leq T\text{.}\)
  2. \begin{equation*} \begin{split} \left(R^2\right)_{ij}&=R_{i1}R_{1j}+R_{i2}R_{2j}+\cdots +R_{in}R_{nj}\\ &\leq S_{i1}S_{1j}+S_{i2}S_{2j}+\cdots +S_{in}S_{nj}\\ &=\left(S^2\right)_{ij} \Rightarrow R^2\leq S^2 \end{split}\text{.} \end{equation*}
    To verify that the converse is not true we need only one example. For \(n=2\text{,}\) let \(R_{12}=1\) and all other entries equal \(0\text{,}\) and let \(S\) be the zero matrix. Since \(R^2\) and \(S^2\) are both the zero matrix, \(R^2\leq S^2\text{,}\) but since \(R_{12}>S_{12}, R\leq S\) is false.
  3. The matrices are defined on the same set \(A=\left\{a_1,a_2,\ldots ,a_n\right\}\text{.}\) Let \(c\left(a_i\right), i=1,2,\ldots ,n\) be the equivalence classes defined by \(R\) and let \(d\left(a_i\right)\) be those defined by \(S\text{.}\) Claim: \(c\left(a_i\right)\subseteq d\left(a_i\right)\text{.}\)
    \begin{equation*} \begin{split} a_j\in c\left(a_i\right)&\Rightarrow a_i r a_j\\ &\Rightarrow R_{ij}=1 \Rightarrow S_{ij}=1\\ &\Rightarrow a_i s a_j\\ & \Rightarrow a_j \in d\left(a_i\right)\\ \end{split} \end{equation*}