Skip to content

Instantly share code, notes, and snippets.

@satomacoto
Created February 13, 2013 07:31
Show Gist options
  • Save satomacoto/4942897 to your computer and use it in GitHub Desktop.
Save satomacoto/4942897 to your computer and use it in GitHub Desktop.
Binary tree, DP, DFS
def binary_tree_dp_dfs(n, k=1, a=[1]):
'''
>>> for x in binary(3): print x
[1, 2, 4]
[1, 2, 5]
[1, 3, 6]
[1, 3, 7]
'''
if n == k:
yield a
else:
for x in binary(n, k + 1, a + [a[-1] * 2]):
yield x
for x in binary(n, k + 1, a + [a[-1] * 2 + 1]):
yield x
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment