Feature description
Hi,
In binary_tree_traversals.py file, there are different kinds of traversals such as preorder, inorder, postorder and etc.
Although the implementations are pretty clean one-liner like:
# preorderreturn [root.data, *preorder(root.left), *preorder(root.right)] ifrootelse []
It isn't memory friendly. We can use generators instead not to load all the nodes into the memory:
# preorderifnotroot:
return []
yieldroot.datayieldfrompreorder(root.left)
yieldfrompreorder(root.right)
Shall we go ahead and change them?
Feature description
Hi,
In binary_tree_traversals.py file, there are different kinds of traversals such as
preorder,inorder,postorderand etc.Although the implementations are pretty clean one-liner like:
It isn't memory friendly. We can use generators instead not to load all the nodes into the memory:
Shall we go ahead and change them?