Skip to content

🧠 DSA Patterns: The Senior Registry

🪟 Archetype: Sliding Window

The Villain: "The Redundant Scan." Re-calculating sums or counts for a range from scratch every time the start index moves.

The Hero: "The Running State." Only updating the state with the new element entering the window and the old one leaving.

The Plot:

  1. Expand the right pointer to include new data.
  2. Once the condition is violated, contract the left pointer.
  3. Capture the result (max, min, or count) at each valid step. 🎯 Field Manual (Local Files):

  4. Longest Substring

  5. Sliding Window Maximum

🏎️ Archetype: Two Pointers (Converging)

The Villain: "The \(O(N^2)\) Pair Search." Using nested loops to find a pair that meets a condition.

The Hero: "The Greedy Squeeze." Starting from both ends and moving inward. 🎯 Field Manual (Local Files):

🐢 Archetype: Fast & Slow Pointers (Tortoise & Hare)

The Villain: "The Infinite Loop." Traversing a structure that has a cycle.

The Hero: "The Relative Velocity." Two pointers moving at different speeds will eventually meet. 🎯 Field Manual (Local Files):

🌲 Archetype: Level-Order Traversal (BFS)

The Villain: "The Fog of War." Not knowing the shortest path or the "width" of a tree.

The Hero: "The FIFO Queue." Processing layer by layer. 🎯 Field Manual (Local Files):

🏗️ Archetype: Depth-First Search (DFS)

The Villain: "The Unexplored Path." Needing to visit every node or find all possible combinations.

The Hero: "The Stack / Recursion." Diving deep into one path before backtracking. 🎯 Field Manual (Local Files):

🪜 Archetype: Dynamic Programming (Tabulation)

The Villain: "The Redundant Recursion." Solving the same sub-problem \(2^N\) times.

The Hero: "The Cache." Storing results in an array to solve in \(O(N)\). 🎯 Field Manual (Local Files):

🫧 Archetype: Sorting (Divide & Conquer)

The Villain: "The \(O(N^2)\) Bottleneck." Trying to sort millions of items with Bubble or Insertion sort.

The Hero: "The Recursive Splitter." Breaking the problem into single-element arrays and merging them back (Merge Sort) or partitioning around a pivot (Quick Sort). 🎯 Field Manual (Local Files):