Data Structures and Algorithms with Object-Oriented Design Patterns in Python
next up previous index

MultiDimensionalArray class __init__ Method

The __init__ method for the MultiDimensionalArray class is defined in Program gif. The dimensions argument is a tuple which represents the dimensions of the array. For example, to create a tex2html_wrap_inline60515 three-dimensional array, we create a MultiDimensionalArray like this:

a = MultiDimensionalArray(3, 5, 7)

   program3131
Program: MultiDimensionalArray class __init__ method.

The __init__ method copies the dimensions of the array into the _dimensions array, and then it computes the _factors array. These operations take O(n), where n is the number of dimensions. The __init__ method then allocates a one-dimensional array of length m given by

displaymath60513

The worst-case running time of the __init__ method is O(m+n).


next up previous index

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