Published Aug 10, 2022Updated Oct 26, 2022
Contribute to Docs
Preorder traversal is a depth-first search algorithm for a binary search tree that first traverses the root, then the left subtree, and then the right subtree. Its primary use is to create a copy of the tree.
The preorder algorithm can be described as follows:
Function Preorder(tree) return root + Preorder(left-subtree) + Preorder(right-subtree)
For the following binary search tree:
Preorder traversal provides the nodes in the following order:
Looking to contribute?
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.
Learn More on Codecademy
Computer ScienceLooking for an introduction to the theory behind programming? Master Python while learning data structures, algorithms, and more!
Includes 6 Courses
With Professional Certification