Foundations
Linear Structures
Hashing
Array and String Patterns
Recursion, Search, and Sorting
Problem Solving Patterns
Algorithm Searching
Sorting Algorithms
Array Algorithms
Grid Algorithms
Linear Structure Algorithms
Hashing Algorithms
Recursion and Backtracking
Greedy Algorithms
Tree and Heap Algorithms
Graph Algorithms
Dynamic Programming Algorithms
String Algorithms
Math Algorithms
Keyboard ready
Space plays. Arrow keys step. R restarts.
LAB Backtracking Lab
Backtracking
Problem shape
Intermediate
4
8
15
16
23
42
Core idea
Build a candidate, recurse, then undo the choice when returning.
Step 1 / 5
Problem shape
Backtracking Intermediate
Backtracking
Welcome to the Backtracking algorithm lab. Build a candidate, recurse, then undo the choice when returning. Use it when: Use for permutations, subsets, combinations, constraints, and search spaces. The time complexity is Often exponential, and the space complexity is O(depth). The pseudocode is: search(state) if complete(state) record state for choice in choices if valid(choice) apply choice search(state) undo choice As you practice, track the state that changes and the condition that makes the algorithm stop.
Time
Often exponential
Space
O(depth)
Pseudocode
search(state)
if complete(state) record state
for choice in choices
if valid(choice)
apply choice
search(state)
undo choice 1.0x