Data Structures & Algorithms Cheatsheet (Summary)
Sorting Algorithms – Time & Space Complexity
Algorithm Best Case Worst Case Space Complexity
Bubble Sort O(n) O(n²) O(1)
Selection Sort O(n²) O(n²) O(1)
Insertion Sort O(n) O(n²) O(1)
Merge Sort O(n log n) O(n log n) O(n)
Quick Sort O(n log n) O(n²) O(log n)
Searching Algorithms – Time Complexity
Algorithm Time Complexity Space Complexity
Linear Search O(n) O(1)
Binary Search O(log n) O(1)
Graph Traversal – Time & Space Complexity
Algorithm Time Complexity Space Complexity Use Case
BFS O(V+E) O(V) Shortest path in
unweighted graph
DFS O(V+E) O(V) Explore all paths,
cycle detection
Advanced Pathfinding – Time Complexity
Algorithm Graph Type Time Complexity Notes
Dijkstra’s Weighted (non- O((V+E) log V) Efficient, fast for
negative) sparse graphs
Bellman-Ford Weighted (with O(VE) Handles negative
negatives) weights
Dynamic Programming (DP)
Break problem into smaller subproblems
Store solutions to reuse (avoid recomputation)
Caching = store data, Memoization = store function results