First-Fit Heuristic¶
Definition¶
The first-fit heuristic processes packing items in their given order. Place the current item into the first previously opened container with enough unused capacity. If no such container exists, open a new container and place the item there. Assume every item individually fits in a container.
Interpretation¶
First fit packs the items one at a time and never reconsiders a placement. Each item goes into the earliest opened container that still has room, and a new container is opened only when none has.
The figure follows the order with capacity . Items and share container 1, leaving units free. The does not fit there () and opens container 2. The fits neither container 1 () nor container 2 () and opens container 3. Two containers suffice for these items, so first fit is not optimal here.
Each part of the rule has a role. "First" means the earliest opened container, not the fullest or the emptiest one; another choice gives a different heuristic. Because an item is only placed where it fits, every intermediate packing respects capacity, and the assumption that each item fits into an empty container guarantees that opening a new container always works. The result depends on the item order: with the order the same items need only two containers.
As a heuristic for the bin packing problem, first fit gives a feasible packing and hence an upper bound on the minimum number of containers; comparing it with the total-weight lower bound shows how far from optimal it can be.
Key Results¶
- Every produced packing respects capacity.
- Its container count is an upper bound, not a proof of optimality.
- The exercise gives this procedure without a name; first-fit is its conventional search name.
Examples¶
The illustrated order with capacity 50 uses three containers under first fit. Two suffice with and , so that first-fit result is not optimal. Reordering the same items as makes first fit use two containers here.
- In the course exercise, items 1, 2, 3, and 9 fill container 1 to weight 49.
- Items 6, 7, and 8 fill another container to weight 49; the full heuristic packing uses five containers.
Prerequisites¶
Related Concepts¶
Sources¶
- OR Modelling · Week 1
Aliases: first-fit algorithm, first fit
Last updated: 20 October 2026 03:02
First-Fit HeuristicBin Packing ProblemHeuristicOptimization Bounds