Just wanna have it checked if i'm doing this rightly...

i was given an expression to translate it into a polish notation and traversals.

the expression is

{( a + b ) - c } * { d * (e / f + g)}

here's my answer:

POSTFIX : a b + c - d e f g + / * *
PREFIX : * - + a b c * d / e + f g

PRE-ORDER : * - + a c b * d / e + f g
POST-ORDER: a b + c - f g + e / d * *
IN-ORDER : a + b - c * d * e / f + g

Dani AI

Generated

Key point: prefix (Polish) is the preorder of the expression tree (visit node, then left, then right), and postfix (reverse Polish) is the postorder (left, right, then node). was right to flag a mismatch — if prefix and a preorder traversal differ, the expression tree or the traversal order is wrong. Common causes are mis-parsed parentheses, incorrect operator precedence, or swapped left/right children when building the tree.

A short verification workflow:

  1. Parse the infix expression into a binary expression tree respecting parentheses and operator precedence (or use the shunting-yard algorithm to get postfix reliably).
  2. Produce prefix by a preorder walk (emit the node before its children) and postfix by a postorder walk (emit after children).
  3. For infix (inorder) output, emit parentheses around each operator node to preserve grouping; plain inorder without parentheses is ambiguous and will usually not match the original grouping.
    To test results, evaluate the original infix and the converted prefix/postfix with a few numeric substitutions — matching numeric results confirm correctness.

Troubleshooting tips: draw the tree and confirm left/right child order, check each parenthesis pair during parsing, and compare a shunting-yard-produced postfix with the postorder output. Helpful references: Polish notation, Tree traversal, Shunting-yard algorithm. , the corrections you made look like progress; focus next on tree construction and adding parentheses for inorder.

Recommended Answers

All 5 Replies

No, you aren't.

No, you aren't.

awww... :(

can you please help me understand this?

Why is your prefix notation and preorder traversal any different?

Why is your prefix notation and preorder traversal any different?

:(

that's how i understood it... :(

should they always be the same?

i'll try it again

pre-order:
* - + a b c * d / e + f g

post-order:
a b + c - f g + e / d * *

in-order:
a + b - c f + g e / d * *

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.