Skip to content
Home » Representation of Linear Arrays in Memory

Representation of Linear Arrays in Memory

✅ Representation of Linear Arrays in Memory


✅ 1. Introduction

A Linear Array is a collection of elements of the same data type stored in continuous (contiguous) memory locations.

✅ Linear arrays are generally represented in memory as:

  • One-Dimensional Arrays (1D)
  • Elements stored sequentially
  • Each element has a fixed memory size

✅ 2. Memory Representation of Linear Array

In a linear array, memory is allocated continuously like this:

📌 Example:

int A[5] = {10, 20, 30, 40, 50};

If each integer takes 4 bytes, then the array is stored in memory as:

IndexElementMemory Address (Example)
A[0]101000
A[1]201004
A[2]301008
A[3]401012
A[4]501016

✅ Here:

  • Base address = address of first element = 1000
  • Each next element = previous address + size of data type

✅ 3. Address Calculation Formula (Important)

✅ Formula:

[
LOC(A[i]) = Base(A) + (i \times W)
]

Where:

  • LOC(A[i]) = address of element at index i
  • Base(A) = address of first element A[0]
  • i = index position
  • W = size of each element in bytes

✅ Example Using Formula

Given:

  • Base address = 1000
  • i = 3
  • W = 4 bytes (integer)

[
LOC(A[3]) = 1000 + (3 \times 4)
= 1000 + 12
= 1012
]

✅ So address of A[3] is 1012


✅ 4. Key Points of Linear Array Representation

✅ Important points:

  1. Array elements are stored in contiguous memory blocks
  2. Access time is very fast using index (Random Access)
  3. Address of any element can be calculated directly
  4. Indexing usually starts from 0 in C, C++, Java, etc.

✅ 5. Diagram Representation (Memory View)

Example:
A = {10, 20, 30, 40, 50}

A[0]   A[1]   A[2]   A[3]   A[4]
10     20     30     40     50
|      |      |      |      |
1000   1004   1008   1012   1016

✅ This shows sequential memory allocation.


✅ 6. Advantages of Memory Representation of Arrays

✅ Benefits:

  • Direct access to any element using index
  • Faster searching and processing in loops
  • Easy to store large number of same-type values
  • Useful in matrix, sorting, searching, etc.

✅ 7. Limitations

❌ Disadvantages:

  • Contiguous memory allocation is required
  • Fixed size in static arrays
  • Insertion and deletion are difficult (shifting needed)

✅ Conclusion

Linear arrays are stored in memory in contiguous locations, which provides fast access using indexing. The address of any element can be found using the formula LOC(A[i]) = Base(A) + (i × W). This makes arrays efficient for accessing data quickly.