Recursion [mp]
Micro pattern¶
Description¶
Invoke the same operation on smaller structures, ranges, or remaining choices.
Problems¶
Backtracking recursion¶
Use calls for choices and undo mutable choices on return.
- 17. Letter Combinations of a Phone Number (Top Medium)
- 22. Generate Parentheses (Top Medium)
- 46. Permutations (Top Medium)
- 78. Subsets (Top Medium)
- 79. Word Search (Top Medium)
- 1079. Letter Tile Possibilities (Google Prep)
- 131. Palindrome Partitioning (Top Hard)
- 212. Word Search II (Top Hard)
- 301. Remove Invalid Parentheses (Top Hard)
- 797. All Paths From Source to Target (Graph Theory)
Structural tree recursion¶
Express tree operations using recursively processed subtrees.
- AVL trees (DSA)
- Inorder traversal (DSA)
- Postorder traversal (DSA)
- Preorder traversal (DSA)
- 98. Validate Binary Search Tree (Top Easy)
- 101. Symmetric Tree (Top Easy)
- 104. Maximum Depth of Binary Tree (Top Easy)
- 108. Convert Sorted Array to Binary Search Tree (Top Easy)
- 404. Sum of Left Leaves (Google Prep)
- 669. Trim a Binary Search Tree (Google Prep)
- 105. Construct Binary Tree from Preorder and Inorder Traversal (Top Medium)
- 297. Serialize and Deserialize Binary Tree (Top Medium)
- 95. Unique Binary Search Trees II (Dynamic Programming)
Graph and grid recursion¶
Recursively process unvisited neighbors in a component.
- DFS (DSA)
- 547. Number of Provinces (Google Prep)
- 200. Number of Islands (Top Medium)
- 1192. Critical Connections in a Network (Graph Theory)
Divide-and-conquer recursion¶
Recursively solve independent ranges before combining results.
- Top-down merge sort (DSA)
- Top-down merge sort linked list (DSA)
- Quick sort (DSA)
Linked-list recursion¶
Pass the preceding node as state while consuming the remaining suffix.
- 206. Reverse Linked List (Top Easy)
Memoized recursion¶
Cache results so repeated calls reuse prior work.
- 140. Word Break II (Top Hard)
- 95. Unique Binary Search Trees II (Dynamic Programming)
- 990. Satisfiability of Equality Equations (Graph Theory)
- 1061. Lexicographically Smallest Equivalent String (Graph Theory)
- 839. Similar String Groups (Graph Theory)