-
-
Notifications
You must be signed in to change notification settings - Fork 47.1k
Labels
enhancementThis PR modified some existing filesThis PR modified some existing files
Description
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?
tianyizheng02 and bhaskar253
Metadata
Metadata
Assignees
Labels
enhancementThis PR modified some existing filesThis PR modified some existing files