Array Address Calculation in Data Structure: 1D, 2D, 3D & N-D Arrays with Formulas and Examples

Chapter 12 • Data Structure

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.

Quick Answer: The memory address of an array element is calculated by adding its offset to the base address of the array. The offset depends on the element position, size of each element, array dimensions, lower bounds and whether the multidimensional array uses Row Major or Column Major Order.

What is Array Address Calculation?

Array Address Calculation in Data Structure: 1D, 2D, 3D & N-D Arrays with Formulas and Examples

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.

Base Address + Element Offset = Required Address
Basic Address Principle Address of Element = Base Address + Byte Offset

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.

Example: If an integer requires 4 bytes and an array starts at memory location 1000, the next element normally begins at address 1004, followed by 1008, 1012 and so on.

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:

A[0] → A[1] → A[2] → A[3] → A[4]

To reach A[i], we simply count how many elements exist before index i.

1D Array Formula

General 1D Formula LOC(A[i]) = BA + w × (i − LB)

where:

BA = Base Address
w = Size of each element
i = Required index
LB = Lower Bound

Zero-Based 1D Formula

If indexing starts from 0:

LOC(A[i]) = BA + w × i

1D Array Solved Example

Suppose:

A[10] Base Address = 1000 Element Size = 4 bytes Find Address of A[6]
Use the zero-based formula:
LOC(A[i]) = BA + w × i
Substitute the values:
LOC(A[6]) = 1000 + 4 × 6
Calculate the offset:
4 × 6 = 24 bytes
Add the offset to the base address:
1000 + 24 = 1024
Final Answer: Address of A[6] = 1024.

1D Array Example with Lower Bound

Suppose an array is declared logically as:

A[5...14]

Given:

Base Address = 2000
Element Size = 2 bytes

Find the address of A[9].

LOC(A[9]) = 2000 + 2 × (9 − 5) = 2000 + 2 × 4 = 2000 + 8 = 2008
Answer: Address of A[9] = 2008.

2D Array Address Calculation

A two-dimensional array has rows and columns.

For example:

A[3][4]

This array contains:

3 Rows × 4 Columns = 12 Elements

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:

A[M][N]

where:

M = Number of rows
N = Number of columns

Zero-Based Formula

2D Row Major Formula LOC(A[i][j]) = BA + w × [(i × N) + j]

General Formula with Lower Bounds

LOC(A[i][j]) = BA + w × [(i − L₁) × N + (j − L₂)]
Memory Trick:

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:

A[3][4] Base Address = 2000 Element Size = 4 bytes

Find the address of A[2][1].

LOC(A[2][1]) = 2000 + 4 × [(2 × 4) + 1] = 2000 + 4 × [8 + 1] = 2000 + 4 × 9 = 2000 + 36 = 2036
Final Answer: Row Major address of A[2][1] = 2036.

2D Array Address Formula in Column Major Order

In Column Major Order, complete columns are stored first.

Zero-Based Formula

2D Column Major Formula LOC(A[i][j]) = BA + w × [(j × M) + i]

General Formula with Lower Bounds

LOC(A[i][j]) = BA + w × [(j − L₂) × M + (i − L₁)]
Memory Trick:

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:

A[3][4] Base Address = 2000 Element Size = 4 bytes

Find the address of A[2][1].

LOC(A[2][1]) = 2000 + 4 × [(1 × 3) + 2] = 2000 + 4 × 5 = 2000 + 20 = 2020
Final Answer: Column Major address of A[2][1] = 2020.

3D Array Address Calculation

A three-dimensional array may look difficult at first because it contains three indices.

Consider:

A[X][Y][Z]

You can imagine it as multiple 2D tables placed one behind another.

Dimension 1
X
×
Dimension 2
Y
×
Dimension 3
Z

The total number of elements is:

Total Elements = X × Y × Z

3D Array Row Major Formula

For a zero-based array:

3D Row Major Formula LOC(A[i][j][k]) = BA + w × [(i × Y × Z) + (j × Z) + k]

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.
Complete blocks skipped = i × Y × Z Complete rows skipped = j × Z Final movement = k

General 3D Row Major Formula

LOC(A[i][j][k]) = BA + w × [ (i − L₁) × N₂ × N₃ + (j − L₂) × N₃ + (k − L₃) ]

Here N₂ and N₃ represent the sizes of the second and third dimensions.

3D Row Major Solved Example

Consider:

A[2][3][4] Base Address = 5000 Element Size = 2 bytes Find A[1][2][3]
LOC(A[1][2][3]) = 5000 + 2 × [(1 × 3 × 4) + (2 × 4) + 3] = 5000 + 2 × [12 + 8 + 3] = 5000 + 2 × 23 = 5000 + 46 = 5046
Final Answer: Address of A[1][2][3] = 5046.

3D Array Column Major Formula

In Column Major Order, earlier dimensions change faster in memory.

For a zero-based array:

3D Column Major Formula LOC(A[i][j][k]) = BA + w × [i + (j × X) + (k × X × Y)]

The same formula may also be written as:

BA + w × [(k × X × Y) + (j × X) + i]

General 3D Column Major Formula

LOC(A[i][j][k]) = BA + w × [ (i − L₁) + (j − L₂) × N₁ + (k − L₃) × N₁ × N₂ ]

3D Column Major Example

For:

A[2][3][4] BA = 5000 w = 2 bytes Find A[1][2][3]
LOC(A[1][2][3]) = 5000 + 2 × [ 1 + (2 × 2) + (3 × 2 × 3) ] = 5000 + 2 × [1 + 4 + 18] = 5000 + 2 × 23 = 5046
In this particular example, the selected position produces the same final offset in both layouts. This is possible for some index combinations. It does not mean Row Major and Column Major formulas are always the same.

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:

A[N₁][N₂][N₃] ... [Nâ‚™]

with zero-based indexing, the Row Major element offset follows this pattern:

Offset = i₁(N₂N₃...Nâ‚™) + i₂(N₃N₄...Nâ‚™) + i₃(N₄N₅...Nâ‚™) + ... + iâ‚™

Therefore:

N-D Row Major Address Address = BA + w × Offset
Easy Rule:

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.

Offset = i₁ + i₂N₁ + i₃(N₁N₂) + i₄(N₁N₂N₃) + ...

Therefore:

N-D Column Major Address Address = BA + w × Offset
Easy Rule:

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:

A[2][3][4][5]

For element:

A[i][j][k][l]

Row Major Offset

Offset = i × (3 × 4 × 5) + j × (4 × 5) + k × 5 + l

So:

Offset = 60i + 20j + 5k + l

Column Major Offset

Offset = i + j × 2 + k × (2 × 3) + l × (2 × 3 × 4)

Therefore:

Offset = i + 2j + 6k + 24l

This same pattern continues even if the array contains five, six or more dimensions.

How to Solve Array Address Numerical Questions

Identify the number of dimensions: 1D, 2D, 3D or N-D.
Write down the base address.
Identify the size of one element in bytes.
Check whether the array uses Row Major or Column Major Order.
Check whether indexing begins from 0, 1 or another lower bound.
Calculate the element offset.
Multiply the element offset by the element size.
Finally, add the result to the base address.

One Formula Pattern You Should Understand

Row Major

Multiply an index by the sizes of dimensions that come after it.

3D: i(N₂N₃) + j(N₃) + k

Column Major

Multiply an index by the sizes of dimensions that come before it.

3D: i + j(N₁) + k(N₁N₂)

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

BA + w(i − LB)

2D Row Major

BA + w[ (i − L₁)N₂ + (j − L₂) ]

2D Column Major

BA + w[ (j − L₂)N₁ + (i − L₁) ]

3D Row Major

BA + w[ (i − L₁)N₂N₃ + (j − L₂)N₃ + (k − L₃) ]

3D Column Major

BA + w[ (i − L₁) + (j − L₂)N₁ + (k − L₃)N₁N₂ ]

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.

LOC(A[i]) = BA + w(i − LB)

Q4. Write the 2D Row Major formula.

LOC(A[i][j]) = BA + w[ (i − L₁)N₂ + (j − L₂) ]

Q5. Write the 2D Column Major formula.

LOC(A[i][j]) = BA + w[ (j − L₂)N₁ + (i − L₁) ]

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:

LOC(A[i]) = BA + w(i − LB)

For a two-dimensional array stored in Row Major Order:

LOC(A[i][j]) = BA + w[ (i − L₁)N₂ + (j − L₂) ]

For Column Major Order:

LOC(A[i][j]) = BA + w[ (j − L₂)N₁ + (i − L₁) ]

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:

Required Address = Base Address + Byte Offset

For a one-dimensional array:

LOC(A[i]) = BA + w(i − LB)

For a two-dimensional array stored in Row Major Order:

LOC(A[i][j]) = BA + w[ (i − L₁)N₂ + (j − L₂) ]

In Column Major Order:

LOC(A[i][j]) = BA + w[ (j − L₂)N₁ + (i − L₁) ]

For a three-dimensional array stored in Row Major Order:

LOC(A[i][j][k]) = BA + w[ (i − L₁)N₂N₃ + (j − L₂)N₃ + (k − L₃) ]

For Column Major Order:

LOC(A[i][j][k]) = BA + w[ (i − L₁) + (j − L₂)N₁ + (k − L₃)N₁N₂ ]

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

Base Address Starting location of array
w Size of one element
Offset Distance from first element
1D i − LB
Row Major Dimensions toward right
Column Major Dimensions toward left
2D Row Major i × Columns + j
2D Column Major j × Rows + i
Final Step BA + w × Offset

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.

Tags

Post a Comment

0 Comments
* Please Don't Spam Here. All the Comments are Reviewed by Admin.
Join Telegram Exam updates and free resources