</>
ShikshaCSLearn. Code. Grow.
šŸ”
ā˜• Support Us
ShikshaCS›Notes›Data Structures & Algorithms
Data Structures & Algorithms
šŸ•’ 8 min read

Arrays

The simplest, most-used data structure — and where every DSA journey begins.

What is an Array?

An array is a collection of elements of the same type, stored in contiguous memory locations, accessed using an index. Because memory is contiguous, accessing any element by index takes constant time, O(1).

int arr[5] = {10, 20, 30, 40, 50};
printf("%d", arr[2]); // prints 30

Common Operations & Complexity

Access by index: O(1). Search (unsorted): O(n). Insertion/Deletion at the end: O(1) (amortized for dynamic arrays). Insertion/Deletion in the middle: O(n), since remaining elements must shift.

When Arrays Aren't Ideal

If your program needs frequent insertions/deletions in the middle, a linked list may perform better. Arrays shine when you need fast random access and know the size in advance.

šŸŒ Real-World Use

Image pixels are stored as 2D arrays (rows and columns of color values). Spreadsheets like Excel are essentially 2D arrays. A leaderboard showing top scores is usually a sorted array.

šŸ’” Pro Tip

Two-pointer technique (one pointer from the start, one from the end, moving toward each other) solves a huge chunk of array interview questions — like finding a pair with a target sum in a sorted array — in O(n) instead of O(n²).

🧪 Quick Self-Test

Check what you just learned — no pressure, just practice.

1. What is the time complexity of accessing an array element by index?

2. Why is inserting in the middle of an array slow?

← Back to all Notes