开发者

Postorder Traversal

In-order tree traversal 开发者_JAVA百科obviously has application; getting the contents in order.

Preorder traversal seems really useful for creating a copy of the tree.

Is there a common use for postorder traversal of a binary tree?


Let me add another one:

Postorder traversal is also useful in deleting a tree. In order to free up allocated memory of all nodes in a tree, the nodes must be deleted in the order where the current node can only be deleted when both of its left and right subtrees are deleted.

Postorder does exactly just that. It processes both of the left and right subtrees before processing the current node.


If the tree represents a mathematical expression, then to evaluate the expression, a post-order traversal is necessary.


Yes. Postorder is sometimes used to translate mathematical expressions between different notations.


It can also generate a postfix representation of a binary tree.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜