Postorder Traversal
Published Aug 10, 2022
Contribute to Docs
Postorder traversal is a depth-first search algorithm for a binary search tree that first traverses the left subtree, then the right subtree, and then the root. Its primary use is deleting the tree.
Algorithm
The postorder algorithm can be described as follows:
Function Postorder(tree)
return Postorder(left-subtree) + Postorder(right-subtree) + root
Example
For the following binary search tree:
Postorder traversal provides the nodes in the following order: 1
, 3
, 2
, 5
, 7
, 6
, 4
.
Contribute to Docs
- 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
- Career path
Computer Science
Looking for an introduction to the theory behind programming? Master Python while learning data structures, algorithms, and more!Includes 6 CoursesWith Professional CertificationBeginner Friendly75 hours - Course
Learn Complex Data Structures
Discover and design new data structures that follow abstract rule-based systems by building out graphs, hash-maps, and heaps.With CertificateIntermediate7 hours