7.3 Symmetric Matrix Data Structures

Recognizing the special character of symmetric matrices can save time and storage during the solution of linear systems. More specifically, a dense matrix requires storage for n2 elements. A symmetric matrix can be stored in about half the space, $\frac{{n}^{2}+n}{2}$ elements. Only the upper (or lower) triangular portion of A has to be explicitly stored. The implicit portions of A can be retrieved using Equation 73. An efficient data structure for storing dense, symmetric matrices is a simple linear array. If the upper triangular portion of A is retained, the array is organized in the following manner.

$$\mathbf{A}=({a}_{11},{a}_{12},\cdots,{a}_{1n},{a}_{21},\cdots,{a}_{2n},\cdots,% {a}_{nn})$$ (82)

The element aij is retrieved from the linear array by the following indexing rule.

$$a_{ij}=\mathbf{a}[(i-1)(n)-(i-1)i/2+j]$$ (83)

If array and matrix indexing is zero based (as in the C programming language), the subscripting rule becomes

$$a_{ij}=\mathbf{a}[in-(i-1)i/2+j]$$ (84)

If the lower triangular portion of A is retained, the linear array is organized as follows.

$$\mathbf{A}=({a}_{11},{a}_{21},{a}_{22},{a}_{31},\cdots,{a}_{n1},{a}_{n2},% \cdots,{a}_{nn})$$ (85)

The element aij is retrieved from the linear array by the following indexing rule.

$$a_{ij}=\mathbf{a}[i(i-1)/2+j]$$ (86)

If array and matrix subscripts are zero based, Equation 86 becomes

$$a_{ij}=\mathbf{a}[i(i+1)/2+j]$$ (87)

You will observe that the dimension of A does not enter the indexing calculation when its lower triangular portion is retained. The indexing equations are implemented most efficiently by replacing division by two with a right shift.