BEGINNER · 10 MIN · FREE LESSON
Divide & conquer
Explore divide & conquer through a visual, step-by-step model.
Loading interactive lesson…
BEGINNER · 10 MIN · FREE LESSON
Explore divide & conquer through a visual, step-by-step model.
Loading interactive lesson…
Enter integers to find a maximum-sum nonempty contiguous subarray using divide-and-conquer. Negative-only arrays return their least-negative element.
Every nonempty interval is solved by splitting, solving and combining.
Solve left and right halves, then scan a maximum suffix of the left half and a maximum prefix of the right half. The best interval is left-only, right-only or crossing the split.
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.
A best contiguous interval either stays in one half or crosses the dividing line.
Split, solve, then prove the combine step. 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(log n) call stack. 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 to understand divide-and-conquer recurrences and combining independently solved regions.
The requested interval is nonempty, so an all-negative array cannot return an empty zero-sum answer.
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.