Created
Feb 2, 2026
Last Modified
2 months ago

Array

Array

ARRAY โ€“ Short Notes

๐Ÿ”น Definition

An array is a collection of similar data types stored in contiguous memory locations and accessed using an index.

Example:
int arr[5] = {10, 20, 30, 40, 50};


๐Ÿ”น Key Characteristics

  • Stores homogeneous data (same data type)

  • Fixed size (size must be defined at creation)

  • Elements are stored in continuous memory

  • Indexing usually starts from 0

  • Fast access using index (O(1))


๐Ÿ”น Types of Arrays

1. One-Dimensional Array (1D)

Stores elements in a single row.

Example:

go
int arr[5] = {1, 2, 3, 4, 5};

2. Two-Dimensional Array (2D)

Used to store data in rows and columns (matrix form).

Example:

c
int mat[2][3] = {{1,2,3},{4,5,6}};

3. Multi-Dimensional Array

Arrays with more than two dimensions (rarely used).


๐Ÿ”น Declaration & Initialization

Declaration

c
datatype arrayName[size];

Initialization

c
int a[3] = {10, 20, 30};

๐Ÿ”น Accessing Array Elements

Using index:

c
a[0] = 10;
printf("%d", a[1]);

๐Ÿ”น Memory Representation

  • If base address = B

  • Size of each element = w

  • Address of arr[i] =

    B + (i ร— w)


๐Ÿ”น Common Array Operations

Operation

Description

Time Complexity

Traversal

Access all elements

O(n)

Insertion

Add element

O(n)

Deletion

Remove element

O(n)

Searching (Linear)

Search sequentially

O(n)

Searching (Binary)

On sorted array

O(log n)

Updating

Modify element

O(1)


๐Ÿ”น Advantages

โœ… Fast access

โœ… Easy to use

โœ… Efficient for storing fixed-size data


๐Ÿ”น Disadvantages

โŒ Fixed size

โŒ Memory wastage possible

โŒ Insertion & deletion are costly

โŒ Cannot store different data types


๐Ÿ”น Applications of Arrays

  • Searching & Sorting algorithms

  • Matrix operations

  • Stack & Queue implementation

  • Graphs and Dynamic Programming

  • Storing large datasets