NeetCode
PracticeCoursesRoadmap
Sign InPro
PracticeCoursesRoadmap
Sign InPro
CoursesAlgorithms & Data Structures for Beginners

Progress

3/35

About

  • 0IntroductionFREE1m

Arrays

  • 1RAMFREE6m
  • 2Static Arrays15m
  • 3Dynamic Arrays16m
  • 4Stacks4m

Linked Lists

  • 5Singly Linked ListsFREE12m
  • 6Doubly Linked Lists10m
  • 7Queues4m

Recursion

  • 8Factorial11m
  • 9Fibonacci Sequence13m

Sorting

  • 10Insertion Sort19m
  • 11Merge Sort22m
  • 12Quick Sort17m
  • 13Bucket Sort14m

Binary Search

  • 14Search Array16m
  • 15Search Range8m

Trees

  • 16Binary Tree11m
  • 17Binary Search Tree15m
  • 18BST Insert and Remove22m
  • 19Depth-First Search15m
  • 20Breadth-First Search11m
  • 21BST Sets and Maps6m

Backtracking

  • 22Tree Maze14m

Heap / Priority Queue

  • 23Heap Properties14m
  • 24Push and Pop18m
  • 25Heapify15m

Hashing

  • 26Hash Usage10m
  • 27Hash Implementation29m

Graphs

  • 28Intro to Graphs22m
  • 29Matrix DFS22m
  • 30Matrix BFS14m
  • 31Adjacency List20m

Dynamic Programming

  • 321-Dimension DP20m
  • 332-Dimension DP22m

Bit Manipulation

  • 34Bit Operations17m

Arrays · Chapter 2 · 15 min

Static Arrays

A static array is a fixed-size sequence of elements stored in contiguous memory. The size is decided up front and can't change.

Key Properties

  • Contiguous memory — every element sits right next to the previous one
  • Fixed size — allocated once, never grows
  • O(1) random access — jump to any index instantly

Reading and Writing

Because elements are laid out contiguously, the address of arr[i] is easy to compute:

address(arr[i]) = base_address + i * size_of_element

That formula takes constant time, which is why reads and writes are O(1):

int[] nums = new int[5];
nums[2] = 42;        // O(1) write
int x = nums[2];     // O(1) read

Insertion and Deletion

The catch: inserting or deleting anywhere except the end is slow. To insert at index i, you have to shift every element from i onward one slot to the right. That's O(n).

| Operation | Time | |---|---| | Read / write by index | O(1) | | Insert at end (if space) | O(1) | | Insert in middle | O(n) | | Delete from middle | O(n) |

Note: Languages like Java and C use static arrays directly. Python and JavaScript give you dynamic arrays by default — we'll see those next.

Previous

RAM

Next

Dynamic Arrays

On this page