Optimize traversal for without recursion

Last updated: April 25, 2026

Quick Overview

Given a binary tree, implement a function to traverse the tree in-order without using recursion. The function should take the root node of the tree as input and return a list of values representing the in-order traversal of the tree nodes.

DoorDash
Coding & Algorithms
Machine Learning Engineer
DoorDash
April 25, 2026
Machine Learning Engineer
Onsite
Coding & Algorithms
Easy

241

0

4,357 solved


Given a binary tree, implement a function to traverse the tree in-order without using recursion. The function should take the root node of the tree as input and return a list of values representing the in-order traversal of the tree nodes.

DoorDash uses this problem in the Onsite to evaluate your algorithmic thinking. They expect you to discuss multiple approaches, analyze trade-offs between them, and implement the optimal solution with clean, readable code.

What the Interviewer Expects
  • Identify the correct data structure and algorithm for the problem
  • Write clean, bug-free code with proper variable naming
  • Analyze time and space complexity correctly
  • Handle basic edge cases (empty input, single element)
  • Communicate your thought process while coding
Key Topics to Cover
Graph algorithms and traversal
Tree structures and recursion
Data structure selection and trade-offs
Binary search and divide and conquer
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
  • What is the worst-case input for your solution?
  • How would your solution change if the input was sorted?
  • How would you parallelize this solution?
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice DSA Problems
Sample Answer
Problem Analysis

In this problem, we need to perform an in-order traversal of a binary tree without using recursion. The in-order traversal visits nodes in the following order: left subtree, current node, right subtre...

Approach
  1. Initialize an empty stack to keep track of nodes and an empty result list to store the traversal order.
  2. Start from the root node and push all the left nodes onto the stack until you reach a null...

Submit Your Answer
Markdown supported

Related Questions