AlgoScope

Fractional Knapsack

AlgorithmintermediateGreedy

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
abcwvv/wtake10✓203060✓1001206✓541✓

Item a, 10 kg worth 60 (6 per kg), room 50. It fits whole: take it all, value 60.0, room 40.

Open in the player →or start at step 2

What you will see

Items sorted by ratio fill a capacity bar; the last one is cut.

How fractional knapsack works →

Cost

BestO(n log n)
AverageO(n log n)
WorstO(n log n)
SpaceO(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.

Before this