Chapter 2 - Tree Traversal: DFS, BFS
This chapter goes over ADT, linked list and tree, but we are going to focus on tree traversal algorithm such as DFS and BFS
Understanding DFS
Preorder:
def PreOrder(root):
if not root:
return
print(root.val)
PreOrder(root.left)
PreOrder(root.right)Postorder:
def PostOrder(root):
if not root:
return
PostOrder(root.left)
PostOrder(root.right)
print(root.val)Inorder:
Applications on DFS

Understanding BFS
Last updated