1. Gyanastra
  2. Data Structures
  3. Arrays and Address Calculation
  4. Random Access and Contiguous Storage in Arrays
Free lesson, no account needed 4 min read 18 practice questions after it
Asked in past papers17 times
  • GATE CSE20252024202220212019201720152007200520041994
  • ISRO2015
  • UGC NET20232017201520142006

Data Structures · Arrays and Address Calculation

Random Access and Contiguous Storage in Arrays

Overview

An array is the simplest data structure that supports random access: any element can be reached directly, without traversing the elements before it.
This works because the array is stored contiguously in memory, so its starting address and element size are enough to compute the location of any element.

Key concepts

  • Array: The simplest data structure that supports random access.
  • Random access: Reaching any element directly, without crossing or traversing all the elements before it.
  • Contiguous storage: The array is stored continuously in memory. This contiguity holds wherever the array is stored — in main memory or on hard disk.
  • Why random access works: Because the array is contiguous and both the size of each element and the starting address of the array are known, the memory location of any element can be computed directly and accessed.
  • Linked list: Nodes are not contiguous — one element can be present here, another there, and their placement can be random.
    The only way to access an element is to go through the chain/list one by one, so random access is not possible.
  • Single-dimensional array: It has nothing much interesting about it — it is stored completely contiguously in memory, and any element can be reached directly.

How it works

  1. The array is stored in main memory continuously (contiguously).
  2. The size of each element is known.
  3. The starting address of the array is known.
  4. From these, the memory location of any desired element is computed directly, and that element is accessed — no traversal of preceding elements is needed.
  5. This contiguity may be in main memory or on hard disk — wherever the array is stored, it is stored contiguously.
  6. In a linked list this is not possible: nodes are non-contiguous and randomly placed, so elements can only be reached by going through the chain one by one.

Comparison

FeatureArrayLinked List
Storage in memoryContiguous (continuous)Non-contiguous (nodes scattered/random)
Random accessPossible — direct access to any elementNot possible
Way to reach an elementDirectly using starting address + element sizeMust traverse the chain/list

Revision summary

  • Arrays are the simplest data structures with random access.
  • Random access works because of contiguous storage + known element size + known starting address.
  • Contiguity applies wherever the array is stored — main memory or hard disk.
  • Linked lists are non-contiguous, so only sequential (chain) access is possible.
  • A one-dimensional array is stored completely contiguously in memory; any element can be reached directly.

Previous-year exam insights

  • Address of an element in a 1-D array: addr(A[i]) = base + i × w, where w is the size of one element in bytes (and indices start at 0;
    for 1-based indexing use base + (i − LB) × w).
    Asked inGATE 2025GATE 2019GATE 2024
  • Pointer arithmetic on an array scales by the element size: if p points to A[i], then p + k points to A[i + k], and the byte difference between two pointers equals (index difference) × sizeof(element); pointer subtraction yields the number of elements, not bytes.
    Asked inGATE 2024GATE 2019GATE 2015
  • A[i] is exactly equivalent to *(A + i), and i[A] is also valid and equal to A[i]; &A[i] equals A + i.
    Asked inGATE 2022GATE 2019GATE 2017
  • Random access in an array costs O(1)O(1) time, whereas accessing the k-th node of a linked list costs O(k)O(k) (O(n)O(n) worst case); insertion/deletion at an arbitrary position is O(n)O(n) in an array (shifting) but O(1)O(1) in a linked list once the position is known.
    Asked inGATE 2021
  • Finding both minimum and maximum of n elements needs at most 3⌈n/2⌉ − 2 comparisons (pairwise comparison method), which is better than the 2n − 2 comparisons of two independent scans.
    Asked inGATE 2021
  • For a 2-D array stored in row-major order, addr(A[i][j]) = base + (i × N + j) × w for an M×N array;
    in column-major order, addr(A[i][j]) = base + (j × M + i) × w (adjust for lower bounds if indexing does not start at 0).
Pages 1–2 of 2