DS - Lecture15 Updated
DS - Lecture15 Updated
MATRIX
4 2 0 6
A 2 3 1 9
0 7 5 1
1
SQUARE MATRIX
A matrix for which the number of rows and columns are equal is called a
square matrix. A square matrix A with n rows and n columns (size n n)
has the form:
a11 a12 a1i a1n
a a2 i a2 n
21 a22
A
ai1 ai 2 aii ain
an1 an 2 ani ann
TRANSPOSE OF A MATRIX
2
EXAMPLE
Find transpose of the following matrix
4 2 0 6
A 2 3 1 9
0 7 5 1
4 2 0
2 3 7
At
0 1 5
6 9 1
SYMMETRIC MATRIX
Note
A that matrix
square the order
A =of(aAij)isof3size n n isascalled
x 4 where ordersymmetric
of A t is 4 xif,3.and
In fact
onlyifif,
A
has order m x n then A will have order n x m.
t
Suppose A and B are two matrices such that the number of columns of A is
equal to the number of rows of B, say A is an m p matrix and B is a p n
matrix.
Then the product of A and B, written AB, is the m n matrix whose ijth
entry is obtained by multiplying the elements of the ith row of A by the
corresponding elements of the jth column of B and then adding;
REMARK
If the number of columns of A is not equal to the
number of rows of B, then the product AB is not defined.
4
EXAMPLE
1 3 2 0 4
A and B
2 1 3 2 6
SOLUTION
Size of A is 2 2 and of B is 2 3, the product AB is defined as a 2 3
matrix. But BA is not defined, because
no. of columns of B = 3 2 = no. of rows of A.
1 3 2 0 4
AB 3 2 6
2 1
(1)(2) (3)(3) (1)(0) (3)(6) (1)(4) (3)(6)
(2)(2) (1)(3) (2)(0) ( 1)( 2) (2)( 4) ( 2)(6)
11 6 14
1 2 14
EXAMPLE
5
1 3
At 2 1
0 4
Now
1 3
1 2 0
AA
t 2 - 1 1 4 0 3 2 0 5 1
3 1 4 3 2 0 9 1 16 1 26
0 4
and
1 3
1 2 0
At A 2 1 3 1 4
0 4
1 9 2 3 0 12
2 3 4 1 0 4
0 120 4 0 16
10 1 12
1 5 4
12 4 16
Which are the required matrices you can note that AA t is not equal to the
AtA. Which shows that the operation of Matrix multiplication is not
commutative in General.
6
ADJACENCY MATRIX OF A GRAPH
Let G be a graph with ordered vertices v 1, v2,.., vn. The adjacency matrix of
G is the matrix A = (aij) over the set of non-negative integers such that
aij = the number of edges connecting v i and vj
for all i, j = 1, 2, …, n
EXAMPLE
e3
e1 e4 e5
v4
v3
e2
Adjacency Matrix
7
EXERCISE
0 2 0
2 1 0
0 0 1
SOLUTION
Let the three vertices of the graph be named v 1, v2 and v3. We label the
adjacency matrix across the top and down the left side with these vertices
and draw the graph accordingly.
v1 v2 v3 v2
v1
v1 0 2 0
v2 2 1 0 v3
v3 0 0 1
DIRECTED GRAPH
8
EXAMPLE
v2
e1
e3
v1
e2
v4 e5 v3
e4 e6
In the above figure we have a directed graph note that there is an edge from
v2 to v3 but no edge from v3 to v2.
10
THEOREM
If G is a graph with vertices v1, v2, …,vm and A is the adjacency matrix of G,
then for each positive integer n,
the ijth entry of An = the number of walks of length n from v i to vj
for all integers i,j = 1, 2, …, n
EXERCISE
1 1 2
Let A 1 0 1
2 1 0
be the adjacency matrix of a graph G with vertices v 1, v2, and v3. Find
(a) the number of walks of length 2 from v 2 to v3
(b) the number of walks of length 3 from v 1 to v3
Draw graph G and find the walks by visual inspection for (a)
SOLUTION
(a) Since we have to find out the number of walks of length 2 from v 2 to
v3 which will be the 23rd element of A2 (By using the above Theorem)
So first we will calculate A2.
1 1 2 1 1 2 6 3 3
A2 AA 1 0 1 1 0 1 3 2 2
2 1 0 2 1 0 3 2 5
1 1 2 6 3 3 15 9 15
A3 AA2 1 0 1 3 2 2 9 5 8
2 1 0 3 2 5 15 8 8
Let G be a graph with vertices v1, v2, …, vn and edges e1, e2, …, em. The
incidence matrix of G is the matrix M = (mij) of size n m defined by
12
EXAMPLE
A graph with its incidence matrix is shown.
INCIDENCE MATRIX
v1 v2
e1 e2 e3 e4
v1 1 0 1 0 0
e4
v2 0 0 0 1 1
e1
e5
e3 M
v3 0 0 1 1 1
v4
v 4 1 1 0 0 0
e2 v3
REMARK
In the incidence matrix
1. Multiple edges are represented by columns with identical entries
(e4 & e5)
2. Loops are represented using a column with exactly one entry equal to
1, corresponding to the vertex that is incident with this loop and other
zeros (e2).
13