Chapter 8 - Array Computer Science
Chapter 8 - Array Computer Science
• An array is a data structure containing several elements of the same data type; these elements can be accessed using
the same identifier name. The position of each element in an array is identified using the array’s index.
of position 0 is 2
Visualization of Array
Why we should use an array?
One dimensional array (1D array)
An one-dimensional array has just one row of data can be considered as a list.
This array has 5 elements and name of the array is Numbers. The first data item is in position 0 and the data value
is 10.
• Array use third brackets after the identifier to indicate the index we want to access. For example , Array[0] is
accessing the first element in the array/identifier named Numbers,
Numbers[0] = 10
Numbers[1] = 5
Numbers[2] = 90
Numbers[3] = 26
Numbers[4] = 87
One dimensional array declaration in pseudocode
A one-dimensional array can be referred to as a list. Here is an example of a list with 10 elements in it where
the first element has an index of zero.
Formula:
Each position in the array can be populated in an array by defining the value at each index position.
For instance, we can assign the number 27 to the fourth position in the array MyList as follows:
MyList[4] ← 27
Notice that in this code we have used the variable Counter as the array index.
We can display the data that lies in a particular location in an array as follows:
Here is an example of a table with 10 rows and 3 columns, which contains 30 elements.
The first element is located at position 0,0.
When a two-dimensional array is declared in pseudocode:
Formula:
We can display the data that lies in a particular location in a two-dimensional array as follows:
OUTPUT MyList[2,1]