Let's return to our example of the XYZ company. After you finish creating a list of the company's employees, you are asked to make an electronic time sheet that shows the number of hours that each employee worked during the week. You begin by associating each data point (hours worked) with two labels: employee's name and day of the week. To organize the data, you use the following logical representation.
Now we have a new data structure called a two-dimensional array. We can see how the data structure gets its name by comparing it with a typical array. All the arrays we have seen so far were simply a group of contiguous memory cells. Since computer memory is linear, the arrays were also linear or one-dimensional. Notice, however, that each row of the table above looks like a typical, linear array. Our table is really a collection of one-dimensional arrays with five memory cells. Each memory cell represents a day of the week, and each array in the table represents an employee. Just like a one-dimensional array is a collection of memory cells, a two-dimensional array is a collection of one-dimensional arrays.
You may be wondering how we can represent our two-dimensional array in the computer's memory. The animation below shows the answer to this question by comparing the logical representation (the table) with the physical representation in memory.
As you saw in the animation, it is common to refer to array locations by specifying the row and column numbers after the array name. If we named our table above "Hours" then we could find the number of hours that Aaron worked on Wednesday at the following array location: Hours[1, 3].
We can also have higher dimensional arrays that are collections of lower dimensional arrays. For example, we could organize the time sheet for one month by making a three-dimensional array. This array would be a collection of four weeks of time sheets which are two-dimensional arrays.
Then we could find the number of hours that Aaron worked during the second Wednesday of the month at the following array location: Hours[2, 1, 3]. The '2' represents the second week of the month, the '1' represents the employee Aaron, and the '3' represents Wednesday, the third day of the week.