Binary tree traversal: Preorder, Inorder, Post-order, BFS, DFS, Level Order, zig zag order
In order to illustrate the 3 traversals - pre order, in-order and post-order lets take following tree:
Preorder traversal:
To traverse a binary tree in Preorder, following operations are carried-out (i) Visit the root, (ii) Traverse the left subtree, and (iii) Traverse the right subtree.
Therefore, the Preorder traversal of the above tree will outputs:
7, 1, 0, 3, 2, 5, 4, 6, 9, 8, 10
Implementing pre-order traversal
[Read More]