Based on a description from The Algorithm Design Manual book by Steven S. Skiena.
- Leverages the Dynamic Programming principle
- O(n²) complexity
- Fully annotated code
- Test suite
- Semver
composer require technically-php/linear-partitioning:^1.0
use \TechnicallyPhp\LinearPartitioning\LinearPartitioning;
$items = [100, 200, 300, 400, 500, 600, 700, 800, 900];
$ranges = LinearPartitioning::partition($items, 3);
var_dump($ranges);
// [ [100, 200, 300, 400, 500], [600, 700], [800, 900] ]
- Implemented by Ivan Voskoboinyk