2. Introduction
Sparse Matrix
Lower Triangular Matrix
Tri-diagonal Matrix
Row Major Representation For Lower Triangular Matrix
Column Major Representation For Lower Triangular Matrix
Column Major Representation For Tri-diagonal Matrix
Advantages of Proposed Method
References
TABLE OF CONTENTS
2
3. INTRODUCTION
3
Sparse matrix generally contains elements with zero values; examples of such kind of matrices are lower & upper
triangular matrix.
For the solution of linear equations, these matrices have been used .
Since many of the elements in such matrices contain zeroes. Thus a need to save space arises, either in memory or
disk.
For lower and upper triangular matrices of 1-D array, analysis has been done. After the analysis their
corresponding addressing formulas have been developed.
4. Few variants are also analyzed for lower and upper triangular matrices.
It is needed to mention that different approaches for addressing an element of sparse matrices are remain
unanalyzed in which column major are also included.
In this paper we analyze storage by means of 1-D array for sparse matrices of the lower triangular type, plus one
matrix of the tri-diagonal type.
To address an element in the lower triangular matrices using row major is presented first.
After this, a new approach based on column major is defined and analyzed for lower triangular matrices and tri-
diagonal matrices.
INTRODUCTION…
4
5. SPARSE MATRIX
5
Matrices with a relatively high proportion of zero entries are called sparse matrices.
Two general types of N-square sparse matrices, which occur in various applications, are
Lower Triangular Matrix (LTM)
Tri-diagonal Matrix (TDM)
6. A matrix which contains nonzero elements only on or below the main
diagonal is called a lower triangular matrix i.e. above the main
diagonal all elements are zero.
Let us define a Lower Triangular Matrix (LTM) named A of order N,
N > 0. Fig. 1 shows an example of this kind of matrix, with N = 7
There are 7 rows and 7 columns in above 7-square LTM A. Any
element in LTM A is represented by a(J, K) where
J=0, 1, 2….7 and K=0, 1, 2….7
In LTM A, row-1 contains 1 element and row-2 contains 2 elements.
Similarly row-3, row-4….row-7 contains 3, 4….7 numbers of
elements respectively. From above Fig. 1, it may be observed that
total number of elements in any LTM of order N can be calculated by
arithmetic progression as follows:
1+2+3+…. +N = N(N+1)/2 (1)
Hence in LTM A, there are 7*(7+1)/2 = 28 elements.
LOWER TRIANGULAR MATRIX(LTM)
Fig. 1. Lower Triangular Matrix A (LTM A)
6
1 2 3 4 5 6 7
1 4
2 3 -5
3 1 0 6
4 -7 8 -1 3
5 5 -2 0 2 -2
6 8 4 5 -1 6 -8
7 2 7 9 0 9 5 -4
7. The matrix, where nonzero entries can only occur on the diagonal or
on elements immediately above or below the diagonal, is called a tri-
diagonal matrix.
Let us define a Tri-diagonal Matrix (TDM) named B of order N, N >
0. Fig. 2 shows an example of this kind of matrix, with N = 7
There are 7 rows and 7 columns in above 7-square TDM B. Any
element in TDM B is represented by b(J, K) where
J=0, 1, 2….7 and K=0, 1, 2….7
Note that TDM has N=7 elements on the diagonal and N–1=6
elements above and below the diagonal. From above Fig. 2, it may be
observed that total number of elements in any TDM of order N can
be calculated as follows:
N + (N–1) + (N–1) = 3N – 2 (2)
Hence TDM B contains at most 3N–2 nonzero elements i.e.
3*7 – 2 = 19.
TRI-DIAGONAL MATRIX(TDM)
Fig. 2. Tri-diagonal Matrix B (TDM B)
7
1 2 3 4 5 6 7
1 4 7
2 3 -5 4
3 0 6 1
4 -1 3 -3
5 2 -2 0
6 6 -8 2
7 5 -4
8. ROW MAJOR REPRESENTATION FOR LTM
8
4 3 -5 1 0 6 -7 8 -1 3 5 -2 0 2 -2 8 4 5 -1 6 -8 2 7 9 0 9 5 -4
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
Fig. 3. 1-D representation by rows of LTM A
Elements in LTM A are represented in Fig. 3 using 1-D array named C.
Any element in 1-D array C is represented by C[L] where L=0, 1, 2….28
Given an element a(J, K) belonging to the triangular array LTM A. Here, the purpose is to determine the
corresponding position of same element a(J, K) in 1-D array C.
The position of element a(J, K) in array C is determined in the following way.
C[1]=a(1,1), C[2]=a(2,1).…C[L]=a(J,K)….C[28]=a(7,7)
According to equation (1), number of elements in any LTM of order N is N(N+1)/2.
So it may be observed that 1-D array C contains only N(N+1)/2 number of elements i.e. 28.
9. ROW MAJOR REPRESENTATION FOR LTM…
9
Since the position of a(J, K) is required in 1-D array C. So the purpose is to calculate the formula that
gives us the integer L in terms of J and K where C[L] = a(J, K).
I.e. L gives the address of element a(J, K) in which all the elements including a(J, K) are list up in 1-D
array C.
To calculate the address of element a(J, K) in 1-D array C, following algorithm is used.
Step-1: Calculate the number of elements coming before Jth row, i.e. number of elements up to (J-1)th row.
Step-2: Then calculate the number of elements in Jth row including a(J, K).
Step-3: Add both the values calculated in above two steps. The result is desired value L i.e. address of element
a(J, K) in 1-D array C.
10. Total numbers of elements in the rows above the element a(J, K) are calculated by arithmetic progression as
follows:
1+2+3+….+(J–1) = J(J–1)/2 (3)
and there are K elements in row-J up to and including a(J, K). The address of element a(J, K) can be
calculated by adding equation (3) with number of elements in row-J up to and including a(J, K) i.e. K. So
L = J(J–1)/2 + K (4)
yields the index that accesses the value of element a(J, K) from the linear array C.
For example: Let’s calculate the address of an element a(5, 3) of LTM A in array C using above formula.
Here J = 5 and K = 3 Then
L = 5(5–1)/2 + 3
L= 5*4/2 + 3
L = 10 + 3
L=13
It means the address of the desired element in 1-D array C is 13. It may be observed in Fig. 3.
ROW MAJOR REPRESENTATION FOR LTM…
10
11. 11
The approach is to insert the same elements of LTM A in another 1-D array named D column wise.
Elements in LTM A are represented in Fig. 4 using 1-D array D.
Any element in 1-D array D is represented by D[L] where L=0, 1, 2….28
Given an element a(J, K) belonging to the triangular array LTM A. Here, the purpose is to determine the
corresponding position of same element a(J, K) in 1-D array D.
The position of element a(J, K) in array D is determined in the following way.
D[1]=a(1,1), D[2]=a(2,1), D[3]=a(3,1) .…D[L]=a(J,K)…. D[28]=a(7,7)
COLUMN MAJOR REPRESENTATION FOR LTM
4 3 1 -7 5 8 2 -5 0 8 -2 4 7 6 -1 0 5 9 3 2 -1 0 -2 6 9 -8 5 -4
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
Fig. 4. 1-D representation by columns of LTM A
12. 12
Since the position of a(J, K) is required in 1-D array D. So the purpose is to calculate the formula that gives us the
integer L in terms of J and K where D[L] = a(J, K).
I.e. L gives the address of element a(J, K) in which all the elements including a(J, K) are list up in 1-D array D.
To calculate the address of element a(J, K) in 1-D array D, following algorithm is used.
Step-1: Calculate the number of elements coming after Kth column, i.e. total number of elements coming
from (K+1)th column to Nth column.
Step-2: Then calculate the number of elements in Kth column coming after the element a(J, K).
Step-3: Add both the values calculated in above two steps. The result is total number of elements coming
after element a(J, K).
Step-4: Subtract the value of Step-3 from equation (1) i.e. total number of elements in LTM A. The result is
desired value L i.e. address of element a(J, K) in 1-D array D.
COLUMN MAJOR REPRESENTATION FOR LTM…
13. 13
Total number of elements coming from (N–K)th i.e. (K+1)th to Nth column can be calculated by arithmetic
progression as follows:
1 + 2 + 3 + …. + (N–K) = (N–K)(N–K+1)/2 (5)
and there are (N-J) elements in same column Kth after a(J, K).
So total number of elements after element a(J, K) are:
{(N–K)(N–K+1)/2} + (N–J) (6)
According to Step-4, address of element a(J, K) of LTM A can be calculated by subtracting the total number of
elements coming after a(J, K) from total number of elements in LTM A. Subtract equation (6) from equation (1)
i.e.
L= {N(N + 1)/2} – {(N–K)(N–K+1)/2 + (N–J)} (7)
yields the index that accesses the value of element a(J, K) from the linear array D.
For example: calculate the address of same element a(5, 3) of LTM A in array D, according to proposed method.
Here J = 5 , K = 3 and N = 7
Then L = {7(7+1)/2} – {(7–3)(7–3+1)/2 + (7–5)}
L = 28 – {(4*5/2) + 2}
L = 28 – 12 = 16
It means the address of the same element in 1-D array D is 16. The same may be observed in Fig. 4.
COLUMN MAJOR REPRESENTATION FOR LTM…
14. 14
The approach is to insert the elements of TDM B in another 1-D array named E column wise. Elements in TDM B
are represented in Fig. 5 using 1-D array E.
Any element in 1-D array E is represented by E[L] where L=0, 1, 2….19
Given an element b(J, K) belonging to the TDM B. Here, the purpose is to determine the corresponding position of
same element b(J, K) in 1-D array E.
The position of the element b(J, K) in array E is determined in the following way.
E[1]=b(1,1), E[2]=b(2,1), E[3]=b(1,2) .…E[L]=b(J,K)…. E[19]=b(7,7)
It may be observed initially from equation (2) that array E contains only (3N – 2) number of elements i.e. 19.
COLUMN MAJOR REPRESENTATION FOR TDM
4 3 7 -5 0 4 6 -1 1 3 2 -3 -2 6 0 -8 5 2 -4
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
Fig. 5. 1-D representation by columns of TDM B
15. 15
Since the position of b(J, K) is required in 1-D array E. So the purpose is to calculate the formula that gives us the
integer L in terms of J and K where E[L] = b(J, K).
I.e. L gives the address of element b(J, K) in which all the elements including b(J, K) are list up in 1-D array E.
To calculate the address of element b(J, K) in 1-D array E, following algorithm is used.
Step-1: Calculate the number of elements coming before Kth column, i.e. number of elements upto (K–1)th
column.
Step-2: Then calculate the number of elements in Kth column coming before element b(J, K).
Step-3: Add both the values calculated in above two steps and also add 1 in it for b(J, K) itself. The result is
desired value L i.e. address of element b(J, K) in 1-D array E.
COLUMN MAJOR REPRESENTATION FOR TDM…
16. 16
Total number of elements coming before the column of element b(J, K) is
3(K–2) + 2 (8)
Total number of elements coming before b(J, K) in Kth column is (J–K+1).
According to Step-3, address of element b(J, K) in 1-D array E can be calculated by adding above value (J–K+1)
and equation (8). Further add 1 for b(J, K) itself. So
L= [3(K–2)+2] + [J–K+1] + 1
L= 2K + J – 2 (9)
yields the index that accesses the value of element b(J, K) from the linear array E.
For example, Let’s calculate the address of an element b(5, 6) of TDM B in array E, according to proposed
method.
Here J = 5, K = 6 and N = 7
Then
L = 2*6 + 5 – 2
L = 12 + 5 – 2
L = 15
It means the address of the element in 1-D array E is 15. It can be observed in Fig. 5.
COLUMN MAJOR REPRESENTATION FOR TDM…
17. 17
Two methods are generally used to traverse the elements of any sparse matrix.
The first method is row wise and second method is column wise.
During traversal few of the elements appears first in column wise rather than row wise.
In this scenario proposed method is useful to access the elements easily.
ADVANTAGES OF PROPOSED METHOD
18. 18
REFERENCES
[1] Grossman S., “Álgebra Lineal,” McGraw Hill, 1996.
[2] Cairó O. & Guardati S., “Data Structures,” McGraw−Hill, 2005.
[3] Horowitz E. & Sahni S., “Fundamentals of data Structures in Pascal,” Computer Science Press, 1990.
[4] Moreno F. & Flórez R., “Fórmulas de Direccionamiento en Matrices Triangulares,” Journal Facultad de Ingeniería
Universidad de Antioquia. Medellín, 2001.
[5] Seymour Lipschutz, “Data Structures,” McGraw-Hill, 2014.