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.

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:

  1. Visit the current node and display its data.

  2. Traverse the left sub-tree of currentNode, recursively using the PreOrder() function.

  3. Traverse the right sub-tree of currentNode, recursively using the PreOrder() function.

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