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

What is a Numeric Array?

 

 

 

               An array is a very simple abstract data structure, which consists or arrangements of integers and real numbers.  Arrays are the most used data structure in existence of computer programming.  In addition, arrays can be incorporated into a number of additional data structures.  A characteristic of arrays is that they hold a fixed number of equally sized data elements which are all of the same data type.       

There are different types of arrays:    

 one dimensional -------------à   Vector

 multi-dimensional.-----------à   matrix

 

Example:

 

Football Scores

 

Team 1

Team 2

Text Box: Indices

 
 

Team 3

 

 Game 1

50

32

Text Box:  Element 
  (at index 2)
 

 
 

42

 

Game 2

16

21

35

Game 3

15

17

27

           

                       -----------------------------------------------------

 

Text Box: Array Length

 
 

                            

 

 

 

In this example each row containing the scores of the different games on one team represents one dimensional array.  In contrast, the entire table containing the scores of the three games of the three different times is an example of a multidimensional array.  In this case it is an array on one dimensional array.

 

Team 1

Text Box: One Dimensional

 
 

  50

 

16

 15

 

 

 

Football Scores

 

Team 1

Team 2

Team 3

Game 1

50

32

Text Box: Multi-dimensional

 
 

42

 

Game 2

16

21

35

Game 3

15

17

27

 

 

         Remember:  All the items of the array must be of the same data type.            

 

 

Even though arrays are very simple to use, there are some disadvantages of using arrays:

·        They do not allow efficient insertion and deletion of elements

·        There are possibilities of referring to non existent element by using an index outside the range of valid indices.

·        Since it has a single fixed size, it is expensive to change it.

 

On the other hand, some of the advantages of using arrays are:

·        Arrays permit efficient ramdom access

·        They are very compact data stuctures

·        An array has good locality of reference.

 

 

Important references:

 

Advantages and disadvantages of arrays

http://en.wikipedia.org/wiki/Array#Advantages_and_disadvantages

 

Creating and using arrays http://java.sun.com/docs/books/tutorial/java/data/arraybasics.html

 

Array Examples- Adding numbers

http://www.fredosaurus.com/notes-cpp/arrayptr/array-examples.html

 

 

 

1. Describe a good situation that may be represented using numeric arrays (All having the same data type)?

 

Test scores of different students in the C++ class, the rows containing the grades of each student is one dimensional array, and the whole table containing the grades of all the students is a multi-dimensional array.

 

2.  Suppose that we stored five prime numbers as:  1, 2, 3, 5, 7, and we used the c declaration:  int prime 1 =1, prime 2= 2, prime 3 = 3, prime 4 = 5, prime 5 = 7.  What are the problems with the declaring the variables as this manner?

 

As you can see, since the prime number order does not coincide with the number assigned, it would be very tedious eth have to declare each of the individual variables.

 

3. What else can you conclude from the declaration?

 

a. It is very easy to search for a particular value that we do not know which variable location it is stored.

 

b. Searching for it becomes cumbersome since we do not know which variable location it is stored.

 

c. none of the above.

 

Answer:  a

 

4. What are the different types of numeric arrays?

 

One dimensional arrays also known as vectors and multi- dimensional also known as matrices or matrix