VOOZH about

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

⇱ Postorder Traversal of Binary Tree - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Postorder Traversal of Binary Tree

Last Updated : 7 Oct, 2025

Given a root of the binary tree, return the postorder traversal of the binary tree.

Postorder Traversal is a method to traverse a tree such that for each node, you first traverse its left subtree, then its right subtree, and finally visit the node itself.

Examples:

Input:

👁 20

Output: [2, 3, 1]
Explanation: Postorder Traversal visits the nodes in the following order: Left, Right, Root. Therefore, we visit the left node 2, then the right node 3 and lastly the root node 1.

Input:

👁 24

Output: [4, 5, 2, 6, 3, 1]
Explanation: Postorder Traversal visits the nodes in the following order: Left, Right, Root. Therefore resulting is 4 , 5, 2, 6, 3, 1.

[Approach] Using Recursion

The main idea is to traverse the tree recursively, starting from the root node, and first completely traverse the left subtree, then completely traverse the right subtree, and finally visit the root node.

How does Postorder Traversal work?


Output
4 5 2 6 3 1 

Time Complexity: O(n)
Auxiliary Space: O(h), h is the height of the tree

  • In the worst case, h can be the same as n (when the tree is a skewed tree)
  • In the best case, h can be the same as log n (when the tree is a complete tree)

Key Properties:

Related articles:

Comment
Article Tags:
Article Tags: