Cover Data Structures and Algorithms with Object-Oriented Design Patterns in Java
next up previous contents index

Dense Matrices

The simplest way to implement a matrix is to use an array of arrays as shown in Program gif. In this case, we use three fields. The first two fields, numberOfRows and numberOfColumns record the dimensions of the matrix. The third field, array, is a Java array of arrays of doubles.

   program3158
Program: DenseMatrix fields and constructor.

The constructor takes two arguments, m and n, and constructs the corresponding tex2html_wrap_inline60042 matrix. Clearly, the running time of the constructor is O(mn). (Remember, Java initializes all the array elements to zero).


next up previous contents index

Bruno Copyright © 1998 by Bruno R. Preiss, P.Eng. All rights reserved.