Array Address Calculation in Data Structure: 1D, 2D, 3D & N-D Arrays with Formulas and Examples
Array address calculation often looks difficult because students see many formulas together and start memorising them without understanding the logic. In reality, every formula is solving the same simple problem: how many array elements must be skipped before reaching the required element?
Once this idea is clear, calculating the address of an element in a 1D, 2D, 3D or even N-dimensional array becomes much easier.
What is Array Address Calculation?
When an array is stored in computer memory, every element occupies a particular memory location. The address of the first element is normally called the base address.
To find any other element, we calculate how far that element is located from the first element.
This basic idea remains the same for every type of array. Only the method used to calculate the offset changes as the number of dimensions increases.
Important Terms Before Learning the Formulas
Base Address
The memory address where the array begins.
It is commonly represented by BA.
Element Size
The number of bytes required to store one array element.
It is usually represented by w.
Lower Bound
The smallest valid index of a dimension.
It may be 0, 1 or another value depending on the question.
Why is Array Address Calculation Important?
Array address calculation is not only a formula-based university topic. It explains how an array that looks logical in a program is mapped to real memory.
The concept helps students understand:
- how arrays are stored in contiguous memory,
- why array indexing can be fast,
- how multidimensional arrays are converted into linear memory,
- how Row Major and Column Major storage work,
- how compilers locate array elements, and
- how memory organisation affects data access.
1D Array Address Calculation
A one-dimensional array is the easiest case because all elements are arranged in a single sequence.
Consider:
To reach A[i], we simply count how many elements exist before index i.
1D Array Formula
where:
BA = Base Address
w = Size of each element
i = Required index
LB = Lower Bound
Zero-Based 1D Formula
If indexing starts from 0:
1D Array Solved Example
Suppose:
LOC(A[i]) = BA + w × i
LOC(A[6]) = 1000 + 4 × 6
4 × 6 = 24 bytes
1000 + 24 = 1024
1D Array Example with Lower Bound
Suppose an array is declared logically as:
Given:
Base Address = 2000
Element Size = 2 bytes
Find the address of A[9].
2D Array Address Calculation
A two-dimensional array has rows and columns.
For example:
This array contains:
However, computer memory is linear. Therefore, the rows and columns must be converted into one continuous sequence.
Two common storage methods are used:
Row Major Order
Complete rows are stored one after another.
Column Major Order
Complete columns are stored one after another.
2D Array Address Formula in Row Major Order
Suppose:
where:
M = Number of rows
N = Number of columns
Zero-Based Formula
General Formula with Lower Bounds
Row Major means complete rows are skipped first. Since every row contains N columns, multiply the row index by the number of columns.
Row Major → i × Columns + j
2D Row Major Solved Example
Suppose:
Find the address of A[2][1].
2D Array Address Formula in Column Major Order
In Column Major Order, complete columns are stored first.
Zero-Based Formula
General Formula with Lower Bounds
Column Major skips complete columns first. Every complete column contains M rows.
Column Major → j × Rows + i
2D Column Major Solved Example
Use the same array:
Find the address of A[2][1].
3D Array Address Calculation
A three-dimensional array may look difficult at first because it contains three indices.
Consider:
You can imagine it as multiple 2D tables placed one behind another.
X
Y
Z
The total number of elements is:
3D Array Row Major Formula
For a zero-based array:
Why Does This Formula Work?
To reach A[i][j][k]:
- first skip i complete 2D blocks,
- then skip j complete rows inside the selected block,
- then move k elements inside the required row.
General 3D Row Major Formula
Here N₂ and N₃ represent the sizes of the second and third dimensions.
3D Row Major Solved Example
Consider:
3D Array Column Major Formula
In Column Major Order, earlier dimensions change faster in memory.
For a zero-based array:
The same formula may also be written as:
General 3D Column Major Formula
3D Column Major Example
For:
What is an N-Dimensional Array?
An N-dimensional array is simply an array containing any number of dimensions.
Examples:
| Array | Dimensions | Example |
|---|---|---|
| 1D | 1 Dimension | A[i] |
| 2D | 2 Dimensions | A[i][j] |
| 3D | 3 Dimensions | A[i][j][k] |
| 4D | 4 Dimensions | A[i][j][k][l] |
| N-D | N Dimensions | A[i₁][i₂]...[iâ‚™] |
N-Dimensional Array Address Calculation
Instead of memorising a new formula for every dimension, understand the pattern.
For Row Major Order, each index is multiplied by the total size of all dimensions that come after it.
For Column Major Order, each index is multiplied by the total size of dimensions that come before it.
N-D Array Row Major Formula
For an N-dimensional array:
with zero-based indexing, the Row Major element offset follows this pattern:
Therefore:
In Row Major Order, look to the right of an index and multiply the sizes of all dimensions present there.
N-D Array Column Major Formula
In Column Major Order, the multiplication pattern works in the opposite direction.
Therefore:
In Column Major Order, look to the left of an index and multiply the dimensions that come before it.
4D Example to Understand the N-D Pattern
Suppose:
For element:
Row Major Offset
So:
Column Major Offset
Therefore:
This same pattern continues even if the array contains five, six or more dimensions.
How to Solve Array Address Numerical Questions
One Formula Pattern You Should Understand
Row Major
Multiply an index by the sizes of dimensions that come after it.
Column Major
Multiply an index by the sizes of dimensions that come before it.
Row Major vs Column Major Formula Pattern
| Array Type | Row Major Offset | Column Major Offset |
|---|---|---|
| 1D | i | i |
| 2D | iN₂ + j | i + jN₁ |
| 3D | iN₂N₃ + jN₃ + k | i + jN₁ + kN₁N₂ |
| 4D | iN₂N₃N₄ + jN₃N₄ + kN₄ + l | i + jN₁ + kN₁N₂ + lN₁N₂N₃ |
| N-D | Multiply using dimensions toward the right | Multiply using dimensions toward the left |
Common Mistakes in Array Address Calculation
1. Forgetting the element size
Finding the element position is not enough. Multiply the offset by the number of bytes used by each element.
2. Forgetting the lower bound
If indexing starts from 1 or 5, do not use the index directly. Subtract the lower bound first.
3. Using rows instead of columns in 2D Row Major
Row Major uses the number of columns.
4. Using columns instead of rows in 2D Column Major
Column Major uses the number of rows.
5. Mixing Row Major and Column Major formulas
Identify the storage order before starting the numerical.
6. Adding base address before completing the offset calculation
Calculate the complete byte displacement first, then add it to BA.
7. Memorising 3D formulas without understanding dimensions
Learn the multiplication pattern instead. It also helps with 4D and N-D questions.
Best Memory Trick for Exams
1D: Count elements before the required index.
2D Row Major: Row × Columns + Column
2D Column Major: Column × Rows + Row
3D Row Major: Multiply using dimensions on the right side.
3D Column Major: Multiply using dimensions on the left side.
N-D: Continue the same direction-based pattern.
Quick Formula Sheet
1D Array
2D Row Major
2D Column Major
3D Row Major
3D Column Major
N-D Array
Use the same dimension-product pattern according to Row Major or Column Major storage.
Exam Questions with Answers
Q1. What is the base address of an array?
The base address is the memory address of the first element of an array. The addresses of other elements are calculated relative to this location.
Q2. What is an array offset?
An array offset represents the distance of a required element from the first element of the array. After multiplying the element offset by element size, we get the byte offset.
Q3. Write the formula for a 1D array.
Q4. Write the 2D Row Major formula.
Q5. Write the 2D Column Major formula.
Q6. What is the main difference between Row Major and Column Major Order?
Row Major stores complete rows consecutively, while Column Major stores complete columns consecutively.
5-Mark Exam Answer: Array Address Calculation
Array address calculation is the process of determining the memory location of a particular element of an array. An array is generally stored in contiguous memory locations, and the address of the first element is called the base address.
For a one-dimensional array, the address can be calculated using:
For a two-dimensional array stored in Row Major Order:
For Column Major Order:
For higher-dimensional arrays, the same principle is extended by multiplying indices with appropriate dimension sizes. Therefore, every address calculation is based on the base address, element size, lower bounds and position of the required element.
10-Mark Exam Answer: Address Calculation of 1D, 2D and 3D Arrays
Arrays store elements of the same data type, normally in consecutive memory locations. Although multidimensional arrays are represented using rows, columns and other dimensions, physical computer memory is linear. Therefore, the compiler needs a formula to convert array indices into a memory address.
The general principle is:
For a one-dimensional array:
For a two-dimensional array stored in Row Major Order:
In Column Major Order:
For a three-dimensional array stored in Row Major Order:
For Column Major Order:
The same logic can be extended to N-dimensional arrays. In Row Major Order, each index is multiplied by the sizes of dimensions that follow it. In Column Major Order, multiplication uses the dimensions that appear before it.
Thus, understanding the offset calculation is more useful than memorising separate formulas for every possible dimension.
Quick Revision Before Exam
Frequently Asked Questions
What is the easiest way to calculate an array address?
First calculate how many elements appear before the required element. Multiply this number by the size of one element and add the result to the base address.
Why do we multiply by the size of an element?
Array indices count elements, while memory addresses are based on bytes. Multiplying by element size converts the element offset into a byte offset.
What happens if the lower bound is zero?
If the lower bound is zero, terms such as (i − L) simply become i. This makes the formula shorter.
Can a 2D array have both Row Major and Column Major representations?
Yes. Both are valid memory-layout methods. Which one is used depends on the language, environment or system being considered.
How can I remember the 3D Row Major formula?
Start from the first index and multiply it by the sizes of all dimensions to its right. For the next index, multiply by the remaining dimensions. The final index is added directly.
How can I remember the N-D formula?
Do not memorise one giant formula. Remember the direction rule: Row Major looks right, Column Major looks left. This pattern can be extended to any number of dimensions.
Are array address calculation questions important for exams?
Yes. They are common numerical and theory questions because they test both array concepts and memory representation. Understanding the method is more reliable than memorising a single solved example.
