Data Structures and Algorithm

We deliberately don't cover every DSA topic. Learn the structures, techniques, and patterns that actually get asked in interviews with a step-by-step visualizer and real practice problems for each one.

01

Foundations

The data structures every pattern below is built on.

01

Arrays

The default choice for ordered data: constant-time index access, linear-time search.

Access O(1), Search O(n), Insert/Delete O(n)
02

Strings

Arrays of characters with their own quirks: immutability, encoding, and O(n) concatenation traps.

Access O(1), Search O(n), Concatenation O(n)
03

HashMap

Key-value lookups in average O(1) time: the single most useful trick for turning O(n²) into O(n).

Get/Set/Delete average O(1), worst case O(n)
04

HashSet

A HashMap that only cares about keys: average O(1) membership checks with no duplicates.

Add/Has/Delete average O(1), worst case O(n)
05

Stack

Last-in, first-out: the structure behind parsing, backtracking, and matching problems.

Push/Pop/Peek O(1)
06

Queue

First-in, first-out ordering: the backbone of BFS, task scheduling, and streaming problems.

Enqueue O(1), Dequeue O(1), Peek O(1)
07

Linked List

Nodes chained by pointers: cheap inserts and deletes at the cost of random access.

Access O(n), Search O(n), Insert/Delete at head O(1)
08

Trees

Hierarchical nodes with parent-child links: the shape behind DOM trees, ASTs, and search structures.

Traversal O(n), Search in BST O(log n) avg / O(n) worst
09

Graphs

Nodes and edges without the hierarchy constraint: the model behind networks, dependencies, and maps.

Traversal O(V + E)
10

Heap / Priority Queue

A complete binary tree stored in an array: gives you the min or max in O(1), always.

Peek O(1), Insert O(log n), Extract-min/max O(log n)
02

Techniques

General-purpose techniques that show up across many problems.

03

Interview Patterns

The core curriculum — recognize these and most interview problems fall into place.

01

Two Pointers

Walk two indices through a sorted structure in tandem to cut a quadratic search down to linear time.

O(n)
02

Sliding Window

Track a moving range over an array or string to turn brute-force O(n^2) scans into a single O(n) pass.

O(n)
03

Prefix Sum

Precompute running totals so any range sum becomes an O(1) lookup instead of a fresh loop every time.

O(n)
04

Frequency Counting

Tally occurrences with a hash map or fixed-size array to turn comparison and grouping problems into linear-time lookups.

O(n)
05

Binary Search

Cut the search space in half every step: the go-to pattern for sorted arrays, rotated arrays, and 'search on the answer' problems.

O(log n)
06

Merge Intervals

Sort by start time, then sweep once: the standard playbook for overlapping ranges, scheduling, and booking problems.

O(n log n)
07

Fast & Slow Pointers

Two pointers moving at different speeds through a sequence: the constant-space trick for cycle detection and finding the middle.

O(n)
08

Tree Depth-First Search

Recurse into left and right subtrees to explore paths, validate properties, and compute tree-wide values.

O(n)
09

Tree Breadth-First Search

Traverse a binary tree level by level using a queue: the go-to pattern for level order, right-side view, and shortest-depth problems.

O(n)
10

Graph Depth-First Search

Explore a graph as deep as possible before backtracking: the pattern behind connected components, cycle detection, and flood fill.

O(V+E)
11

Graph Breadth-First Search

Expand outward in waves from a source using a queue: the pattern for shortest paths, multi-source spread, and minimum-step problems.

O(V+E)
12

Top K Elements

Find the K largest, smallest, or most frequent elements without fully sorting the input, powered by a heap of size K.

O(n log k)
13

Two Heaps

Split a stream into a max-heap of smaller values and a min-heap of larger values to get the median or a running order statistic in O(log n) per operation.

O(log n) per insert, O(1) to read the median
14

Backtracking

Explore every candidate solution by choosing, recursing, and un-choosing, pruning branches the moment they can't possibly lead to a valid answer.

Typically O(2^n), O(n!), or O(k^n) depending on the branching factor
15

Dynamic Programming

Break a problem into overlapping subproblems, solve each one once, and reuse the answer, turning exponential brute force into polynomial time.

Typically O(n) to O(n^2) depending on state space and transitions
16

Greedy Algorithms

Make the locally optimal choice at every step and never look back: valid only when a local best provably leads to a global best.

Typically O(n) or O(n log n) if a sort is required first