There are three types of binary tree traversals

1. In – Order Traversal
2. Pre – Order Traversal
3. Post – Order Traversal

In – Order Traversal ( leftChild – root – rightChild )
In In-Order traversal, the root node is visited between left child and right child. In this traversal, the left child node is visited first, then the root node is visited and later we go for visiting right child node. This in-order traversal is applicable for every root node of all subtrees in the tree. This is performed recursively for all nodes in the tree.

Pre – Order Traversal ( root – leftChild – rightChild )
In Pre-Order traversal, the root node is visited before left child and right child nodes. In this traversal, the root node is visited first, then its left child and later its right child. This pre-order traversal is applicable for every root node of all subtrees in the tree.

Post – Order Traversal ( leftChild – rightChild – root )
In Post-Order traversal, the root node is visited after left child and right child. In this traversal, left child node is visited first, then its right child and then its root node. This is recursively performed until the right most node is visited.

Example : For the below tree,

• Inorder traversal gives:     2, 3, 4, 5, 6, 7, 8 , 9, 11, 12, 15, 19, 20
• Preorder traversal gives:   7, 4, 2, 3, 6, 5, 12, 9, 8, 11, 19, 15, 20
• Postorder traversal gives:  3, 2, 5, 6, 4, 8, 11, 9, 15, 20, 19, 12, 7

Code Example :- Tree Traversals (Inorder, Preorder and Postorder)