Back to Course
Quick Reference

Data Structure Cheat Sheet: Complete Guide

Welcome to the ultimate DSA cheat sheet! This page consolidates all the key information from our Data Structures and Algorithms tutorial series into a single, scannable reference. Use this to review concepts, memorize complexities, and ace your technical interviews.

Pro Tip: Bookmark this page for quick revision before interviews. Understanding when to use a specific data structure is just as important as knowing how it works.

1. Data Structures & Big O Complexity

Legend: * denotes O(1) time with known position (e.g., at head or tail).

Data StructureAccessSearchInsertionDeletionSpace
ArrayO(1)O(n)O(n)O(n)O(n)
StackO(1)O(n)O(1)O(1)O(n)
QueueO(1)O(n)O(1)O(1)O(n)
Singly Linked ListO(n)O(n)O(1)*O(1)*O(n)
Doubly Linked ListO(n)O(n)O(1)*O(1)*O(n)
Hash TableO(1) avgO(1) avgO(1) avgO(1) avgO(n)
BSTO(log n) avgO(log n) avgO(log n) avgO(log n) avgO(n)
AVL TreeO(log n)O(log n)O(log n)O(log n)O(n)
Heap (Min/Max)O(1)O(n)O(log n)O(log n)O(n)
B-TreeO(log n)O(log n)O(log n)O(log n)O(n)

2. Sorting Algorithms Summary

AlgorithmBestAverageWorstSpaceStable
Bubble SortO(n)O(n²)O(n²)O(1)Yes
Selection SortO(n²)O(n²)O(n²)O(1)No
Insertion SortO(n)O(n²)O(n²)O(1)Yes
Merge SortO(n log n)O(n log n)O(n log n)O(n)Yes
Quick SortO(n log n)O(n log n)O(n²)O(log n)No
Heap SortO(n log n)O(n log n)O(n log n)O(1)No
Counting SortO(n+k)O(n+k)O(n+k)O(k)Yes
Radix SortO(nk)O(nk)O(nk)O(n+k)Yes
Bucket SortO(n+k)O(n+k)O(n²)O(n)Yes

3. Graph Algorithms Cheat Sheet

AlgorithmUse CaseTime ComplexitySpace Complexity
BFSShortest path (unweighted), level traversalO(V + E)O(V)
DFSCycle detection, topological sort, path findingO(V + E)O(V)
Dijkstra'sShortest path (positive weights)O((V+E) log V)O(V)
Bellman-FordShortest path (negative weights, cycle detection)O(VE)O(V)
Floyd-WarshallAll-pairs shortest pathO(V³)O(V²)
Kruskal'sMinimum Spanning Tree (MST)O(E log E)O(V)
Prim'sMinimum Spanning Tree (MST)O((V+E) log V)O(V)
Topological SortOrdering vertices in a DAGO(V + E)O(V)

4. Algorithm Paradigms — Quick Guide

  • Brute Force: Exhaustive search. Simple but often exponential (O(2ⁿ) or O(n!)). E.g., Subset sum, TSP.
  • Divide & Conquer: Split problem into subproblems, solve recursively, merge. E.g., Merge Sort, Quick Sort, Binary Search.
  • Greedy: Make locally optimal choices at each step. Fast, but may not yield global optimum. E.g., Activity Selection, Fractional Knapsack.
  • Dynamic Programming: Break into overlapping subproblems and store results (memoization/tabulation). Guarantees optimal solution. E.g., 0/1 Knapsack, LCS, Fibonacci.
  • Backtracking: Explore all solutions, abandon (backtrack) when constraint fails. E.g., N-Queens, Sudoku solver.

5. Key Data Structure Definitions

  • Array: Contiguous memory allocation, fixed size (static) or dynamic. Provides O(1) random access.
  • Linked List: Dynamic size, non-contiguous memory (nodes). Efficient O(1) insert/delete at known positions.
  • Stack: LIFO (Last-In-First-Out). Implemented via arrays/linked lists. Used in DFS, recursion, undo/redo.
  • Queue: FIFO (First-In-First-Out). Used in BFS, scheduling, buffering.
  • Binary Search Tree (BST): Left child < Parent < Right child. Average O(log n) search, insert, delete.
  • AVL Tree: Self-balancing BST. Balance factor = {-1, 0, 1}. Guarantees O(log n) operations.
  • Heap: Complete binary tree. Max-heap: Parent ≥ Children. Min-heap: Parent ≤ Children. Used for Priority Queues.
  • Hash Table: Key-Value store using hash functions. Average O(1) operations. Collision handling: Chaining, Open Addressing.
  • Graph: Nodes (Vertices) connected by edges. Directed/Undirected, Weighted/Unweighted.
  • Trie: Tree-like structure for strings. Efficient prefix searching (O(m) where m is word length).
  • B-Tree: Self-balancing multi-way tree. Optimized for disk I/O. Used in databases and file systems.

6. Common Pitfalls & Tips

  • Off-by-one errors: Carefully check loop boundaries, especially with 0-based indexing.
  • Recursion depth: For large inputs, prefer iterative solutions or increase recursion limit.
  • Hash map collisions: Ensure a good hash function and reasonable load factor (e.g., 0.75).
  • Integer overflow: When calculating sums in problems like "Maximum Subarray", use appropriate data types (e.g., `long` in Java).
  • Memory leaks: In languages like C/C++, always free dynamically allocated memory.
  • Reading the problem: Always read the constraints first. They dictate the required complexity (e.g., n ≤ 10⁶ -> O(n log n) is acceptable).

7. Complexity Comparison Visualization

For n = 10⁶ elements:

  • O(1): 1 operation (Instant)
  • O(log n): ~20 operations (Instant)
  • O(n): 1,000,000 operations (~0.01s)
  • O(n log n): ~20,000,000 operations (~0.2s)
  • O(n²): 10¹² operations (~10 minutes)
  • O(2ⁿ): Impossible for n=10⁶

🎉 Congratulations! You've completed the entire DSA Tutorial Series! 🎉

You now have a solid foundation in Data Structures and Algorithms. Keep practicing, stay curious, and never stop learning!

Ready to master Data Structures & Algorithms?

Learn DSA hands-on with mentor-led sessions, real interview practice, and placement support.

Explore Course