Forty Items Two Halves

You have 40 weights and a target sum, and you must decide whether some subset hits the target exactly. Enumerating all subsets is 240≈1.10⋅10122^{40} \approx 1.10 \cdot 10^{12}, far too slow.

You split the 40 into two halves of 20, enumerate all 220=1 048 5762^{20} = 1,048,576 subset sums of each half, sort the left list, and for every right-half sum binary search the left list for the complement.

Roughly how many elementary operations does that plan cost?

A

About 1.1⋅10121.1 \cdot 10^{12}: splitting the input changes the constant factor but not the exponential term.

B

About 4⋅1074 \cdot 10^7: 2⋅2202 \cdot 2^{20} sums to generate, plus 220⋅202^{20} \cdot 20 to sort one half, plus 220⋅202^{20} \cdot 20 binary search steps.

C

About 2⋅1062 \cdot 10^6, just the 2⋅2202 \cdot 2^{20} subset sums, since sorting and searching are lower-order.

D

About 1.1⋅10121.1 \cdot 10^{12}, because every left sum still has to be checked against every right sum, and 220⋅220=2402^{20} \cdot 2^{20} = 2^{40}.