wpe41.gif (23084 bytes)CIS3355: Business Data Structures
Fall, 2008
 

WHAT IS AN ARRAY?

 

  1. Definition of an array:
  1. An ordered arrangement of data elements. It nearly contains a fixed number

    of elements all of the same type.

  2. It is a rectangular arrangement of quantities that can be displayed in rows

    and columns as in a matrix.

  3. An example of a one-dimensional array is a vector.
  4. An example of a two-dimensional array is a matrix.
  5. You can store and handle arrays in one or more dimensions in some of the programming languages.
  6. Multi-dimensional arrays are used in scientific simulation and mathematics.
  7. Arrays can be of any data type. The data type for an array specifies the data type for each element of an array.

 

EXAMPLE:

If we wanted to store a numeric value for everyday of the year, we could declare 365 separate numeric variables. We could create an array to store all the data in one variable. The array itself is a single variable with multiple elements, each element can contain one piece of data.

 

 

 

 

TWO TYPES OF ARRAYS:

  1. Fixed sized arrays---has a fixed number of elements and is only used when

    you know exactly how many elements your array will have.

  2. Dynamic arrays are more useful in mathematics.

 

 

 

HOW TO CALCULATE AN ELEMENT ADDRESS:

Base address of the array + (offset number * 2)

2 bytes are needed for an integer in the above formula.

 

ARRAY INFORMATION:

1. Arrays give us a way to determine an address.

2. The subscript is the offset from the base address of an array.

3. The numvector will be connected with the base address of the array.

4. If we have the base address, we use the offset to determine the address of the

element in the array.

 

USE OF ONE OR TWO ARRAYS:

  1. If we have 2 vectors we need 2 blocks of RAM.
  2. If we have one array we need 1 block of RAM.

 

THREE TYPES OF ARRAYS:

  1. Automatic arrays- they are inside a function, memory allocation is free.
  2. Static arrays- they are functional, hold on to values between calls.
  3. External arrays- they are initialized and are known to all functions.

 

 

GOOD REFERENCES FOR ARRAYS:

  1. http://www.aspire.cs.uah.edu/textbook/CPP7019.html
  2. http://www.mathworks.com/access/helpdesk/help/techdoc/matlab_prog/ch_dat45.html
  1. http://www.boost.org/libs/python/doc/v2/numeric.html

 

 

MULTIPLE CHOICE:

  1. An example of a two-dimensional array is:
  1. vector
  2. element
  3. numvector
  4. matrix

Answer: d. matrix

 

  1. What kind of arrays is used in scientific and math?
  1. one –dimensional
  2. two-dimensional
  3. multi-dimensional
  4. three-dimensional

Answer: c. multi-dimensional

 

  1. What is not a characteristic of an array?
  1. ordered arrangement
  2. rectangular
  3. matrix is type of an array
  4. square in shape

Answer: d. square in shape

 

SHORT ANSWER PROBLEMS

  1. What is the formula to calculate an element address?

    Answer: base address of the array + (offset number * 2)

     

  2. What are external arrays?

    Answer: They are all known to all functions and are initialized.

     

  3. If we use the base address of an array, how do we determine the address

of the element?

Answer: We use the offset of the array to determine it.