Graphs & Greedy · 9 min read · Intermediate
Greedy Algorithms & Backtracking
Make locally optimal choices cleanly with Greedy interval scheduling, and explore combinations systematically with Backtracking.
What you'll learn
- Solve interval scheduling (non-overlapping meetings) with a Greedy sort-by-end-time strategy
- Generate subsets and combinations with recursive Backtracking (choose -> explore -> unchoose)
- Know when Greedy works vs. when Dynamic Programming is required
- Greedy: At every step, pick the locally best option (for example, sorting meetings by earliest end time to fit the maximum number of non-overlapping meetings).
- Backtracking: Explore a decision tree systematically using three lines: choose (
path.push(x)), explore (dfs(i + 1)), and unchoose (path.pop()).
Fill-in-the-Blank Exercise
Backtracking Choose & Unchoose
Push nums[i] onto path, recurse, then pop it to restore state.
path.(nums[i]);
backtrack(i + 1);
path.();Live DSA Playground
Generate All Subsets (Backtracking)
Live Result
Console Output
No console output yet. Try calling console.log(...) in JS.
Check Your Understanding
Score: 0 / 1
1. In the classic Greedy activity selection problem (fit the maximum number of non-overlapping meetings), how should you sort the intervals first?
Study Workspace
Finished this lesson?
Your progress is saved locally in your browser, no account needed.