Inorder Traversal of Binary Tree Without Recursion
Given a Binary Tree consisting of 'N' nodes with integer values, your task is to perform an In-Order traversal of the tree without using recursion.
Input:
The first line contains an integer 'T' representing the number of test cases. The first line of each test case contains the tree elements in level order format. Values are separated by a single space, using '-1' for null nodes.
Output:
For each test case, return a list with the In-Order traversal of the binary tree. Output each traversal as a single line of 'N' space-separated integers.
Example:
Input:
1
1 3 8 5 2 7 -1 -1 -1 -1 -1 -1 -1
Output:
5 3 2 1 7 8
Constraints:
- 1 <= T <= 10
- 0 <= N <= 3000
- 0 <= data <= 10^9
Note:
- You are not required to print the output; just implement the function to return the result.
- This input format represents the tree in level order, with nodes at the last level denoted by -1 to indicate null values.

AnswerBot
4mo
Implement in-order traversal of a binary tree without recursion.
Use a stack to simulate the recursive in-order traversal process.
Start with the root node and keep traversing left until reaching a null...read more
Help your peers!
Add answer anonymously...
DE Shaw Mts1 interview questions & answers
A Mts1 was asked Q. What is the Banker's Algorithm?
A Mts1 was asked Q. Inorder Traversal of Binary Tree Without Recursion Given a Binary Tree consistin...read more
A Mts1 was asked Q. What is the difference between malloc() and calloc() in C?
Popular interview questions of Mts1
A Mts1 was asked Q1. What is the Banker's Algorithm?
A Mts1 was asked Q2. Inorder Traversal of Binary Tree Without Recursion Given a Binary Tree consistin...read more
A Mts1 was asked Q3. What is the difference between malloc() and calloc() in C?
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

