The Polish notation of the expression a + b * c + d ( where "+" is left associative):
A/ + + a * b c d
B/ + a * bc + d
C/ + + * a b c d
D/ + * bc + ad
Can anyone explain why the answer is A please? What is the best way to solve this kind of problem though?
Thanks
I assume that * has priority over +, but it is easier to show that explicitly using parentheses:
$a + (b*c) + d$
Now, you know that + is left associative, which means that this is evaluated as follows:
$(a + (b*c)) + d$
Finally, to show where the two + operators end up, let's label them:
$(a +_1 (b*c)) +_2 d$
OK, now put it in prefix (Polish notation) step by step:
$(a +_1 (b*c)) +_2 d \Rightarrow +_2 (a +_1 (b*c)) \: d \Rightarrow +_2 +_1 a \: (b*c) \: d \Rightarrow +_2 +_1 a * b \: c \: d$
And so that's $+ + a * b \: c \: d$