Efficient Bill-of-Materials Algorithms