Postorder Tree Traversal: Calculating the Result

  • Context: MHB 
  • Thread starter Thread starter barbara
  • Start date Start date
  • Tags Tags
    Tree
Click For Summary

Discussion Overview

The discussion revolves around the application of a postorder tree traversal algorithm to a specific binary expression tree. Participants explore the steps of the traversal and the resulting computation, while also addressing formatting issues in the representation of the tree.

Discussion Character

  • Exploratory
  • Technical explanation
  • Debate/contested

Main Points Raised

  • One participant outlines the postorder traversal algorithm and asks for its application to a given binary tree.
  • Another participant begins to describe the traversal process, noting the pointer's movement through the tree and requesting further continuation.
  • There is a correction regarding a formatting typo in the tree representation, with participants discussing the correct structure of the tree.
  • A participant attempts to summarize the traversal process, detailing the left and right subtree expansions and the final computation, but there is a disagreement on the values derived from the traversal.
  • Another participant questions the certainty of the final answer provided and points out a potential error in the computed values.

Areas of Agreement / Disagreement

Participants express differing views on the correctness of the computed values from the traversal, particularly regarding the representation of the tree and the final result. No consensus is reached on the final answer.

Contextual Notes

There are unresolved issues regarding the accuracy of the computed values and the representation of the tree structure, which may affect the understanding of the traversal process.

barbara
Messages
10
Reaction score
0
The following algorithm describes a postorder tree traversal

Postorder(tree)

If left subtree exists then Postorder(left subtree)

If right subtree exists then Postorder(right subtree)

Print root

end



How can I apply that to the following tree





+

/ \

/ \

* -

/ \ / \

2 3 * +

/ \ / \

4 2 1 5



What is the result of the computation? What kind of algorithm is being used here?
 
Physics news on Phys.org
Firstly, the pointer shows to +. Then we notice that a left subtree exists , so we call the function Postorder(left subtree) and then the pointer shows to * . Can you continue?

P.S. : At the following part:

+

/ \

/ \

* -

this: / \ should appear only once. Is it a typo?
 
Last edited:
evinda said:
Firstly, the pointer shows to +. Then we notice that a left subtree exists , so we call the function Postorder(left subtree) and then the pointer shows to * . Can you continue?

P.S. : At the following part:

+

/ \

/ \

* -

this: / \ should appear only once. Is it a typo?
Yes its a typo
Thank you for your help and this is what the answer should look like. Please let me know if its correctThe is a representation of a recursion algorithm traverses the left subtree, the right subtree, and finally the root. That carries on the subtrees of the subtrees until a leaf is found. Thus, starting with +

/ \

/ \

* -

/ \ / \

2 3 * +

/ \ / \

4 2 1 5You start with the left subtree of the root, which is *

/ \

2 3The root of this tree is * , and it has a left subtree consisting of the leaf 2, and the right subtree consisting of the leaf 3. Going through the traversal, then this subtree is traversed as 2 3 *Now you expand the right subtree of the root of the tree. That is
-

/ \

* +

/ \ / \

4 2 1 5The left subtree is *

/ \

4 2 The expansion of this tree is 4 2 *The right subtree is is

+

/ \

1 5The expansion of this tree is 1 5 +The root of the right subtree is -so the expansion of the right subtree is (left) (right) (root) 4 3 * 1 5 + -Finallyyou put together the traversal of the entire tree is (left) (right) root2 3 * 4 3 * 1 5 + - +
The value is equal to 8
 
Last edited:
Barbara, in the future please use a text editor with a fixed-width font to type the tree and then copy and paste it between the [textdraw]...[/textdraw] tags, like this.

[textdraw]
+
/ \
/ \
/ \
* -
/ \ / \
2 3 * +
/ \ / \
4 2 1 5
[/textdraw]
barbara said:
this is what the answer should look like. Please let me know if its correct
How do you know that the answer should look like this if you are not sure whether it is correct?

barbara said:
2 3 * 4 3 * 1 5 + - +

According to the tree, it's 4 2 and not 4 3. Otherwise, it's correct.
 

Similar threads

  • · Replies 1 ·
Replies
1
Views
2K
Replies
14
Views
3K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 15 ·
Replies
15
Views
3K
  • · Replies 1 ·
Replies
1
Views
1K
  • · Replies 15 ·
Replies
15
Views
2K
  • · Replies 1 ·
Replies
1
Views
9K