6

I was asked to convert 7-2+3 into post fix notation while no operator precedence or left to right or right to left was mentioned in the question and then I had to make tree using translation scheme of the post fix notion ed result.

I found it ambiguous because 7-2+3 may give 2 possible results 8 and 2 so I wrote two post fix notations 72-3+ & 723+- and made two possible trees using translation scheme.

I want to confirm either I was Correct or Not.

2 Answers2

1

If you apply Shunting-yard algorithm to 7-2+3 the output is 72-3+

Note: + and - are left associative and have the same precedence unless otherwise indicated

ivangalbans
  • 470
  • 5
  • 14
0

Postfix notation is also called as 'suffix notation' and 'reverse polish'. linear representation of a syntax tree. In the postfix notation, any expression can be written unambiguously without parentheses.

in first part of your question for postfix notation of any infix expression: **

Scan the infix expression from left to right.

** so following the algorithm this one is correct 72-3+ and for this you have to make tree or what ever there is mentioned.. for further details regarding postfix rules check it out

https://www.geeksforgeeks.org/stack-set-2-infix-to-postfix/

leh me know if you find it useful

sabeen kanwal
  • 607
  • 1
  • 5
  • 16