What is meant by dimensionality of an Array?
Last Updated :
03 Jun, 2022
The dimension of an array can simply be defined as the number of subscripts or indices required to specify a particular element of the array. Dimension has its own meaning in the real world too and the dimension of an array can be associated with it like:-
1-dimension array can be viewed as 1-axis i.e., a line.
Analogy:
Let's understand the dimensionality of an array by an analogy of a library. In Library, Let's consider books as individual elements. Books are kept on the shelves of the racks in the library where each rack and shelf are indexed. Here, a single shelf can be viewed as a 1-D (1-Dimensional) array of books, then a single rack with several shelves can be considered to be a 2-D (2-Dimensional) array and the complete library with several racks can be viewed as a 3-D (3-Dimensional) array. And we require rack number, shelf number, and position of the book on the shelf to get a particular book from the library. Similarly, an institution can have several libraries on its campus and thus the institution can be viewed as a 4-D (4-Dimensional) array with individual libraries as its elements.
1-D array:
1-D array or 1-Dimensional array requires only one subscript to access the individual element as arr[x], where arr is the array and x is the subscript or the linear index. In real world it can be associated with a line that has only one axis. We can understand a 1-D array as a line holding some value in each integral position.
For example:
Lets consider: arr = {1, 2, 3, 4}
Here, a[0] = 1, a[1] = 2
Note: 1 subscript is used to access the element.
2-D array:
A 2-D array or 2-Dimensional array requires two subscripts to access the individual element as arr[x][y] or arr[x,y], where arr is the array and x and y are the subscripts. In the real world, it can be associated with a plane with two axes, i.e., the x-axis and the y-axis. Mathematically, it can also be viewed as M*N matrix.
For example:
Lets consider, arr = {{1, 2, 3, 4}, {1, 2, 3, 4}, {1, 2, 3, 4}, {1, 2, 3, 4}}
Here, a[0][0] = 1, a[1][2] = 3
Note: 2 subscripts are used to access the element.
3-D array:
3-D array or 3-Dimensional arrays requires three subscripts to access the individual element as arr[x][y][z] or arr[x,y,z], where arr is the array and x, y and z are the subscripts. In the real world, it can be associated with space which has three axes i.e., x-axis, y-axis, and z-axis corresponding to length, breadth, and height.
For example:
Lets consider, arr = {{{1, 2, 3, 4}, {1, 2, 3, 4}, {1, 2, 3, 4}, {1, 2, 3, 4}}, {{1, 2, 3, 4}, {1, 2, 3, 4}, {1, 2, 3, 4}, {1, 2, 3, 4}}, {{1, 2, 3, 4}, {1, 2, 3, 4}, {1, 2, 3, 4},
{1, 2, 3, 4}}, {{1, 2, 3, 4}, {1, 2, 3, 4}, {1, 2, 3, 4}, {1, 2, 3, 4}}
Here, a[0][0][1] = 2, a[1][2][3] = 4
Note: 3 subscripts are used to access the element.
N-D array:
Although the dimensions greater than 3 cannot be viewed in the real world, we can represent N-D (N-Dimensional) array as arr[x1][x2][x3].....[xn] or arr[x1, x2, x3,...., xn], where arr is the array and x1,x2,x3...., xn are the subscripts. Declaration of an array should also be done keeping dimensions in mind.
Similar Reads
One Dimensional Arrays in C++ One-dimensional arrays are like a row of boxes where you can store things where each box can hold one item, such as a number or a word. For example, in an array of numbers, the first box might hold 5, the second 10, and so on. You can easily find or change what's in each box by referring to its posi
6 min read
One Dimensional Arrays in C In C, an array is a collection of elements of the same type stored in contiguous memory locations. This organization allows efficient access to elements using their index. Arrays can also be of different types depending upon the direction/dimension they can store the elements. It can be 1D, 2D, 3D,
5 min read
One Dimensional Array in Java An array is a type of data structure that can store a collection of elements. These elements are stored in contiguous memory locations and provide efficient access to each element based on the index of each array element.In this article, we will learn about a one-dimensional array in Java.What is an
7 min read
Multi-Dimensional Arrays in Objective-C Arrays are basically defined as linear data structures that are used to store similar types of data elements. Arrays can be single-dimensional or multi-dimensional. Â As the name suggests that multi-dimensional means it is a data structure that is used to store similar types of data like(integers, fl
5 min read
What is a Dimension Table? In the field of data warehousing, one of the key table typesâthe dimension tableâtakes the central stage and performs an expansive role in the arrangement of data. For clarification, these types of tables are used in a star or snowflake schema and are useful in presenting descriptive attributes of f
10 min read