Last active
September 14, 2022 02:41
-
-
Save nariaki3551/ec3b9a5f83157a734bea13d1e4575a8a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
depth = 3 | |
tree = [i for i in range(2**depth-1)] | |
def path_generator(node_ix): | |
if node_ix >= 2**(depth-1) - 1: # leaf node | |
yield [node_ix] | |
else: | |
for path in _dfs(2*node_ix+1): # left child | |
yield [node_ix] + path | |
for path in _dfs(2*node_ix+2): # right child | |
yield [node_ix] + path | |
root_ix = 0 | |
print(list(path_generator(root_ix))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment