Interactive Guide to Arrays & Applications

Introduction to Arrays

An array is a collection of items of the same data type stored at contiguous memory locations. Elements are identified by an index or a key.

Dimensions of Arrays

One-Dimensional Array

A linear sequence of elements.

10[0]
20[1]
30[2]
40[3]

Two-Dimensional Array

A grid of elements in rows and columns.

10
20
30
40

Multi-Dimensional Array

An array of arrays (e.g., a cube).

2D Array Memory Representation

In memory, a 2D array is flattened into a 1D sequence. This can be done in two ways: Row-Major or Column-Major order. Use the calculator below to see how the memory address of an element is calculated.

Address Calculator

Results

Row-Major Order

Address = base + (i * num_cols + j) * size

Column-Major Order

Address = base + (j * num_rows + i) * size

Application: Polynomials

Arrays (especially arrays of structures) are an efficient way to represent polynomials, storing only the non-zero terms.

Polynomial to Array Representation

Structured Array Representation

Application: Sparse Matrices

A sparse matrix is a matrix with very few non-zero elements. Storing it as a full matrix is inefficient. Instead, we store only the non-zero elements in a "triplet" format (row, column, value).

Interactive Matrix (5x5)

Click cells to toggle non-zero values.

Triplet Representation

Thriveni C

Assistant Professor, Computer Science Engineering

MVJ College of Engineering

Whitefield, Bengaluru 560067