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:
# preorder
return [root.data, *preorder(root.left), *preorder(root.right)] if root else []
It isn't memory friendly. We can use generators instead not to load all the nodes into the memory:
# preorder
if not root:
return []
yield root.data
yield from preorder(root.left)
yield from preorder(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?