BEGINNER · 10 MIN · FREE LESSON
Greedy algorithms
Explore greedy algorithms through a visual, step-by-step model.
Loading interactive lesson…
BEGINNER · 10 MIN · FREE LESSON
Explore greedy algorithms through a visual, step-by-step model.
Loading interactive lesson…
Use {"mode":"activities","intervals":[[1,3],[2,5],[3,4]]} or {"mode":"fractional-knapsack","items":[{"weight":10,"value":60},{"weight":20,"value":100}],"capacity":15}. Items are divisible only in fractional mode.
Empty
A greedy rule needs a proof tied to the exact problem constraints.
An exchange argument justifies earliest finishing for maximum-count interval scheduling. Value density is optimal for divisible fractional knapsack, but does not solve 0/1 knapsack.
Measured reads + comparisons, seed 42. Plotted sample sizes respect each lesson’s explicit input limits.
Keyboard: Space play/pause · ←/→ step · R restart · 1–5 speed. Reduced motion disables transitions.
Finish an activity early to preserve future room; pack divisible items by value density.
Choose locally only when an exchange proof permits it. Change the input to test a base case, a repeated subproblem and an unreachable or constrained state where applicable.
Predict a recurrence choice, comparison or valid search branch. Explain which stored state or constraint makes the next decision correct.
O(n log n) time and O(n) teaching copy. The player states the recurrence or greedy/search invariant and counts teaching operations rather than measuring animation time.
The four reference languages show the core operations under the same bounded input assumptions. Full tables preserve predecessor information for reconstruction; a table-only reference returns those states for the caller to backtrack. Backtracking references include N-Queens, subsets, permutations and a budgeted 9×9 Sudoku solver.
Use when a valid exchange argument makes local optimal decisions globally safe.
Fractional density greediness does not solve 0/1 knapsack. Weighted interval scheduling is also a different problem.
Check the state definition, cost model and boundary conditions below.
MAKE IT STICK
Progress saves on this device and merges with your account after sign-in.
0 / 5000 · Saved on this device; synced when signed in.