Ihtisham Ali Farooq
Ihtisham Ali Farooq

Reputation: 442

Possible Trees using translation scheme for post fix notation of 7-2+3

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.

Upvotes: 6

Views: 79

Answers (2)

sabeen kanwal
sabeen kanwal

Reputation: 607

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

Upvotes: 0

ivangalbans
ivangalbans

Reputation: 500

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

Upvotes: 1

Related Questions