Binary tree: advantages of pre-ordering, post-traversal in binary tree?

Rotating through the order of the binary search tree yields the nodes in ascending order. But what are the advantages of preordering and traversal orders on any binary tree?

EDIT: Advantages I mean are "any situation where applying a pre-order or post-op workaround is particularly appropriate."

+3


source to share


1 answer


Not all binary trees have numbers in them. You can use a binary tree to represent objects that exhibit a tree structure, such as expressions. For example, it 2 * 3 + 4

can be represented as

              +
            /   \
           *     4
         /   \
        2     3

      

If you supply such an expression, traversal in order will result in your "normal" infix notation



2 * 3 + 4

      

but after-order traversal will give Reverse Polish Notation expressions:

2 3 * 4 +

      

+4


source







All Articles