Breadth-First Traversal (BFT)
Also known as level-order traversal when applied to trees.
It starts at a node and explores all its immediate neighbors before moving on to child nodes.
Depth-First Traversal (DFT)
Also known as depth-first search.
It starts at a node and explores as for as possible along one branch before backtracking to other branches.
Preorder
Visit first root and then children.
preorder(node):
if node is null:
return
visit(node)
preorder(node.left)
preorder(node.right)
Inorder
Visit first left child, then root, finally right child. Put root in-between children.
inorder(node):
if node is null:
return
inorder(node.left)
visit(node)
inorder(node.right)
Postorder
Visit first left child, then right child, finally the root. Put root after children.
postorder(node):
if node is null:
return
postorder(node.left)
postorder(node.right)
visit(node)