Given a set of integers, is there an algorithm that returns the sum of all the subsets? For example if $s = \{6, 3, -2\}$ then the algorithm returns $28$. I.e:
$$(-2) + (3) + (3-2) + 6 + (6-2) + (6+3) + (6+3-2) = 28$$
The runtime of this is $\mathcal{O}(2^n)$ though I believe: is there a quicker way to do this?
Thanks
You are generating the Power set of some set $S$ with $n$ elements (denoted $\mathcal{P}(S)$) and then summing over all of the elements, so it would be impossible to have a runtime better than $\mathcal{O}(2^{n})$ because you need to generate and iterate over all of the $2^{n}$ possible subsets.