Tree Traversal: Difference between revisions
Jump to navigation
Jump to search
Line 12: | Line 12: | ||
=<span id='Preorder'></span>Pre-Order= | =<span id='Preorder'></span>Pre-Order= | ||
Pre-order tree traversal means to first visit (process) the current node, then branches, starting with the left branch and continuing with the right branch. | |||
=<span id='Postorder'></span>Post-Order= | =<span id='Postorder'></span>Post-Order= | ||
=Depth First= | =Depth First= | ||
=Breadth First= | =Breadth First= |
Revision as of 22:30, 10 November 2021
Internal
In-Order
In-order traversal means to recursively visit the left branch, the node itself, and then the right branch (in order). In-order tree traversal can be used to print a binary search tree node keys in sorted order.
let r = root of the search tree with subtrees TL and TR recurse of TL # by recursion/induction, prints out keys of TL in increasing order print out r's key recurse of TR # by recursion/induction, prints out keys of TR in increasing order
The running time is O(n).
Pre-Order
Pre-order tree traversal means to first visit (process) the current node, then branches, starting with the left branch and continuing with the right branch.