Data Structures: Derivation of Index Formula for 1-D, 2-D, and Multi-D Arrays
Course Overview and Learning Objectives
Course Information:
Course Name: Data Structures
Course Code: R1UC302B
Session Number: 5
Instructor: Mriganka Shekhar Das
Class Duration: 50 mins
Date of Conduction: 16 Aug 2026
Instructional Framework: GSCALE (Galgotias Student Centered Active Learning Ecosystem), which incorporates Critical Thinking, Collaboration, Learning Engagement, and Experiential Learning.
Session Learning Outcomes:
Calculate the memory address of any given element in 1D, 2D, and 3D arrays under various storage orders using formal address formulas.
Explain the step-by-step derivation process of index formulas for 1-D, 2-D, and multi-D arrays in both row-major and column-major order.
Array Classification and Storage Orders
Array Types Based on Size:
Fixed Size Array: Memory size is predetermined during declaration and cannot be resized during runtime.
Dynamic Size Array: Memory size can grow or shrink dynamically during program execution.
Array Types Based on Dimensions:
One-Dimensional (1D) Array: A linear sequence of elements stored in contiguous memory locations.
Multi-Dimensional Array: Higher-dimensional structures, including Two-Dimensional (2D) Arrays, Three-Dimensional (3D) Arrays, and higher dimensions.
Two-Dimensional Storage Orders:
Row-Major Order: Matrix elements are stored in memory row by row sequentially. For a matrix containing elements , the row-major memory sequence is:
Column-Major Order: Matrix elements are stored in memory column by column sequentially. For the same matrix, the column-major memory sequence is:
Warm-Up Problem: Theater Ticket Sales Calculation
Problem Scenario:
A theater auditorium contains 20 rows, with 30 seats in each row.
Each ticket costs .
Tickets are sold seat by seat in row-major order (from left to right in a row, then proceeding to the first seat of the next row).
The last ticket sold was for Row 7, Seat 12.
Step-by-Step Calculation:
Fully sold rows: Row 1 through Row 6 = .
Total seats sold in full rows = .
Seats sold in Row 7 = Seats 1 through 12 = .
Total tickets sold = .
Total money collected = ().
Address Calculation in One-Dimensional (1D) Arrays
Parameters and Definitions:
Base Address (): The actual memory address of the first element in the array.
Element Width (): The memory space acquired by each individual element in bytes.
Lower Bound (): The starting index or lower limit of the subscript (assumed to be if not explicitly provided).
Index (): The specific subscript location of the element whose address is being calculated.
Address Calculation Formula:
Concrete Memory Example:
Given Base Address .
Given Element Width .
Given Lower Bound .
Array Elements: stored at indices .
Memory addresses calculated for each index:
Address of
Address of
Address of
Address of
Address of
Address of
Address Calculation in Two-Dimensional (2D) Arrays
Row-Major Order Calculation:
Formula:
Parameter Definitions:
: Row index of the target element.
: Column index of the target element.
: Base address of the array.
: Memory size of one array element in bytes.
: Lower limit of row index / starting row index (default is if omitted).
: Lower limit of column index / starting column index (default is if omitted).
: Total number of columns in the matrix.
Column-Major Order Calculation:
Formula:
Parameter Definitions:
: Total number of rows in the matrix.
All other parameters (, , , , , ) carry identical definitions to the Row-Major Order formula.
Address Calculation in Multi-Dimensional (3D) Arrays
Row-Major Order Formula for 3D Array :
Column-Major Order Formula for 3D Array :
Parameter Definitions for 3D Array Formulas:
: Base Address (start address of the array).
: Weight / storage size of one element in bytes.
: Height / Layer (total number of cells depth-wise).
: Total number of rows.
: Total number of columns.
: Lower Bound of Row index ().
: Lower Bound of Column index ().
: Lower Bound of Height/Depth index ().
Peer Learning Activities and Problem Solutions
Peer Learning Activity Design:
Group Structure: 6 members split into 3 pairs.
Task Distribution:
Pair 1: 1D Array Problem
Pair 2: 2D Array Row-Major Order Problem
Pair 3: 2D Array Column-Major Order Problem
Timing Protocol: Total 5 minutes (2 minutes individual problem-solving, followed by 3 minutes pair discussion and consensus).
Comparison Phase: Pairs present solutions to the entire group and compare formula structures across array types.
Problem 1 (1D Array Address Calculation):
Problem Statement: An array is stored in memory with base address . Each element takes . Find the address of .
Given Data: , , ,
Derivation:
Problem 2 (2D Array Row-Major Order Calculation):
Problem Statement: A matrix is stored in row-major order. Base address = , element size = . Find the address of .
Given Data: , , , , ,
Matrix Dimensions: Rows , Columns
Derivation:
Problem 3 (2D Array Column-Major Order Calculation):
Problem Statement: A matrix is stored in column-major order. Base address = , element size = . Find the address of .
Given Data: , , , , ,
Matrix Dimensions: Rows , Columns
Derivation:
Summary of Array Address Formulas
1D Array:
Formula:
Parameters: = Base address, = Size of one element (bytes), = Lower bound of index.
2D Array (Row-Major Order):
Formula:
Parameters: = Base address, = Element size, = Row lower bound, = Column lower bound, = Number of columns.
2D Array (Column-Major Order):
Formula:
Parameters: = Number of rows, all other symbols identical to Row-Major Order.
3D Array (Row-Major Order):
Formula:
Parameters: = Base address, = Element size, = Depth/Height, = Rows, = Columns, = Lower bounds for row, column, and depth.
3D Array (Column-Major Order):
Formula:
Parameters: Identical parameter definitions to 3D Row-Major Order.
Assessment and Next Session Preview
Learning Outcome Verification:
Confirmation of formula application for memory addresses across 1D, 2D, and 3D arrays.
Mastery of formula derivation steps for Row-Major and Column-Major memory layouts.
Interactive Assessment Tools and Review:
Pre-Assessment Lecture 05 - DS
Post-Assessment Lecture 05 - DS
Interactive reinforcement tools: WooClap and WooFlash.
Next Session Topics:
Practical Applications of Arrays
Sparse Matrices
Memory Representations of Sparse Matrices