VOOZH about

URL: https://www.geeksforgeeks.org/dsa/binary-tree-traversal/

⇱ Binary Tree Traversal - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Binary Tree Traversal

Last Updated : 23 Jul, 2025

Binary trees are fundamental data structures in computer science and understanding their traversal is crucial for various applications. Traversing a binary tree means visiting all the nodes in a specific order. There are several traversal methods, each with its unique applications and benefits. This article will explore the main types of binary tree traversal: in-order, pre-order, post-order, and level-order.

Types of Binary Tree Traversal

1. In-Order Binary Tree Traversal

In in-order traversal, the left child is visited first, followed by the node itself, and then the right child. This can be visualized as Left - Root - Right.


Output
In-Order Traversal: 4 1 5 2 3 

Time Complexity: O(N)
Auxiliary Space: If we don’t consider the size of the stack for function calls then O(1) otherwise O(h) where h is the height of the tree.

Below are some important concepts in In-order Traversal:

2. Pre-Order Binary Tree Traversal

In pre-order traversal, the node is visited first, followed by its left child and then its right child. This can be visualized as Root - Left - Right.


Output
Pre-Order Traversal: 1 2 4 5 3 

Time Complexity: O(N)
Auxiliary Space: If we don’t consider the size of the stack for function calls then O(1) otherwise O(h) where h is the height of the tree.

Below are some important concepts in Pre-Order Traversal:

3. Post-Order Binary Tree Traversal

In post-order traversal, the left child is visited first, then the right child, and finally the node itself. This can be visualized as Left - Right - Root.


Output
Post-Order Traversal: 4 5 2 3 1 

Below are some important concepts in Post-Order Traversal:

4. Level-Order Binary Tree Traversal

In level-order traversal, the nodes are visited level by level, starting from the root node and then moving to the next level. This can be visualized as Level 1 - Level 2 - Level 3 - ....


Output
Level-Order Traversal: 1 2 3 4 5 

Below are some important concepts in Level-Order Traversal:

Special Binary Tree Traversals

All articles on Binary Tree !

Quick Links :

Comment
Article Tags:
Article Tags: