Tree Traversal: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
(Created page with "=Internal= * Tree Concepts =Depth First= =Breadth First= =In-Order= '''In-order tree walk''' can be used to print a binary search tree node keys...")
 
m (Ovidiu moved page Tree Walking to Tree Traversal without leaving a redirect)
(No difference)

Revision as of 22:25, 10 November 2021

Internal

Depth First

Breadth First

In-Order

In-order tree walk 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).

Preorder

Postorder