Calculate the address of any element in the 3-D Array

3-Dimensional array is a collection of 2-Dimensional arrays. It is specified by using three subscripts:

  1. Block size
  2. Row size
  3. Column size

More dimensions in an array mean more data can be stored in that array. 

Example:

3-D Array

To find the address of any element in 3-Dimensional arrays there are the following two ways:

  • Row Major Order
  • Column Major Order

Row Major Order:

To find the address of the element using row-major order, use the following formula:

Address of A[i][j][k] = B + W *(M * N * (i-x) + N *(j-y) + (k-z))

Here:

B = Base Address (start address)
W = Weight (storage size of one element stored in the array)
M = Row (total number of rows)
N = Column (total number of columns)
P = Width (total number of cells depth-wise)
x = Lower Bound of Row
y = Lower Bound of Column
z = Lower Bound of Width

Example: Given an array, arr[1:9, -4:1, 5:10] with a base value of 400 and the size of each element is 2 Bytes in memory find the address of element arr[5][-1][8] with the help of row-major order?

Solution:

Given:
Block Subset of an element whose address to be found I = 5
Row Subset of an element whose address to be found J = -1 
Column Subset of an element whose address to be found K = 8
Base address B = 400
Storage size of one element store in any array(in Byte) W = 2
Lower Limit of blocks in matrix x = 1
Lower Limit of row/start row index of matrix y = -4 
Lower Limit of column/start column index of matrix z = 5
M(row) = Upper Bound – Lower Bound + 1 = 1 – (-4) + 1 = 6
N(Column)= Upper Bound – Lower Bound + 1 = 10 – 5 + 1 = 6
 

Formula used:                                                
Address of[I][J][K] =B + W (M * N(i-x) + N *(j-y) + (k-z))

Solution:
Address of arr[5][-1][8] = 400 + 2 * {[6 * 6 * (5 – 1)] + 6 * [(-1 + 4)]} + [8 – 5]
                             = 400 + 2 * (6*6*4)+(6*3)+3
                            = 400 + 2 * (165)
                           = 730

Column Major Order:

To find the address of the element using column-major order, use the following formula:1

Address of A[i][j][k]= B + W(M * N(i – x) + M *(k – z) + (j – y))

Here:

B = Base Address (start address)
W = Weight (storage size of one element stored in the array)
M = Row (total number of rows)
N = Column (total number of columns)
P = Width (total number of cells depth-wise)
x = Lower Bound of block (first subscipt)
y = Lower Bound of Row
z = Lower Bound of Column

Example: Given an array arr[1:8, -5:5, -10:5] with a base value of 400 and the size of each element is 4 Bytes in memory find the address of element arr[3][3][3] with the help of column-major order ?

Solution:

Given:
Row Subset of an element whose address to be found I = 3
Column Subset of an element whose address to be found J = 3
Block Subset of an element whose address to be found K = 3
Base address B = 400
Storage size of one element store in any array(in Byte) W = 4
Lower Limit of blocks in matrix x = 1
Lower Limit of row/start row index of matrix y = -5
Lower Limit of column/start column index of matrix z = -10
M (row)= Upper Bound – Lower Bound + 1 = 5 +5 + 1 = 11
N (column)= Upper Bound – Lower Bound + 1 = 5 + 10 + 1 = 16

Formula used:
Address of[i][j][k] = B + W(M * N(i – x) + M * (j-y) + (k – z))

Solution:
Address of arr[3][3][3] = 400 + 4 * ((11*16*(3-1)+11*(3-(-5)+(3-(-10)))
                                    = 400 + 4 * ((176*2 + 11*8 + 13)
                                   = 400 + 4 * (453)
                                  = 400 + 1812
                                 = 2212

Array Notes for GATE Exam [2024]

Arrays are fundamental data structures in computer science, and mastering them is crucial for success in the GATE exam. This article aims to provide concise yet comprehensive notes on arrays, covering essential concepts and strategies to help you tackle array-related questions in the GATE 2024 exam.

Table of Content

  • Introduction to Arrays
  • Basic terminologies of the array
  • Representation of Array
  • Types of arrays
  • Finding Adress of an Element in Array
  • Calculating the address of any element In the 1-D array
  • Calculate the address of any element in the 2-D array
  • Calculate the address of any element in the 3-D Array
  • Previously Asked GATE Questions on Arrays

Similar Reads

Introduction to Arrays:

An array is a collection of items of the same variable type that are stored at contiguous memory locations. It’s one of the most popular and simple data structures and is often used to implement other data structures. Each item in an array is indexed starting with 0....

Basic terminologies of the array:

Array Index: In an array, elements are identified by their indexes. Array index starts from 0. Array element: Elements are items stored in an array and can be accessed by their index. Array Length: The length of an array is determined by the number of elements it can contain....

Representation of Array:

The representation of an array can be defined by its declaration. A declaration means allocating memory for an array of a given size....

Types of arrays:

...

Finding Adress of an Element in Array

...

Calculating the address of any element In the 1-D array:

...

Calculate the address of any element in the 2-D array:

...

Calculate the address of any element in the 3-D Array:

...

Previously Asked GATE Questions on Arrays:

...

Contact Us