3D Arrays
Computer Science: OCR A Level, topic 4.2.1
Arrays
Arrays are data structures which are of a fixed size and contain data of the same type stored in a contiguous block of memory.

1D array
- A 1-dimensional array is a single set of data, which can be visualised in a single row. - For example: oneDArray = [A, B, C, D]
,w_800.png)
2D array
- A 2-dimensional array is a set of data which can be visualised in rows and columns.
- For example, array twoDArray = [[A, B, C, D], [E, F, G, H],[I, J, K, L]]
- Items in a 2-dimensional array are referred to by their row number, followed by column number.
- For example, twoDArray [1,2] = G
,w_800.png)
3D array
- A 3-dimensional array is a collection of 2-dimensional arrays.
- You can visualise each 2D array as being stored one behind the other.
- For example, threeDArray = [[[A, B, C, D], [E, F, G, H],[I, J, K, L]], [[M, N, O, P], [Q, R, S, T],[U, V, W, X]],[[Y, Z, 0, 1], [2, 3, 4, 5], [6, 7, 8, 9]]]
,w_800.png)
3D array cont.
- Items in a 3-dimensional array are referred to by their 2D array number, followed by the row number, and column number.
- For example, threeDArray [1,2,2] = W
Test yourself on 3D Arrays
Which of the following would be used to refer to the element J?
What is the array element referred to by threeDArray[2,2,3]?
What type of array is declared below?
array = [[Apple,Orange,Pear],[Kiwi,Mango,Lychee],[Banana,Lime,Lemon]]