Pre-Order Traversal
In this lesson, we will cover the traversal strategy, 'Pre-Order Traversal', in a Binary Search Tree and implement it in JavaScript.
We'll cover the following
Introduction #
In pre-order traversal, the current node will be visited before its children nodes. Therefore, it is called the pre-order traversal.
The root of the tree will always be the first one to be visited.
In pre-order traversal, the elements are traversed in “root-left-right” order.
Here is a high-level description of the algorithm for Pre-Order traversal, starting from the root node:
-
Visit the
currentNode
, i.e., print the value stored at the node -
Call the
preOrderPrint()
function on the left subtree of thecurrentNode
. -
Call the
preOrderPrint()
function on the right subtree of thecurrentNode
.
Create a free account to view this lesson.
By signing up, you agree to Educative's Terms of Service and Privacy Policy