Template relationship maps

Visual guides for how the collections connect — from shared primitives to traversal paradigms and optimization patterns.

Hub view All category collections orbit the master index.
LeetCode Template Hub Master hub connected to all template category collections. Template categories around the master index Each collection links back to the master categories post and shares core primitives. Master Categories & Templates Data Structures core primitives Array & Matrix String Linked List Tree BFS DFS Graph Stack Queue Heap DP · Greedy · Backtrack optimization paradigms DS Design Advanced Math · Search
Layer stack Foundation → domain structures → traversal → paradigms.
LeetCode Template Layers Four layers from foundation data structures to optimization paradigms. Template stack: bottom-up relationships Lower layers supply primitives; upper layers compose them into problem-solving patterns. Layer 1 · Foundation Data Structures & Core Algorithms BS · Prefix · Mono Stack/Queue · Heap · DSU · Trie · Seg/Fenwick Layer 2 · Domain structures Array & Matrix 2 pointers · window String KMP · parsing Linked List dummy · reverse Tree Search BS templates Layer 3 · Traversal & containers Stack Queue Heap BFS DFS Graph topo · Dijkstra · DSU Layer 4 · Paradigms & design DP Greedy Backtracking DS Design Advanced Math/Bit
Cross-links Which families reuse primitives from Data Structures & Core Algorithms.
LeetCode Template Cross Links Key reuse paths between template families. How templates borrow from each other Solid arrows = direct building blocks · Dashed = common pattern overlap Data Structures & Core BS · Prefix · Mono · Heap · DSU · Trie Array / String Search Stack Queue Heap Design BFS DFS Graph Tree Backtracking DP Greedy Advanced Tip: start from Data Structures, then pick the domain (array/graph/tree) before choosing DP / greedy / backtracking.

Data Structures & Core Algorithms

Subcategories: Binary search (bounds), Prefix sum & difference array, Monotonic stack/queue, Heap (K-way merge), DSU, Trie, Segment tree, Fenwick tree, Sparse table

Array & Matrix

Subcategories: Two Pointers, Sliding Window (fixed/variable), Prefix Sum / Difference Array, Binary Search (sorted/rotated), Matrix Operations (rotate, spiral), Array Manipulation (merge intervals, jump game)

String Processing

Subcategories: Sliding Window (longest substring, minimum window), Two Pointers (palindrome, reverse), String Matching (KMP), String Manipulation (anagrams, duplicates), Parsing (decode string, abbreviations)

Linked List

Subcategories: Basic Operations (traversal, insertion, deletion), Two Pointers (fast/slow, kth from end), Dummy Node Pattern, Reversal (entire list, between positions, k-group), Merge (two sorted, k sorted), Cycle Detection, Circular Linked List

Tree

Subcategories: Tree Traversals (iterative inorder/level-order), LCA (Binary Lifting), HLD (Heavy-Light Decomposition) skeleton, BST operations, Tree DFS patterns

BFS

Subcategories: Basic BFS (graph traversal), BFS on Grid (4/8-directional), Multi-source BFS, BFS for Shortest Path (unweighted), Level-order Traversal (tree), BFS with State

DFS

Subcategories: Basic DFS (graph traversal), DFS on Grid (connected components, paths), DFS on Tree (preorder, inorder, postorder), DFS with Memoization, Iterative DFS (using stack)

Dynamic Programming

Subcategories: 1D DP (Knapsack/linear transitions), 2D DP (grid paths/obstacles), Digit DP (count numbers with property), Bitmask DP (TSP/subsets), LIS (Patience Sorting)

Backtracking

Subcategories: Permutations (with/without duplicates), Combinations (choose k from n), Subsets (power set generation), Combination Sum (unbounded/reuse elements), Grid Backtracking (Word Search, path finding), Constraint Satisfaction (N-Queens, Sudoku), Palindrome Partitioning

Greedy

Subcategories: Interval Scheduling, Activity Selection, Greedy on Arrays (Kadane's, stock problems), Greedy on Strings (subsequence matching), Greedy with Sorting (assign cookies, queue reconstruction), Jump Problems, Scheduling Problems

Stack

Subcategories: Stack (expression evaluation, parentheses matching), Monotonic Stack, Calculator (basic, II, III), Reverse Polish Notation, Nested Structure Processing

Queue

Subcategories: Basic Queue Operations, BFS with Queue, Monotonic Queue (sliding window max), Priority Queue (heap, k-way merge, top k), Circular Queue, Double-ended Queue (Deque)

Heap

Subcategories: Min Heap, Max Heap, Custom Comparators (struct, lambda), K-way Merge, Top K Elements, Two Heaps (median finding), Dijkstra's Algorithm, Frequency-Based Problems, Scheduling Problems

Graph

Subcategories: BFS / Shortest Path (unweighted), Multi-source BFS (grids/graphs), BFS on Bitmask State (visit all keys), Topological Sort (Kahn / DFS), Dijkstra (nonnegative weights), 0-1 BFS (edge weights 0 or 1), Disjoint Set Union (DSU), Tarjan SCC (strongly connected components), Bridges & Articulation Points

Data Structure Design

Subcategories: LRU Cache, LFU Cache, Trie (Prefix Tree), Time-based Key-Value Store, Design Patterns (Random Pick with Weight, Tic-Tac-Toe)

Advanced Algorithms

Subcategories: Coordinate Compression, Meet-in-the-Middle (subset sums), Manacher (longest palindromic substring O(n)), Z-Algorithm (pattern occurrences), Bitwise Trie (max XOR pair), Sweep Line (intervals)

Math & Bit Manipulation

Subcategories: Bit Operations (set, clear, toggle, count), Common Bit Tricks (lowest set bit, power of 2), Single Number problems, Gray Code, Fast Exponentiation, GCD and LCM, Prime Numbers (Sieve of Eratosthenes), Number Theory

Search

Subcategories: Binary Search (sorted array, rotated array, answer space), Search in 2D Matrix, Advanced Search (merge sort on prefix sums, divide and conquer), Search Templates and Patterns