You are on page 1of 3

surname1

[student]

[instructor]

[course]

[Submission date]

Arrays are used when storing many variables of the same type. An array is a sequence of

objects of the same data type(Gunnerson). It is used for storing multiple pieces of information

for the following reasons:

It saves memory. There is a dynamic allocation of memory in an array. This leads to the system

saving memory. There is manual allocation of memory at runtime in case the predefined array

does not have sufficient memory. The amount of required memory is dependent on the type of

data.

Cache friendly. The values of an array are near each other. There is easy access from the CPU to

the cache. This makes it easier in a case where one has to iterate over a large number of items.

Arrays have predictable timings. The access time of the items in an array is provided. The

system is aware of the exact address of the array. Accessing the array becomes fast and

predictable(Marquis & Smith).

Easier debugging. Compared to other data structures debugging is easier. This is because it has

specified indexes that allow for easy traversal(Marquis & Smith). The memory space required is

only for the values, the start address, and the length. The process of implementation is straight
surname2

forwards. The data stored in an array has to be homogenous. This makes it easier for

manipulation. The data is stored in a sequential manner making its tracking faster.

Reusability of code is easier. Once the array has been declared, it can be reused multiple times.

The readability of code is improved.

Array implementation in python

# Python program to demonstrate

# Creation of Array

# importing "array" for array creations

import array as arr

# creating an array with integer type

a = arr.array('i', [1, 2, 3])

# printing original array

print ("The new created array is : ", end =" ")

for i in range (0, 3):

    print (a[i], end =" ")


surname3

print()

# creating an array with float type

b = arr.array('d', [2.5, 3.2, 3.3])

# printing original array

print ("The new created array is : ", end =" ")

for i in range (0, 3):

    print (b[i], end =" ")

Works cited

Gunnerson, Eric. Arrays. 10.1007/978-1-4302-0909-6_16.2001.

Marquis, Hank & Smith, Eric. Arrays and Array Manipulation. 10.1007/978-1-4302-5125-

5_1.2000

You might also like