Asked inDE Shaw,Mts1

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!
Select
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?
DE Shaw Mts1 Interview Questions
Stay ahead in your career. Get AmbitionBox app
play-icon
play-icon
qr-code
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

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2025 Info Edge (India) Ltd.

Follow Us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter
Profile Image
Hello, Guest
AmbitionBox Employee Choice Awards 2025
Winners announced!
awards-icon
Contribute to help millions!
Write a review
Write a review
Share interview
Share interview
Contribute salary
Contribute salary
Add office photos
Add office photos
Add office benefits
Add office benefits