Class SparseSquareMatrix

  • All Implemented Interfaces:
    Serializable

    public class SparseSquareMatrix
    extends Object
    implements Serializable
    A sparse, square matrix, implementing using two arrays of sparse vectors, one representation for the rows and one for the columns. For matrix-matrix product, we might also want to store the column representation. Derived from http://introcs.cs.princeton.edu/java/44st/SparseMatrix.java.html For additional documentation, see Section 4.4 of Introduction to Programming in Java: An Interdisciplinary Approach by Robert Sedgewick and Kevin Wayne.
    See Also:
    Serialized Form
    • Constructor Detail

      • SparseSquareMatrix

        public SparseSquareMatrix​(int N)
        initialize an N-by-N matrix of all 0s
        Parameters:
        N - - size
    • Method Detail

      • put

        public void put​(int i,
                        int j,
                        double value)
        set A[i][j] = value
        Parameters:
        i -
        j -
        value -
      • get

        public double get​(int i,
                          int j)
        access a value at i,j
        Parameters:
        i -
        j -
        Returns:
        return A[i][j]
      • nnz

        public int nnz()
        return the number of nonzero entries (not the most efficient implementation)
        Returns: