Fractional Knapsack
Sort by value per weight; take whole items until one must be split to fill the remaining room exactly.
Decision · step 2 of 5Fractional Knapsack: The classic three items
Item a, 10 kg worth 60 (6 per kg), room 50. It fits whole: take it all, value 60.0, room 40.
What you will see
Items sorted by ratio fill a capacity bar; the last one is cut.
Cost
| Best | O(n log n) |
|---|---|
| Average | O(n log n) |
| Worst | O(n log n) |
| Space | O(1) |
How you work with it here
play it through, step one change at a time, scrub to any step, run it on your own input, predict what happens next.
Screen readers: Candidates announce their key and state (candidate, chosen, rejected); each step announces the local choice and its consequence.
Reduced motion: Chosen and rejected states crossfade; no travelling emphasis.