Ω
DSA PATTERN BIBLE Algorithmic Patterns & Foundations
PATTERNS: 44
PROBLEMS: 305
WALKTHROUGHS: 328
THE DEFINITIVE PATTERN COMPENDIUM Production Grade

The Complete DSA Pattern Bible

"You don't need to memorize 43 patterns. You need to memorize 5 questions, 7 families, and 1 mantra."

Pillar 0 · Theory

Physics of Computation

Computability, Rice's theorem, Turing reductions, Complexity Zoo (P, NP, PSPACE), Lower Bounds & Amortization.

Pillar 1 · Mechanics

14 Engine Rooms

Array & String, Heaps, BSTs, Tries, Disjoint Sets, Circular Lists, and Bitwise Engines with typed Python implementations.

Pillar 2 · Arsenal

43 Algorithmic Patterns

The SIFT Method, Muscle Memory skeletons, Step-by-Step execution dry runs, and 305 typed Python solutions.

Click chapter headers to toggle accordion
⚡ The SIFT Method — 10-Second Pattern Finder
Mental Radar

Before writing a single line of code, execute the SIFT protocol: State the problem, Identify inputs/constraints, Find the trigger, Template the skeleton.

Identified Pattern 🏃 Runner
Two Pointers (Opposite Ends)
"My input is a sorted array. I need to find a pair. The constraint is O(N). Therefore, shrink from both ends inwards."
👨‍👩‍👧‍👦 The 7 Pattern Families
Categorical Mastery

"Don't memorize 43 patterns. Memorize 7 families. Each family shares the same intuitive feeling."

🏃 Runners 4 Patterns
Two things moving through data. Shrink from both sides or slide a window.
WarmupTwo PointersFast & Slow PointersSliding Window
📦 Sorters 3 Patterns
Put items in the right place. Handle overlapping intervals or direct index cyclic placement.
Merge IntervalsCyclic SortLinear Sorting Algorithm
🌲 Explorers 6 Patterns
Traverse trees, graphs, grids, or explore all permutations and subsets.
Tree Breadth First SearchTree Depth First SearchGraphsIsland (Matrix Traversal)SubsetsBacktracking
📊 Rankers 3 Patterns
Find the top/bottom K elements, running medians, or multi-stream merges.
Two HeapsTop K ElementsK-way Merge
🔍 Searchers 4 Patterns
Cut search spaces in half, prefix matching with tries, or O(1) hash maps.
Hash MapsModified Binary SearchTrieMeet in the Middle
🧮 Counters 9 Patterns
Count ways, range sums, or optimize values via dynamic programming and prefix trees.
Greedy Algorithms0-1 Knapsack (DP)Fibonacci Numbers (DP)Palindromic Subsequence (DP)Prefix SumCounting PatternMO's AlgorithmSegment TreeBinary Indexed Tree
🔗 Connectors 13 Patterns
Manage disjoint sets, task scheduling orders, node cloning, or graph articulation bridges.
In-place Reversal of a LinkedListStacksMonotonic StackTopological Sort (Graph)Union FindOrdered SetMulti-threadedMonotonic Queue PatternSimulation PatternSerialize and DeserializeClone PatternArticulation Points and BridgesMiscellaneous
🗺️ Master Algorithmic Decision Flowchart
100%
flowchart TD
    START["📖 Read the Problem"] --> Q1["❓ What is the INPUT?"]
    
    Q1 -->|"Sorted Array"| SA["🔍 Binary Search<br/>👉 Two Pointers"]
    Q1 -->|"Unsorted Array / String"| UA["❓ What do you need?"]
    Q1 -->|"Linked List"| LL["🐢 Fast & Slow<br/>🔄 In-place Reversal<br/>📋 Clone"]
    Q1 -->|"Tree"| TR["❓ Level-by-level<br/>or Path-by-path?"]
    Q1 -->|"Graph / Matrix"| GR["❓ What to find?"]
    Q1 -->|"Intervals"| IV["📐 Merge Intervals<br/>🤑 Greedy"]
    Q1 -->|"Numbers / Bits"| BT["⊕ Bitwise XOR"]
    
    UA -->|"Subarray contiguous"| SUB["🪟 Sliding Window<br/>➕ Prefix Sum"]
    UA -->|"Pair / Triplet"| TP["👉 Two Pointers (sort first!)"]
    UA -->|"Missing in 1 to N"| CS["🔢 Cyclic Sort"]
    UA -->|"Next Greater / Smaller"| MS["📊 Monotonic Stack"]
    UA -->|"All combos"| BK["🔙 Backtracking<br/>📦 Subsets"]
    UA -->|"Kth largest / smallest"| TK["🏆 Top K / Heap"]
    UA -->|"Count ways / Optimize"| DP["🧮 Dynamic Programming"]
    UA -->|"Lookup / Frequency"| HM["#️⃣ Hash Map"]
    
    TR -->|"Level-by-level"| BFS["🌊 Tree BFS (Queue)"]
    TR -->|"Path / Depth"| DFS["🌲 Tree DFS (Recursion)"]
    
    GR -->|"Connected groups"| UF["🔗 Union Find"]
    GR -->|"Task ordering"| TS["📋 Topological Sort"]
    GR -->|"Islands / Flood fill"| IS["🏝️ Island Traversal"]
    GR -->|"Critical edges"| AP["🌉 Articulation Points"]
              
Figure 1.0: Algorithmic Routing Matrix (Double-click or drag to explore topology)
⚡ Engineering Complexity Triage: Kill Mode vs Pull the Plug
Asymptotic Rules
Constraint (N) Allowed Complexity Tactical Mindset Strategic Action
N ≤ 10 O(N!) or O(N^6) 🔙 Permutations / Backtracking Brute-force DFS, state permutations (itertools)
N ≤ 20 O(2^N · N) 🧩 Bitmask DP / Subsets Meet-in-the-Middle, State compression DP
N ≤ 100 O(N^4) 🧮 2D/3D DP / Floyd-Warshall High-dimensional Dynamic Programming
N ≤ 5,000 O(N^2) 🪟 Nested Loops / 2D DP Quadratic DP, Kadane variants, nested sweeps
N ≤ 10^5 O(N log N) 🚀 KILL MODE: Sort / Heap Sorting, Divide & Conquer, Segment Trees, Heaps
N ≤ 10^6 O(N) ⚡ KILL MODE: Linear Scan Sliding Window, Two Pointers, Monotonic Stack
N ≥ 10^9 O(log N) or O(1) 🎯 Math / Binary Search Binary Search over answer space, closed-form math
🗺️

Architecture Canvas

Theater Mode
100%