Skip to content

Commit 1ab35fd

Browse files
committed
Working backtracking to generate all subsets of a set
1 parent bfc36cb commit 1ab35fd

1 file changed

Lines changed: 16 additions & 0 deletions

File tree

AllSubSets.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#Generate all subsuts of a set Tushar Roy methode
2+
3+
def foo(mainSet, result, index):
4+
print result
5+
for i in range(index, len(mainSet)):
6+
result.append(mainSet[i])
7+
foo(mainSet, result, i+1)
8+
#Backtrack
9+
result.pop()
10+
11+
12+
#Main Program
13+
foo(['a', 'a', 'b','c'], [], 0)
14+
print "With repeated characters such as this, we get set a,b,c printed twice"
15+
print "To avoid that just do what you did in stirng permutation method"
16+

0 commit comments

Comments
 (0)