← All writing
Development

Binary tree traversal DFS BFS

Binary tree traversal

DFS

preorder

Root first, then left subtree, and then right subtree.

inorder

Left subtree first, then root, and then right subtree.

postorder

Left subtree first, then right subtree, and then root.

BFS

level order traversal

Start from root node and traverse its neighbours, and its second level neighbours and so on.