Special Matrices
Special Matrices
Special Matrices
• Square – same number of rows and columns.
• Some special forms of square matrices are
– Diagonal: M(i,j) = 0 for i ≠ j
– Tridiagonal: M(i,j) = 0 for |i-j| > 1
– Lower triangular: M(i,j) = 0 for i >= j
– Upper triangular: M(i,j) = 0 for i <= j
– Symmetric M(i,j) = M(j,i) for all i and j
Thapar University UCS406 - Data Structures and Algorithms 2
Contd…
2 0 0 0 2 1 0 0 2 0 0 0
0 1 0 0 3 1 3 0 5 1 0 0
0 0 4 0 0 5 2 7 0 3 1 0
0 0 0 6 0 0 9 0 4 2 7 0
Diagonal Tri-Diagonal Lower Triangular
2 1 3 0 2 4 6 0
0 1 3 8 4 1 9 5
0 0 1 6 6 9 4 7
0 0 0 0 0 5 7 0
Upper Triangular Symmetric
Thapar University UCS406 - Data Structures and Algorithms 3
Contd…
• Why are we interested in these "special" matrices?
– We can provide more efficient implementations
for specific special matrices.
– Rather than having a space complexity of O(n2),
we can find an implementation that is O(n).
– We need to be clever about the "store" and
"retrieve" operations to reduce time.
0 0 0 15 0 3 22 0 5 -15
x x
1 1 1 11 1 2 3
x x
2 2 3 -6
x x
3 x
4 4 0 91
x x
x 5 5 2 28
Operations
• Transpose
• Addition
• Multiplication