Challenge: Print Depth First Without Recursion

Let’s print a binary tree depth first without using recursion.

Problem

Given a binary tree, perform a depth-first search traversal on it by completing the PrintDepthFirst() function. The depth-first search (DFS) is an algorithm that starts from the root node of a tree and explores as far as possible along each branch before backtracking.

Input

A binary tree.

Output

Display the DFStraversal of the tree on the console.

Sample input

Level up your interview prep. Join Educative to access 70+ hands-on prep courses.