Iterative Binary Tree PreOrder Traversal in Java - Without Recursion

This is the second article on binary tree pre-order traversal in Java. In the first part, I have shown you how to traverse a binary tree with pre-order traversal using recursion, and in this article, you will learn how to implement pre-order traversal without using recursion. Just to revise, pre-order is a depth-first algorithm, where the depth of the tree is first explored before traversing sibling. In preOrder traversal, first, node or root is visited, then left subtree, and right subtree, hence it is also known as NLR (Node-Left-Right) algorithm. You might know that when you use recursion, methods calls are stored in an internal Stack which unwinds itself when algorithm reaches the base case. When recursion is not allowed, you can use the Stack data structure to create the same effect, in fact, this is also a common technique to convert a recursive algorithm into an iterative one.
Read more »