Solving a Postfix Expression: ABCD+*/E- Tree

  • Thread starter Thread starter Bucs44
  • Start date Start date
  • Tags Tags
    Expression Tree
Click For Summary

Homework Help Overview

The discussion revolves around interpreting a postfix expression and constructing a corresponding binary tree. The expression in question is ABCD+*/E-.

Discussion Character

  • Exploratory, Conceptual clarification, Problem interpretation

Approaches and Questions Raised

  • Participants explore the structure of the binary tree, particularly focusing on the left side involving ABCD and the right side with operators. There is a discussion on how to utilize a stack for parsing the expression and the sequence of operations involved.

Discussion Status

The conversation is active, with participants offering insights into the parsing process and the relationship between the postfix notation and the binary tree structure. Some guidance on using a stack to manage the operations has been suggested, though multiple interpretations of the tree structure are being explored.

Contextual Notes

There is a mention of the need to consider the equivalent infix expression, which may provide additional clarity in understanding the postfix structure. Participants are also navigating the complexities of tree construction based on the order of operations in the expression.

Bucs44
Messages
57
Reaction score
0

Homework Statement


I am having a hard time figuring out this postfix expression and turning it into a binary tree: ABCD+*/E-



The Attempt at a Solution



what's confusing me is the left side of the tree - the ABCD - I know the right side of the tree would look like this: - is the root and * / E

Any help would be greatly appreciated
 
Physics news on Phys.org
When you see a letter, think of it as an instruction to put it on a stack. When you see an operator, think of pulling the last two things off the stack and pushing the result of the operation back on the stack. So after you've parsed the ABCD, you have four things on the stack waiting for later operations.
 
What needs to be parsed? AB on the left and CD on the right?
 
Bucs44 said:
What needs to be parsed? AB on the left and CD on the right?

?? Neither. I can't start drawing a tree until I hit the +, at which point I realize C and D are leaves of the + node. Then the + node is itself a leaf of the * node, to get the other leaf I go back and see what's on the stack and there is a B etc etc.
 
(This belongs into the computer homework section.)

It might be instructive for you to work out the equivalent infix expression.
 

Similar threads

  • · Replies 3 ·
Replies
3
Views
3K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 2 ·
Replies
2
Views
2K
Replies
1
Views
2K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 16 ·
Replies
16
Views
2K
  • · Replies 2 ·
Replies
2
Views
1K
  • · Replies 3 ·
Replies
3
Views
2K
Replies
7
Views
2K
  • · Replies 5 ·
Replies
5
Views
2K