Binary Tree Traversals
You are provided with a binary tree consisting of integer-valued nodes. The task is to compute the In-Order, Pre-Order, and Post-Order traversals for the given binary tree.
Input:
The input begins with an integer 'T', representing the number of test cases.
For each test case, a line of integers is provided, denoting the tree's nodes in level order. Use -1 for any null node.
Output:
For each test case, return a nested list containing the three traversals (In-Order, Pre-Order, Post-Order).
Each traversal will be a list of integers, printed in separate lines in the specified order.
Example:
For a binary tree like the following:
[Image of a binary tree]
In-Order traversal: [5, 3, 2, 1, 7, 4, 6]
Pre-Order traversal: [1, 3, 5, 2, 4, 7, 6]
Post-Order traversal: [5, 2, 3, 7, 6, 4, 1]
Constraints:
1 ≤ T ≤ 100
0 ≤ N ≤ 3000
0 ≤ data ≤ 10^9
Note:
- A non-null node from a previous level becomes the parent of the first two nodes of the current level.
- Input ends when nodes at the last level are all null (-1).
- The tree is represented in a single line for each test case.

AnswerBot
4mo
Compute In-Order, Pre-Order, and Post-Order traversals for a given binary tree.
Implement tree traversal algorithms like In-Order, Pre-Order, and Post-Order.
Use recursion to traverse the binary tree ef...read more
Help your peers!
Add answer anonymously...
Cisco Software Developer Intern interview questions & answers
A Software Developer Intern was asked 9mo agoQ. Dijkastra's Algorithm
A Software Developer Intern was asked Q. Binary Tree Traversals You are provided with a binary tree consisting of integer...read more
A Software Developer Intern was asked Q. Remove Duplicates from String Problem Statement You are provided a string STR of...read more
Popular interview questions of Software Developer Intern
A Software Developer Intern was asked 10mo agoQ1. Dijkastra's Algorithm
A Software Developer Intern was asked Q2. Binary Tree Traversals You are provided with a binary tree consisting of integer...read more
A Software Developer Intern was asked Q3. Remove Duplicates from String Problem Statement You are provided a string STR of...read more
Stay ahead in your career. Get AmbitionBox app


Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+
Reviews
10L+
Interviews
4 Cr+
Salaries
1.5 Cr+
Users
Contribute to help millions
AmbitionBox Awards
Get AmbitionBox app

