0

I want to find the sum of all subsets of a powerset for a large-sized array (up to 1500). I searched but was unable to find an efficient algorithm for this.

Example:

array=[1,2,3]

Answer:

{} -> 0,{1} -> 1,{2} -> 2,{3} -> 3,{1,2} -> 3,{1,3} -> 4,{2,3} -> 5,{1,2,3} -> 6

Is there an efficient way to do so?

Lightness Races in Orbit
  • 378,754
  • 76
  • 643
  • 1,055
kvnt1102
  • 1
  • 2

1 Answers1

1

There are 2^n subsets of an array with n elements.

Each element will be present in exactly half of them.

Therefore the sum of all subsets will be the sum of all elements multiplied by 2n-1.

Columbo
  • 60,038
  • 8
  • 155
  • 203
Peter de Rivaz
  • 33,126
  • 4
  • 46
  • 75