Skip to content
vaddePublic

About

Algorithmic mental models & the SIFT Framework for engineering mentorship. 43 structural pattern archetypes to eliminate interview anxiety.

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Latest commit

ย 

History

92 Commits

Folders and files

NameName
Last commit message
Last commit date
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿง  Data Structures & Algorithms โ€” The Complete Pattern Bible

Living Documentation Portal Quality Gate

๐Ÿš€ Explore the Interactive Living Documentation Portal: https://vadde.github.io/DSA/
Complete interactive architecture with 44 patterns, 14 engines, 460 isolated visual diagrams, full-text Cmd+K search, SIFT simulator, and multi-theme cosmic liquid-glass UI.

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


๐Ÿ›๏ธ The Three Pillars of Mastery

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚ ๐Ÿ›๏ธ PILLAR 0: THEORETICAL FOUNDATIONS (The Physics of Computation)             โ”‚
โ”‚ Computability (Turing/Rice) โ€ข Complexity Zoo (P, NP, PSPACE) โ€ข Lower Bounds   โ”‚
โ”‚ Asymptotics โ€ข Amortization โ€ข Approximations โ€ข Heuristics โ€ข Engineering Triage โ”‚
โ”‚ ๐Ÿ“‚ 00 - Fundamentals/000 - Theoretical Foundations (The Complete Guide)/      โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                                       โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚ โš™๏ธ PILLAR 1: DATA STRUCTURE ENGINE ROOMS (The Concrete Mechanics)             โ”‚
โ”‚ Stacks โ€ข Queues โ€ข Linked Lists โ€ข Heaps โ€ข BSTs โ€ข Tries โ€ข Trees โ€ข Graphs       โ”‚
โ”‚ ๐Ÿ“‚ 00 - Fundamentals/ (001 - 014 Engines, 015 Trees Guide, 016 Graphs Guide) โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                                       โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚ โš”๏ธ PILLAR 2: ALGORITHMIC PATTERNS (The Tactical Arsenal)                     โ”‚
โ”‚ 43 Patterns โ€ข SIFT Method โ€ข 7 Pattern Families โ€ข Muscle Memory Skeletons    โ”‚
โ”‚ ๐Ÿ“‚ 01 - Warmup/ ... 43 - Miscellaneous/                                     โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

๐Ÿ”‘ The SIFT Method โ€” Your 10-Second Pattern Finder

Before writing a single line of code, say this out loud:

"My input is a ____. I need to find ____. The constraint is ____. Therefore, the pattern is ____."

  • State the problem in your own words
  • Identify the input type and constraints
  • Find the pattern using the trigger words below
  • Template: Write the skeleton code from memory

๐Ÿ—บ๏ธ The Master Decision Flowchart

Read the problem โ†’ Ask Question 1 โ†’ Narrow โ†’ Ask Question 2 โ†’ Solve.

flowchart TD
    START["๐Ÿ“– Read the Problem"] --> Q1{"โ“ What is the INPUT?"}
    
    Q1 -->|"Sorted Array"| SA["๐Ÿ” Binary Search\n๐Ÿ‘‰ Two Pointers"]
    Q1 -->|"Unsorted Array / String"| UA{"โ“ What do you need?"}
    Q1 -->|"Linked List"| LL["๐Ÿข Fast & Slow\n๐Ÿ”„ In-place Reversal\n๐Ÿ“‹ Clone"]
    Q1 -->|"Tree"| TR{"โ“ Level-by-level\nor Path-by-path?"}
    Q1 -->|"Graph / Matrix"| GR{"โ“ What to find?"}
    Q1 -->|"Intervals"| IV["๐Ÿ“ Merge Intervals\n๐Ÿค‘ Greedy"]
    Q1 -->|"Numbers / Bits"| BT["โŠ• Bitwise XOR"]
    
    UA -->|"Subarray (contiguous)"| SUB["๐ŸชŸ Sliding Window\nโž• Prefix Sum"]
    UA -->|"Pair / Triplet"| TP["๐Ÿ‘‰ Two Pointers (sort first!)"]
    UA -->|"Missing / Duplicate in [1,N]"| CS["๐Ÿ”ข Cyclic Sort"]
    UA -->|"Next Greater / Smaller"| MS["๐Ÿ“Š Monotonic Stack"]
    UA -->|"All combos / permutations"| BK["๐Ÿ”™ Backtracking\n๐Ÿ“ฆ 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"]
    
    style START fill:#1a1a2e,color:#fff,stroke:#e94560
    style Q1 fill:#16213e,color:#fff,stroke:#0f3460
    style SA fill:#0f3460,color:#fff
    style LL fill:#0f3460,color:#fff
    style IV fill:#0f3460,color:#fff
    style BT fill:#0f3460,color:#fff
    style SUB fill:#533483,color:#fff
    style TP fill:#533483,color:#fff
    style CS fill:#533483,color:#fff
    style MS fill:#533483,color:#fff
    style BK fill:#533483,color:#fff
    style TK fill:#533483,color:#fff
    style DP fill:#533483,color:#fff
    style HM fill:#533483,color:#fff
    style BFS fill:#2b2d42,color:#fff
    style DFS fill:#2b2d42,color:#fff
    style UF fill:#e94560,color:#fff
    style TS fill:#e94560,color:#fff
    style IS fill:#e94560,color:#fff
    style AP fill:#e94560,color:#fff
Loading

โšก Engineering Triage: When to Go "Kill Mode" vs "Pull the Plug"

"Amateurs guess algorithms. Professionals inspect constraints, classify the complexity class, and decide instantly whether to optimize to the metal or switch to an approximation."

Input Constraint ($N$) Allowed Complexity Tactical Mindset Strategic Move
$N \le 10$ $O(N!) \text{ or } O(N^6)$ ๐Ÿ”™ Permutations / Backtracking Brute-force DFS, state permutations (itertools.permutations)
$N \le 20$ $O(2^N \cdot N)$ ๐Ÿงฉ Bitmask DP / Subsets Meet-in-the-Middle, State compression DP, Subsets
$N \le 100$ $O(N^4)$ ๐Ÿงฎ 2D/3D DP / Floyd-Warshall High-dimensional Dynamic Programming
$N \le 500$ $O(N^3)$ ๐ŸŒŠ Matrix Multiplication / Floyd Triple nested loops, all-pairs shortest paths
$N \le 5,000$ $O(N^2)$ ๐ŸชŸ Nested Loops / 2D DP Quadratic DP, nested scans, Kadane variants
$N \le 10^5$ $O(N \log N)$ ๐Ÿš€ KILL MODE: Sort / Heap / Tree Sorting, Divide-and-Conquer, Segment Trees, Heaps
$N \le 10^6$ $O(N)$ โšก KILL MODE: Linear Scan Sliding Window, Hash Map, Two Pointers, Monotonic Stack
$N \ge 10^9$ $O(\log N) \text{ or } O(1)$ ๐ŸŽฏ Math / Binary Search Binary Search over answer, Bitwise tricks, Closed-form math

๐Ÿšจ The Decision Rule:

  • Problem is in $P$ (or $N$ fits the table) $\longrightarrow$ ๐Ÿ”ฅ GO KILL MODE: Derive the exact optimal pattern, eliminate allocations, exploit CPU cache locality, and nail the proof.
  • Problem is $NP$-Hard and $N > 30$ $\longrightarrow$ ๐Ÿ›‘ PULL THE PLUG: Stop searching for polynomial exact algorithms ($P \ne NP$). Switch to Approximations (Ch 7), Randomization (Ch 8), or Metaheuristics (Ch 9).
  • Need the full engineering decision framework? Explore 000 - Chapter 12: Kill Mode vs Pull the Plug.

๐Ÿ‘จโ€๐Ÿ‘ฉโ€๐Ÿ‘งโ€๐Ÿ‘ฆ The 7 Pattern Families

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

mindmap
  root((๐Ÿง  DSA Patterns))
    ๐Ÿƒ Runners
      Two Pointers
      Fast & Slow
      Sliding Window
    ๐Ÿ“ฆ Sorters
      Merge Intervals
      Cyclic Sort
      Linear Sort
    ๐ŸŒฒ Explorers
      Tree BFS
      Tree DFS
      Island Traversal
      Backtracking
    ๐Ÿ“Š Rankers
      Top K Elements
      Two Heaps
      K-way Merge
    ๐Ÿ” Searchers
      Binary Search
      Trie
      Hash Maps
    ๐Ÿงฎ Counters
      Prefix Sum
      DP: Knapsack
      DP: Fibonacci
      DP: Palindrome
      Segment Tree
      BIT
    ๐Ÿ”— Connectors
      Union Find
      Topological Sort
      Clone
      Serialize
Loading
Family Core Idea When Your Gut Says...
๐Ÿƒ Runners Two things moving through data "I need to scan with a window or shrink from both sides"
๐Ÿ“ฆ Sorters Put things in the right place "Things overlap or belong at specific positions"
๐ŸŒฒ Explorers Visit nodes, explore paths "I need to traverse a tree, graph, or grid"
๐Ÿ“Š Rankers Find the best K things "I need the top/bottom K or a running median"
๐Ÿ” Searchers Find something fast "I need to look up, match, or search efficiently"
๐Ÿงฎ Counters Count or accumulate values "I need to count ways, sums, or optimize a value"
๐Ÿ”— Connectors Manage relationships "Things are connected, ordered, or need to be copied"

๐ŸŽฏ Trigger Word โ†’ Pattern (Instant Lookup)

Scan the problem statement. Spot ONE of these phrases. You have your pattern.

๐Ÿƒ Runner Patterns

๐Ÿ” When You See... ๐Ÿ’ก Instantly Think... ๐Ÿท๏ธ Pattern
"pair", "triplet", "two sum", "sorted array" Shrink from both ends Two Pointers
"cycle in linked list", "middle of list", "happy number" Tortoise ๐Ÿข and Hare ๐Ÿ‡ Fast & Slow
"longest substring", "K distinct characters", "window" Expand right, shrink left Sliding Window

๐Ÿ“ฆ Sorter Patterns

๐Ÿ” When You See... ๐Ÿ’ก Instantly Think... ๐Ÿท๏ธ Pattern
"merge intervals", "overlapping meetings" Sort by start, merge greedily Merge Intervals
"missing number", "duplicate in [1,N]", "first missing positive" Each number IS its own index Cyclic Sort

๐ŸŒฒ Explorer Patterns

๐Ÿ” When You See... ๐Ÿ’ก Instantly Think... ๐Ÿท๏ธ Pattern
"level order", "zigzag traversal", "right side view" Queue + level_size loop Tree BFS
"max depth", "path sum", "diameter", "LCA" Recurse left + right Tree DFS
"number of islands", "flood fill", "surrounded regions" DFS/BFS on grid, mark visited Island Traversal
"N-Queens", "generate parentheses", "sudoku", "permutations" Choose โ†’ Explore โ†’ Un-choose Backtracking

๐Ÿ“Š Ranker Patterns

๐Ÿ” When You See... ๐Ÿ’ก Instantly Think... ๐Ÿท๏ธ Pattern
"Kth largest", "K closest points", "top K frequent" Min-heap of size K Top K Elements
"median of stream", "balance two halves" Max-heap (left) + Min-heap (right) Two Heaps
"merge K sorted lists/arrays" Min-heap holding K heads K-way Merge

๐Ÿ” Searcher Patterns

๐Ÿ” When You See... ๐Ÿ’ก Instantly Think... ๐Ÿท๏ธ Pattern
"sorted", "rotated sorted", "search in...", "minimum in rotated" Cut search space in half Binary Search
"autocomplete", "word search II", "prefix match" Character-by-character tree Trie
"frequency", "seen before", "contains duplicate" O(1) lookup dictionary Hash Map

๐Ÿงฎ Counter Patterns

๐Ÿ” When You See... ๐Ÿ’ก Instantly Think... ๐Ÿท๏ธ Pattern
"subarray sum equals K", "range sum" prefix[j] โˆ’ prefix[i] = K Prefix Sum
"coin change", "subset sum", "0/1 knapsack" Include or Exclude with memo 0-1 Knapsack DP
"climb stairs", "house robber", "decode ways" dp[i] = dp[iโˆ’1] + dp[iโˆ’2] Fibonacci DP
"longest palindromic subsequence" 2D DP on substring s[i..j] Palindromic DP
"range sum query โ€” mutable" Array-backed tree Segment Tree / BIT

๐Ÿ”— Connector Patterns

๐Ÿ” When You See... ๐Ÿ’ก Instantly Think... ๐Ÿท๏ธ Pattern
"connected components", "redundant edge", "accounts merge" find() + union() Union Find
"course schedule", "build order", "task dependencies" In-degree + BFS queue Topological Sort
"clone graph", "copy list with random pointer" Old โ†’ New HashMap Clone
"serialize/deserialize tree" Pre-order + null markers Serialize

โšก Other Instant Triggers

๐Ÿ” When You See... ๐Ÿ’ก Instantly Think... ๐Ÿท๏ธ Pattern
"reverse linked list", "reverse between positions" prev / curr / next dance In-place Reversal
"next greater element", "daily temperatures" Decreasing stack, pop when bigger Monotonic Stack
"sliding window maximum / minimum" Deque keeping decreasing order Monotonic Queue
"single number", "XOR" a โŠ• a = 0 Bitwise XOR
"critical connections", "bridges in graph" Tarjan's disc/low DFS Articulation Points

๐Ÿงฌ Pattern DNA Cards โ€” The Core Skeletons

Once you identify the pattern, recall its skeleton. Every problem in that pattern uses the SAME bones.

๐Ÿƒ Two Pointers

left, right = 0, len(nums) - 1
while left < right:
    if condition:   left += 1
    else:           right -= 1

๐Ÿข Fast & Slow

slow = fast = head
while fast and fast.next:
    slow = slow.next
    fast = fast.next.next
# slow is now at the middle (or meeting point if cycle)

๐ŸชŸ Sliding Window

left = 0
for right in range(len(nums)):
    # expand: add nums[right] to window
    while window_is_invalid:
        # shrink: remove nums[left], left += 1
    result = max(result, right - left + 1)

๐Ÿ“Š Monotonic Stack

stack = []  # store INDICES, not values
for i in range(len(nums)):
    while stack and nums[stack[-1]] < nums[i]:
        result[stack.pop()] = nums[i]
    stack.append(i)

๐Ÿ” Binary Search

lo, hi = 0, len(nums) - 1
while lo <= hi:
    mid = lo + (hi - lo) // 2
    if nums[mid] == target:  return mid
    elif nums[mid] < target: lo = mid + 1
    else:                    hi = mid - 1

๐ŸŒŠ Tree BFS

queue = deque([root])
while queue:
    for _ in range(len(queue)):  # process ONE level
        node = queue.popleft()
        if node.left:  queue.append(node.left)
        if node.right: queue.append(node.right)

๐ŸŒฒ Tree DFS

def dfs(node):
    if not node: return BASE_CASE
    left = dfs(node.left)
    right = dfs(node.right)
    return COMBINE(left, right, node.val)

๐Ÿงฎ Dynamic Programming

# Step 1: WHAT does dp[i] mean?
# Step 2: HOW does dp[i] relate to dp[i-1]?
# Step 3: WHAT is dp[0]?
dp = [BASE] * (n + 1)
for i in range(1, n + 1):
    dp[i] = TRANSITION(dp[i-1], dp[i-2], ...)

๐Ÿ”™ Backtracking

def backtrack(path, choices):
    if GOAL_REACHED:
        result.append(path[:])
        return
    for choice in choices:
        path.append(choice)        # โœ… CHOOSE
        backtrack(path, next)      # ๐Ÿ”„ EXPLORE
        path.pop()                 # โ†ฉ๏ธ UN-CHOOSE

๐Ÿ“‹ Topological Sort

# Build in_degree map. Start with all nodes that have in_degree == 0.
queue = deque([n for n in graph if in_degree[n] == 0])
while queue:
    node = queue.popleft()
    result.append(node)
    for neighbor in graph[node]:
        in_degree[neighbor] -= 1
        if in_degree[neighbor] == 0:
            queue.append(neighbor)
# if len(result) != total_nodes โ†’ CYCLE EXISTS

๐Ÿ”— Union Find

def find(x):
    if parent[x] != x:
        parent[x] = find(parent[x])  # path compression
    return parent[x]

def union(x, y):
    px, py = find(x), find(y)
    if rank[px] < rank[py]: px, py = py, px
    parent[py] = px

๐Ÿšจ The 10 Interview-Killing Mistakes

# โŒ The Mistake โœ… The Fix
1 Jumping to code without understanding Spend 3 min asking questions. Restate the problem.
2 Ignoring edge cases (empty, single, all-same) Write 3 edge cases BEFORE coding.
3 Off-by-one in Binary Search Drill lo <= hi + lo + (hi-lo)//2 until muscle memory.
4 Not marking visited in BFS/DFS Mark BEFORE adding to queue, not after popping.
5 Wrong DP state definition If your transition feels forced, your state is wrong.
6 Two Pointers on unsorted array Sort first. Always. (Except linked lists.)
7 Confusing Subarray vs Subsequence Sub-array = contiguous โ†’ Sliding Window. Sub-sequence = not โ†’ DP.
8 Modifying collection while iterating Use indices, or build a separate list.
9 Forgetting about negative numbers Sliding Window usually needs all positives.
10 50+ lines of code Step back. You're probably missing a simpler pattern.

๐Ÿ“š The Pattern Index

About

Algorithmic mental models & the SIFT Framework for engineering mentorship. 43 structural pattern archetypes to eliminate interview anxiety.

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages