In-Order Traversal
Understand the in-order traversal method where nodes in a binary tree are visited in left-root-right sequence. This lesson teaches how to implement this traversal in JavaScript, enabling you to print tree elements in ascending order using recursion.
We'll cover the following...
Introduction #
In in-order traversal, the elements are traversed in “left-root-right” order so they are traversed in order.
In other words, elements are printed in sorted, ascending order with this traversal. We first visit the left child, then the root/parent node, and then the right child.
Here is a high-level description of the in-order traversal algorithm:
-
Traverse the left subtree of the
currentNoderecursively by calling theinOrderPrint()function on the left child. -
Visit
currentNodeand print its value. ...