Reputation: 11365
Inorder traversal of a Binary Search Tree yields nodes in increasing order. But what advantages do pre order and post order traversals have on any binary tree?
EDIT:What I mean by advantages is : "any situation where applying pre-order or post-order traversal is specifically suited".
Upvotes: 4
Views: 2692
Reputation: 726579
Not all binary trees have numbers in them. You can use a binary tree to represent things that exhibit tree structure, such as expressions. For example, 2 * 3 + 4
can be represented as
+
/ \
* 4
/ \
2 3
If you represent an expression like that, the in-order traversal would yield your "normal" infix notation of
2 * 3 + 4
but a post-order traversal would yield a Reverse Polish Notation of the expression:
2 3 * 4 +
Upvotes: 6