The most basic structure for storing and accessing a collection of data is the array. Arrays can be used to solve a wide range of problems in computer science. Most programming languages provide this structured data type as a primitive and allow for the creation of arrays with multiple dimensions. In this chapter, we implement an array structure for a one-dimensional array and then use it to implement a two-dimensional array and the related matrix structure.
At the hardware level, most computer architectures provide a mechanism for creating and using one-dimensional arrays. A one-dimensional array, as illustrated in Figure 2.1, is composed of multiple sequential elements stored in contiguous bytes of memory and allows for random access to the individual elements.
The entire contents of an array are identified by a single name. Individual elements within the array can be accessed directly by specifying an integer subscript or index value, which indicates an offset from the start of the array. This is similar to the mathematics notation (xi), which allows for multiple variables of the same name. The difference is that programming languages typically use square brackets following the array name to specify the subscript,
Figure 2.1. A sample 1-D array consisting of 11 elements.
You will notice the array structure looks very similar ...