Is this Tree of Algebraic Expression Correct?

  • Context: MHB 
  • Thread starter Thread starter Brian82784
  • Start date Start date
  • Tags Tags
    Expression Tree
Click For Summary
SUMMARY

The discussion centers on the construction of two trees representing the algebraic expression ((x - 2) + 3) / ((2 - (3 + y)) x (w - 8)). Participants confirm that the tree on the right is correct, evaluating the expression as ((x + 2) - 3) / ((2 - (3 + y)) * (w - 8)), while the left tree is incorrect due to misplacement of the denominator. Preorder, inorder, and postorder search results for both trees are provided and analyzed, leading to a consensus on the correctness of the right tree.

PREREQUISITES
  • Understanding of algebraic expressions and their tree representations
  • Familiarity with preorder, inorder, and postorder traversal methods
  • Knowledge of operator precedence in mathematical expressions
  • Experience with Reverse Polish Notation (postfix notation)
NEXT STEPS
  • Study tree data structures in computer science
  • Learn about expression evaluation techniques using stacks
  • Explore the implementation of algebraic expression trees in programming languages
  • Research mathematical operator precedence and its implications in expression evaluation
USEFUL FOR

Mathematicians, computer scientists, students studying data structures, and anyone interested in algebraic expression evaluation and tree structures.

Brian82784
Messages
19
Reaction score
0
Hello I just wanted to see if I did this right. I've come up with two trees and I'm pretty sure one of them is correct, I'm just not sure.

Construct the Tree of the algebraic expression:
((x - 2) + 3) / ((2 - (3 + y)) x (w - 8))
 

Attachments

  • Tree.jpg
    Tree.jpg
    5.9 KB · Views: 126
  • tree2.jpg
    tree2.jpg
    5.7 KB · Views: 135
Last edited:
Physics news on Phys.org
Kristen said:
Hello I just wanted to see if I did this right. I've come up with two trees and I'm pretty sure one of them is correct, I'm just not sure.

Construct the Tree of the algebraic expression:
((x - 2) + 3) / ((2 - (3 + y)) x (w - 8))

Hi! :) I think that both of them are right,but it would be better to include also the parentheses of the algebraic expression at the trees,that you constructed.
 
Okay thank you. I also had to do this with one of the trees. So I picked the first tree. Does this look correct?

1) Show the results of performing a preorder search.
× ÷ + - X 2 3 - - 2 3 Y - W 82) Show the results of performing an inorder search.
X – 2 + 3 ÷ 2 – 3 – Y × W - 8 3) Show the results of performing a postorder search.
X 2 - 3 + 2 3 - y - ÷ W 8 - ×
 
Kristen said:
Okay thank you. I also had to do this with one of the trees. So I picked the first tree. Does this look correct?

1) Show the results of performing a preorder search.
× ÷ + - X 2 3 - - 2 3 Y - W 82) Show the results of performing an inorder search.
X – 2 + 3 ÷ 2 – 3 – Y × W - 8 3) Show the results of performing a postorder search.
X 2 - 3 + 2 3 - y - ÷ W 8 - ×

I also tried it,and found the same result as yours!It should be right! (Nod) (Yes)
 
The one on the right is correct, the one on the left is incorrect. The one on the left is evaluating the expression $\dfrac{(x-2)+3}{(2-3)-y}(w-8),$ whereas the one on the right is evaluating the expression $\dfrac{(x+2)-3}{(2-(3+y)) \cdot (w-8)}$. You can see that in the left version, $w-8$ is in the numerator, whereas in the right version, $w-8$ is in the denominator.
 
So the one I did starting with Division is actually correct
 
Ackbach said:
The one on the right is correct, the one on the left is incorrect. The one on the left is evaluating the expression $\dfrac{(x-2)+3}{(2-3)-y}(w-8),$ whereas the one on the right is evaluating the expression $\dfrac{(x+2)-3}{(2-(3+y)) \cdot (w-8)}$. You can see that in the left version, $w-8$ is in the numerator, whereas in the right version, $w-8$ is in the denominator.

Oh,yes you are right! Sorry for assuming that the left tree is also right.. (Sadface)
 
Kristen said:
So the one I did starting with Division is actually correct

Right - the "biggest" mathematical operator is the last one you'd evaluate.

By the way, the only reason I can answer this question is that http://mathhelpboards.com/mathematics-software-calculator-discussion-29/hp-50g-1953.html?highlight=calculator, with Reverse Polish Notation (postfix notation) and a stack. That's a very nice combination, because it let's you play with calculations as you go.
 
So then would this be correct for the tree on the right?

1) Show the results of performing a preorder search.
÷ + - X 2 3 × - 2 + 3 Y- W 82) Show the results of performing an inorder search.
X – 2 + 3 ÷ 2 – 3 +Y × W - 8 3) Show the results of performing a postorder search.
X 2 - 3 + 2 3 y +- W 8 - ×÷
 
  • #10
Kristen said:
So then would this be correct for the tree on the right?
Yes, they seem correct.
 

Similar threads

  • · Replies 16 ·
Replies
16
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 19 ·
Replies
19
Views
2K
  • · Replies 7 ·
Replies
7
Views
2K
  • · Replies 18 ·
Replies
18
Views
3K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 6 ·
Replies
6
Views
1K
Replies
9
Views
2K