Update appNew update is available. Click here to update.
sidenav-btnClose
Topic list
Postorder Traversal
EASY
8 upvotes
Stacks & Queues
Topics (Covered in this problem)
Problem solved
Badge
Skill meter
Stacks & Queues
-
-
Other topics
Problem solved
Badge
Skill meter
Strings
-
-
Matrices (2D Arrays)
-
-
Linked List
-
-
Sorting
-
-
Binary Search
-
-
Trees
-
-
Graph
-
-
Dynamic Programming
-
-
Greedy
-
-
Tries
-
-
Arrays
-
-
SQL
-
-
Binary Search Trees
-
-
Heap
-
-
Bit Manipulation
-
-
Solve problems & track your progress
Checkout your overall progress in every topic here
Become
userLevel
Sensei
in DSA topics
Open the topic and solve more problems associated with it to improve your skills
Check out the skill meter for every topic
See how many problems you are left with to solve for cracking any stage. Score more than zero to get your progress counted.

Postorder Traversal

Contributed by
Yash Chaudhari
Easy
yellow-spark
0/40
Share
8 upvotes

Problem Statement

You have been given a Binary Tree of 'N' nodes, where the nodes have integer values. Your task is to find the Post-Order traversal of the given binary tree.

For example :
For the given binary tree:

The Postorder traversal will be [5, 2, 3, 7, 6, 4, 1].
Detailed explanation ( Input/output format, Notes, Constraints, Images )
Sample Input 1 :
2
1 2 3 -1 -1 -1  6 -1 -1
1 2 3 -1 -1 -1 -1
Sample Output 1 :
2 6 3 1
2 3 1
Explanation of Sample Output 1 :
 In test case 1, the given binary tree is shown below:

Postorder traversal of given tree = [2, 6, 3, 1]

In test case 2, the given binary tree is shown below:

Postorder traversal of given tree = [2, 3, 1]
Sample Input 2 :
2
1 -1 -1
1 2 4 5 3 -1 -1 -1 -1 -1 -1
Sample Output 2 :
1
5 3 2 4 1
Explanation of Sample Output 2 :
In test case 1, there is only one node, so Post-Order traversal will be only [1].

In test case 2, the given binary tree is shown below:

Postorder traversal of given tree = [5, 3, 2, 4, 1]
Reset Code
Full screen
Auto
copy-code
Console