Skip to content

Data Structures & Algorithms

A structured path for developing problem-solving ability for technical interviews and writing efficient, correct code in real systems.

This section is language-oriented but not language-locked. Core explanations focus on the underlying data structure or algorithm; implementations will primarily use Python, Go, and Java, with consistent examples where useful.

How to use this section

  1. Understand the problem constraints and clarify input assumptions.
  2. Work through a straightforward solution before optimizing.
  3. Identify the data structure or algorithmic pattern that improves the solution.
  4. Explain correctness, time complexity, and auxiliary space complexity.
  5. Test edge cases and compare the implementation against the constraints.

Do not memorize solutions without understanding why they work. The goal is to recognize patterns and adapt them to unfamiliar problems.

Learning path

Stage Topics What to learn
1. Foundations Big-O, arrays, strings, hashing Complexity, traversal, lookup, frequency counting
2. Linear structures Linked lists, stacks, queues, deques Pointer manipulation, monotonic structures, FIFO/LIFO
3. Search and ordering Sorting, binary search, intervals Search invariants, partitioning, sweep-line foundations
4. Core patterns Two pointers, sliding window, prefix sums Efficient subarray and sequence reasoning
5. Trees and heaps Binary trees, BSTs, heaps, tries Traversals, invariants, priority-based processing
6. Graphs BFS, DFS, topological sort, shortest paths Modeling relationships, visited state, weighted paths
7. Recursion Backtracking, divide and conquer State, choices, pruning, recursion trees
8. Optimization Greedy algorithms, dynamic programming Proof of choices, overlapping subproblems, state transitions
9. Advanced structures Union-find, Fenwick tree, segment tree Efficient connectivity and range queries

Topic index

Foundations

Core patterns

  • Two pointers
  • Sliding window
  • Prefix sums and difference arrays
  • Fast and slow pointers
  • Sorting and binary search
  • Intervals and sweep-line techniques

Data structures

  • Linked lists
  • Stacks, queues, and deques
  • Monotonic stacks and queues
  • Binary trees and binary search trees
  • Heaps and priority queues
  • Tries
  • Union-find / disjoint set union
  • Fenwick trees and segment trees

Algorithms

  • Recursion and backtracking
  • Breadth-first search and depth-first search
  • Topological sorting
  • Shortest paths: Dijkstra, Bellman-Ford, and Floyd-Warshall
  • Minimum spanning trees
  • Greedy algorithms
  • Dynamic programming
  • Divide and conquer

Standards for solutions

Every problem write-up should include:

  • Problem statement, constraints, and assumptions.
  • A clear explanation of the key observation or pattern.
  • A baseline approach where it helps explain the optimization.
  • Correct implementation with meaningful names and no hidden dependencies.
  • Time and auxiliary space complexity, with variables defined.
  • Correctness reasoning and important edge cases.
  • Tests covering normal, boundary, and adversarial inputs.
  • Equivalent implementations in Python, Go, and Java when they add value.

Complexity claims must match the actual implementation. Distinguish auxiliary space from total space, and average-case from worst-case behavior where relevant.

Interview preparation

Practice explaining your reasoning aloud:

  • What are the input constraints?
  • What is the simplest correct approach?
  • Which operation dominates the runtime?
  • What data structure makes that operation cheaper?
  • What invariant does the algorithm maintain?
  • Why is the algorithm correct?
  • What are the time and space costs?
  • Which edge cases could break the implementation?

Start with complexity analysis, arrays, strings, hash maps, and sets. Then learn two pointers, sliding windows, prefix sums, stacks, queues, and binary search. Move to trees and graphs before studying backtracking, greedy algorithms, and dynamic programming. Finish with advanced data structures and mixed interview practice.

The sequence is a guide, not a rigid prerequisite graph. Revisit earlier patterns as problems combine them.