Skip to content

Cross-Reference Guide — Pattern → Implementation Map

Purpose: Master lookup for mapping problem descriptions, patterns, and real-world scenarios to specific implementations in this repo. Start here when facing a new problem.


Section 1: Problem Pattern → Implementation Map

Arrays & Hashing

When You See...Use This PatternImplementationComplexity
"Find two values that sum to X"Hash map lookupsrc/algo/arrays/two_sum.pyO(n)
"Group items by property"Hash map groupingsrc/algo/arrays/group_anagrams.pyO(n*k log k)
"Top K / most frequent"Bucket sort or heapsrc/algo/arrays/top_k_frequent.pyO(n)
"Product without self"Prefix/suffix arrayssrc/algo/arrays/product_except_self.pyO(n)

Two Pointers

When You See...Use This PatternImplementationComplexity
"Three values sum to zero"Sort + two pointerssrc/algo/two_pointers/three_sum.pyO(n^2)
"Maximum area / container"Two pointers convergingsrc/algo/two_pointers/container_with_most_water.pyO(n)
"Water trapped between bars"Two pointers + max trackingsrc/algo/two_pointers/trapping_rain_water.pyO(n)

Sliding Window

When You See...Use This PatternImplementationComplexity
"Minimum window containing chars"Variable sliding windowsrc/algo/sliding_window/min_window_substring.pyO(n)
"Longest substring without repeat"Sliding window + hashsrc/algo/sliding_window/longest_substring_no_repeat.pyO(n)

Stacks & Queues

When You See...Use This PatternImplementationComplexity
"Valid brackets/parentheses"Stack matchingsrc/algo/stacks_queues/valid_parentheses.pyO(n)
"Min/max in O(1)"Auxiliary stacksrc/algo/stacks_queues/min_stack.pyO(1)
"Next greater/warmer element"Monotonic stacksrc/algo/stacks_queues/daily_temperatures.pyO(n)
When You See...Use This PatternImplementationComplexity
"Find target in sorted array"Binary searchsrc/algo/searching/binary_search.pyO(log n)
"Search in rotated array"Modified binary searchsrc/algo/searching/search_rotated_array.pyO(log n)
"Find min in rotated array"Binary search variantsrc/algo/searching/find_minimum_rotated.pyO(log n)

Linked Lists

When You See...Use This PatternImplementationComplexity
"Reverse a linked list"Pointer manipulationsrc/algo/linked_lists/reverse_linked_list.pyO(n)
"Merge sorted lists"Two-pointer mergesrc/algo/linked_lists/merge_two_sorted.pyO(n+m)
"Cache with eviction"Hash map + doubly linked listsrc/algo/linked_lists/lru_cache.pyO(1)

Trees

When You See...Use This PatternImplementationComplexity
"Tree depth / height"DFS recursionsrc/algo/trees/max_depth.pyO(n)
"Mirror / flip tree"Recursive swapsrc/algo/trees/invert_tree.pyO(n)
"Is it a valid BST?"DFS with boundssrc/algo/trees/validate_bst.pyO(n)
"Level-by-level traversal"BFS with dequesrc/algo/trees/level_order_traversal.pyO(n)

Graphs

When You See...Use This PatternImplementationComplexity
"Connected components / islands"BFS/DFS flood fillsrc/algo/graphs/number_of_islands.pyO(m*n)
"Deep copy a graph"BFS/DFS + visited mapsrc/algo/graphs/clone_graph.pyO(V+E)
"Dependency ordering"Topological sort (Kahn's)src/algo/graphs/topological_sort.pyO(V+E)
"Can finish all tasks? (cycles)"Topological sort / DFSsrc/algo/graphs/course_schedule.pyO(V+E)
"Shortest path (positive weights)"Dijkstra's algorithmsrc/algo/graphs/dijkstra.pyO((V+E) log V)
"Signal delay to all nodes"Dijkstra variantsrc/algo/graphs/network_delay_time.pyO((V+E) log V)
"Shortest transformation chain"BFS level-by-levelsrc/algo/graphs/word_ladder.pyO(n*m^2)
"Grid pathfinding with heuristic"A* searchsrc/algo/graphs/a_star_search.pyO(E log V)
"Shortest path (negative weights)"Bellman-Fordsrc/algo/graphs/bellman_ford.pyO(V*E)
"Minimum cost to connect all"Kruskal's / Prim'ssrc/algo/graphs/minimum_spanning_tree.pyO(E log E)
"Maximum flow through network"Edmonds-Karpsrc/algo/graphs/network_flow.pyO(V*E^2)
"Spatial proximity queries"Geohash encodingsrc/algo/graphs/geohash_grid.pyO(precision)
"Nearest neighbor in k dimensions"KD-treesrc/algo/graphs/kd_tree.pyO(log n) avg

Dynamic Programming

When You See...Use This PatternImplementationComplexity
"Count ways to reach target"DP (Fibonacci-like)src/algo/dp/climbing_stairs.pyO(n)
"Minimum cost to reach amount"DP (bottom-up)src/algo/dp/coin_change.pyO(amount*coins)
"Longest increasing subsequence"DP + binary searchsrc/algo/dp/longest_increasing_subseq.pyO(n log n)
"String edit distance"2D DPsrc/algo/dp/edit_distance.pyO(m*n)
"0/1 Knapsack"DP (1D optimized)src/algo/dp/knapsack.pyO(n*W)
"Longest common subsequence"2D DPsrc/algo/dp/longest_common_subseq.pyO(m*n)
"Shortest route visiting all cities"Bitmask DP (TSP)src/algo/dp/traveling_salesman_dp.pyO(n^2 * 2^n)
"Constraint satisfaction (Sudoku)"Backtracking + propagationsrc/algo/dp/constraint_satisfaction.pyvaries

Heaps

When You See...Use This PatternImplementationComplexity
"Kth largest element"Min-heap of size ksrc/algo/heaps/kth_largest.pyO(n log k)
"Merge k sorted lists"Heap mergesrc/algo/heaps/merge_k_sorted_lists.pyO(n log k)
"Task scheduling with cooldown"Max-heap + queuesrc/algo/heaps/task_scheduler.pyO(n)

Backtracking

When You See...Use This PatternImplementationComplexity
"Generate all subsets"Backtrackingsrc/algo/backtracking/subsets.pyO(n * 2^n)
"Generate all permutations"Backtrackingsrc/algo/backtracking/permutations.pyO(n * n!)
"Combinations summing to target"Backtracking (w/ reuse)src/algo/backtracking/combination_sum.pyO(2^target)
"N queens placement"Backtracking + pruningsrc/algo/backtracking/n_queens.pyO(n!)

Greedy

When You See...Use This PatternImplementationComplexity
"Merge overlapping intervals"Sort + mergesrc/algo/greedy/merge_intervals.pyO(n log n)
"Can reach end? Min jumps?"Greedy max-reachsrc/algo/greedy/jump_game.pyO(n)
"Max non-overlapping intervals"Greedy by end timesrc/algo/greedy/interval_scheduling.pyO(n log n)

Bit Manipulation

When You See...Use This PatternImplementationComplexity
"Find unique element (others x2)"XOR allsrc/algo/bit_manipulation/single_number.pyO(n)
"Count set bits 0..n"DP: dp[i] = dp[i>>1] + (i&1)src/algo/bit_manipulation/counting_bits.pyO(n)
"Reverse bits of integer"Bit-by-bit or D&Csrc/algo/bit_manipulation/reverse_bits.pyO(1)

Sorting

When You See...Use This PatternImplementationComplexity
"Find kth smallest"Quickselectsrc/algo/sorting/quickselect.pyO(n) avg
"Count inversions"Merge sort variantsrc/algo/sorting/merge_sort_inversions.pyO(n log n)

Section 2: Data Structure Selection Guide

NeedUseWhyExample Implementations
O(1) lookup by keydict / hash mapHash-based amortized O(1)two_sum.py, group_anagrams.py
O(1) membership testsetHash-basednumber_of_islands.py (visited set)
Ordered iterationsorted listTimsort O(n log n)three_sum.py (sort first)
FIFO queuecollections.dequeO(1) appendleft/popleftBFS in level_order_traversal.py, word_ladder.py
Priority queueheapqO(log n) push/popdijkstra.py, kth_largest.py, merge_k_sorted_lists.py
Stack (LIFO)list with append/popO(1) amortizedvalid_parentheses.py, daily_temperatures.py
Sorted containerbisect moduleO(log n) searchlongest_increasing_subseq.py, hypothesis_patterns.py
Disjoint setsUnion-Find class~O(alpha(n)) amortizedminimum_spanning_tree.py
Spatial indexKD-tree / geohashO(log n) nearest neighborkd_tree.py, geohash_grid.py
Cache with evictionOrderedDict / DLL+dictO(1) get, put, evictlru_cache.py

When to pick what

Need key -> value?          --> dict
Need "is X in the set?"     --> set
Need min/max repeatedly?    --> heapq
Need FIFO?                  --> collections.deque
Need LIFO?                  --> list (append/pop)
Need sorted insert + search --> bisect / SortedList
Need merge/find groups?     --> Union-Find
Need nearest in 2D/3D?      --> KD-tree or geohash

Section 3: Concept Modules -- When to Study Each

Concept ModuleStudy When...Key Functions / ClassesCross-References
t_strings.pyLearning Python 3.14 features, preventing injectionsql_safe(), html_safe(), structured_log(), render()PEP 750, ref sheet 09 (Python 3.14)
advanced_typing.pyWriting typed Python, understanding Protocol vs ABCDrawable Protocol, Stack[T], Container[T], @overload, TypeGuardPEP 544/612/647/695/696, ref sheet 09
hypothesis_patterns.pyLearning property-based testing, finding edge casesSortedList, BoundedCounterHypothesis docs, ref sheet 09, tests/concepts/test_hypothesis_patterns.py
fft_dct.pySignal processing, frequency analysis, sensor datacompute_fft(), filter_signal(), compute_dct(), spectral_analysis()Radar, telemetry, radio, and other sensor streams
modern_flask.pyWeb API patterns, app factory, testingcreate_app(), api_bp Blueprint, ValidationErrorSystem design round, API questions
validation.pyData validation, API boundaries, Pydantic v2 vs ZodUser model, Address, Shape discriminated union, serialize_user()Practical problem solving round

Concept -> Algorithm connections

  • t_strings demonstrate the template pattern -- same concept as parameterized queries in sql_safe(), analogous to how DP builds solutions from templates
  • advanced_typing shows Stack[T] -- the same LIFO structure used in valid_parentheses.py and daily_temperatures.py
  • hypothesis_patterns uses bisect -- the same binary search strategy in longest_increasing_subseq.py
  • fft_dct is pure signal processing -- relevant for sensor data pipelines
  • modern_flask is the API layer -- pairs with validation.py for full request lifecycle
  • validation with Pydantic is the runtime counterpart to advanced_typing's static type system

Section 4: Quick Decision Tree

START: What does the problem ask for?
|
+-- "Find / search for something"
|   |
|   +-- Input is sorted?
|   |   +-- YES --> Binary search (searching/binary_search.py)
|   |   |           Rotated? --> search_rotated_array.py, find_minimum_rotated.py
|   |   +-- NO  --> Hash map O(n) lookup (arrays/two_sum.py pattern)
|   |
|   +-- Find in a graph?
|       +-- Unweighted shortest path --> BFS (graphs/number_of_islands.py pattern)
|       +-- Weighted, positive       --> Dijkstra (graphs/dijkstra.py)
|       +-- Weighted, negative       --> Bellman-Ford (graphs/bellman_ford.py)
|       +-- With heuristic           --> A* (graphs/a_star_search.py)
|
+-- "Optimize a value" (min cost, max profit, count ways)
|   |
|   +-- Overlapping subproblems?
|   |   +-- YES --> Dynamic programming (dp/)
|   |   |          1D: climbing_stairs.py, coin_change.py
|   |   |          2D: edit_distance.py, longest_common_subseq.py
|   |   |          Bitmask: traveling_salesman_dp.py
|   |   +-- NO  --> Greedy (prove greedy choice property)
|   |               merge_intervals.py, jump_game.py, interval_scheduling.py
|   |
|   +-- Need top-K or priority ordering?
|       +-- Kth element     --> Heap (heaps/kth_largest.py) or Quickselect (sorting/quickselect.py)
|       +-- Merge K streams --> Heap merge (heaps/merge_k_sorted_lists.py)
|
+-- "Generate all / enumerate"
|   |
|   +-- All subsets          --> Backtracking (backtracking/subsets.py)
|   +-- All permutations     --> Backtracking (backtracking/permutations.py)
|   +-- Combinations to sum  --> Backtracking with reuse (backtracking/combination_sum.py)
|   +-- Placement with rules --> Backtracking + pruning (backtracking/n_queens.py)
|
+-- "Process a sequence" (subarray, substring)
|   |
|   +-- Contiguous subarray/substring?
|   |   +-- YES --> Sliding window (sliding_window/)
|   |   |          Fixed size:    pattern in patterns/sliding_window.py
|   |   |          Variable size: min_window_substring.py, longest_substring_no_repeat.py
|   |   +-- NO  --> Subsequence: DP (dp/longest_increasing_subseq.py, longest_common_subseq.py)
|   |
|   +-- Next greater/smaller element? --> Monotonic stack (stacks_queues/daily_temperatures.py)
|   +-- Valid nesting?                --> Stack (stacks_queues/valid_parentheses.py)
|
+-- "Graph structure" (explicit or implicit)
|   |
|   +-- Connected components  --> DFS/BFS (graphs/number_of_islands.py) or Union-Find
|   +-- Dependency ordering   --> Topological sort (graphs/topological_sort.py)
|   +-- Cycle detection       --> Course schedule pattern (graphs/course_schedule.py)
|   +-- Clone / copy          --> BFS/DFS + visited map (graphs/clone_graph.py)
|   +-- Minimum spanning tree --> Kruskal's (graphs/minimum_spanning_tree.py)
|   +-- Maximum flow          --> Edmonds-Karp (graphs/network_flow.py)
|
+-- "Design a data structure"
    |
    +-- O(1) access + eviction --> LRU Cache (linked_lists/lru_cache.py)
    +-- O(1) min/max retrieval --> Min Stack (stacks_queues/min_stack.py)
    +-- Sorted insert + search --> SortedList with bisect (concepts/hypothesis_patterns.py)
    +-- Generic typed container -> Stack[T] (concepts/advanced_typing.py)

Section 5: Complexity Quick-Reference by Category

Use this to sanity-check your solution's complexity during an interview.

O(1) solutions

ProblemImplementation
Min stack operationsstacks_queues/min_stack.py
LRU cache get/putlinked_lists/lru_cache.py
Reverse bitsbit_manipulation/reverse_bits.py

O(n) solutions

ProblemImplementation
Two sumarrays/two_sum.py
Product except selfarrays/product_except_self.py
Top K frequentarrays/top_k_frequent.py
Container with most watertwo_pointers/container_with_most_water.py
Trapping rain watertwo_pointers/trapping_rain_water.py
Min window substringsliding_window/min_window_substring.py
Longest substring no repeatsliding_window/longest_substring_no_repeat.py
Valid parenthesesstacks_queues/valid_parentheses.py
Daily temperaturesstacks_queues/daily_temperatures.py
Reverse linked listlinked_lists/reverse_linked_list.py
Max depth of treetrees/max_depth.py
Invert treetrees/invert_tree.py
Validate BSTtrees/validate_bst.py
Level order traversaltrees/level_order_traversal.py
Climbing stairsdp/climbing_stairs.py
Single numberbit_manipulation/single_number.py
Counting bitsbit_manipulation/counting_bits.py
Task schedulerheaps/task_scheduler.py
Jump gamegreedy/jump_game.py
Quickselect (average)sorting/quickselect.py

O(n log n) solutions

ProblemImplementation
Three sumtwo_pointers/three_sum.py (sort dominates, then O(n^2) scan)
Longest increasing subseqdp/longest_increasing_subseq.py
Merge intervalsgreedy/merge_intervals.py
Interval schedulinggreedy/interval_scheduling.py
Merge sort inversionssorting/merge_sort_inversions.py

O(log n) solutions

ProblemImplementation
Binary searchsearching/binary_search.py
Search rotated arraysearching/search_rotated_array.py
Find minimum rotatedsearching/find_minimum_rotated.py

O(V+E) graph solutions

ProblemImplementation
Clone graphgraphs/clone_graph.py
Topological sortgraphs/topological_sort.py
Course schedulegraphs/course_schedule.py

O((V+E) log V) graph solutions

ProblemImplementation
Dijkstragraphs/dijkstra.py
Network delay timegraphs/network_delay_time.py
A* searchgraphs/a_star_search.py

Exponential solutions (backtracking)

ProblemImplementation
Subsets O(n * 2^n)backtracking/subsets.py
Permutations O(n * n!)backtracking/permutations.py
Combination sum O(2^target)backtracking/combination_sum.py
N queens O(n!)backtracking/n_queens.py
TSP O(n^2 * 2^n)dp/traveling_salesman_dp.py

Section 6: Pattern Recognition Cheat Sheet

When you read a problem statement, look for these keywords and jump to the right section.

Keyword in ProblemFirst Thing to TryIf That Fails
"sorted"Binary search, two pointers--
"contiguous subarray"Sliding windowPrefix sums, Kadane's
"substring"Sliding window + hash mapDP
"parentheses" / "brackets"Stack--
"next greater" / "next warmer"Monotonic stack--
"shortest path"BFS (unweighted), Dijkstra (weighted)Bellman-Ford (negative), A* (heuristic)
"connected" / "island" / "region"DFS/BFS flood fill, Union-Find--
"dependency" / "prerequisite"Topological sort--
"cycle"DFS coloring (directed), Union-Find (undirected)--
"minimum cost" / "count ways"Dynamic programming--
"all subsets" / "all combinations"BacktrackingBitmask enumeration
"merge" / "overlapping intervals"Sort + greedy sweep--
"kth largest" / "top k"Heap of size kQuickselect
"design" / "implement"Choose data structures, define API--
"cache" / "eviction"LRU = hash map + doubly linked list--
"stream" / "online"Heap, sliding window--
"frequency" / "how many times"Hash map / Counter--
"edit distance" / "transform"2D DPBFS (word_ladder)
"knapsack" / "subset sum"DP (1D or 2D)--
"schedule tasks"Heap + greedyTopological sort if deps
"maximum flow"Edmonds-Karp / Ford-Fulkerson--
"nearest point" / "proximity"KD-tree, geohash--
"visit all cities/nodes"TSP bitmask DP--
"XOR" / "single unique"Bit manipulation--

Section 7: Study Order Recommendations

If you have 2 hours (crunch mode)

  1. Skim this decision tree (Section 4) -- internalize the branching
  2. Review arrays/two_sum.py (hash map pattern)
  3. Review sliding_window/min_window_substring.py (window pattern)
  4. Review dp/coin_change.py (DP template)
  5. Review graphs/dijkstra.py (graph traversal)
  6. Review backtracking/subsets.py (enumeration template)

If you have 1 day

Add to the above:

  • All of Section 1 (scan for recognition, don't memorize)
  • trees/validate_bst.py + level_order_traversal.py
  • greedy/merge_intervals.py
  • linked_lists/lru_cache.py
  • concepts/modern_flask.py + concepts/validation.py

If you have 1 week

Work through every implementation in order:

  1. Arrays & hashing (day 1)
  2. Two pointers + sliding window (day 2)
  3. Stacks, searching, linked lists (day 3)
  4. Trees + graphs (day 4)
  5. DP + backtracking (day 5)
  6. Heaps, greedy, bit manipulation, sorting (day 6)
  7. Concept modules (day 7)

Cross-Reference to Other Sheets

SheetUse it for...
01-python-stdlib.mdPython built-in functions, data types, standard library
02-data-structures.mdDetailed data structure theory and operations
03-algorithm-templates.mdPseudocode templates for each algorithm family
04-big-o-complexity.mdComplexity analysis, input size -> acceptable complexity
05-common-patterns.mdProblem signal -> pattern mapping (compact version)
06-system-design.mdSystem design interview framework
07-interview-day-guide.mdDay-of logistics, communication framework, timing
08-cross-reference-guide.mdYou are here -- the master lookup
09-python-314-and-modern-patterns.mdPython 3.14 features, t-strings, typing, Hypothesis
This page lives in git. Anyone can propose an edit. Edit this page View source

A reading surface for the DSA study packet. Content is tracked in git; every page links to its source.