Skip to content
PalletLab
Complexity cheat sheet

Complexity cheat sheet

n = cartons on the pallet, k = contact corners, P = extreme points, R = multi-start runs, m = orders.

OperationComplexityNotes
AABB intersectionO(1)three interval overlaps
Check one placementO(n)single pass over placed cartons, plus the hull
Convex hull (monotone chain)O(k log k)the sort dominates
Point in convex polygonO(h)left of every edge
Center of mass (running sums)O(1) per queryinstead of O(n) recomputation
Greedy layer, full planO(n log n + n²)sort + row and rule checks
Extreme points, one runO(n · P · n) = O(n³)P grows linearly with n
Extreme points, multi-startO(R · n³)R = 12
Priority queue push/popO(log m)binary heap
Destination lookupO(1) averagehash map
BM25 search (assistant)O(chunks × query terms)over an inverted index
Welford mean and varianceO(1) per sampleone pass, numerically stable

Measured with Google Benchmark

micro_bench times the hot paths and fits a Big-O curve:

./build/release/micro_bench
# BM_CheckPlacement/64     ~ microseconds, fitted O(N)
# BM_ExtremePoints/80      ~ milliseconds, fitted O(N^3)

Why heuristics win in industry

An exact solver for 3D packing with stability constraints can take minutes or hours. A cell places a carton every 6–10 seconds, so a heuristic that is within a few percent of optimal in milliseconds is the right engineering choice.