Pre-Order Traversal in Binary Search Trees
In this lesson, we will cover the first traversal strategy in a Binary Search Tree-- Pre-Order Traversal--and implement it in code by using an example.
We'll cover the following
Pre-Order Traversal
In this type, the elements are traversed in “root-left-right” order. We first visit the root/parent node and then the children; First the left child and then the right one.
The following steps are required to perform Pre-Order Traversal, starting from the root node:
-
Visit the current node and display its data.
-
Traverse the left sub-tree of currentNode, recursively using the
PreOrder()
function. -
Traverse the right sub-tree of currentNode, recursively using the
PreOrder()
function.
Level up your interview prep. Join Educative to access 80+ hands-on prep courses.