0

i have used the binary array to get the power set.it does the job in O(n^2) but i want to know any other more efficient way to get power set or any other way to get that without using arrays of bits.

ar=[1,2,3]
binary=[]
for i in range(1,(len(ar)**2)-1):
    if len(bin(i)[2:])<=len(ar)-1:
        binary.append((((len(ar))-len(bin(i)[2:]))*'0'+bin(i)[2:]))
    else:
        binary.append((bin(i)[2:]))
for i in binary:
    print('(',end='')
    for j in range(len(i)):
        if i[j]=='1':
            print(ar[j],end=' ')
    print(')',end='')
juanpa.arrivillaga
  • 88,713
  • 10
  • 131
  • 172
Rednivrug
  • 107
  • 1
  • 5

0 Answers0