Stack Expression Conversion: 18 flashcards

All 18 flashcards from this kit, free and with no sign-up.

1. What is the standard data structure used for converting infix expressions to postfix or prefix?

Show the answer

A stack, because it follows LIFO (Last In, First Out) order, which helps manage operator precedence and parentheses during conversion.

2. In the infix-to-postfix conversion algorithm, what happens when an operand (e.g., a variable or number) is read?

Show the answer

It is immediately appended to the output (postfix expression).

3. When converting infix to postfix using a stack, what is done with an opening parenthesis '('?

Show the answer

It is pushed onto the stack.

4. When converting infix to postfix, what happens when a closing parenthesis ')' is encountered?

Show the answer

Operators are popped from the stack and appended to the output until an opening parenthesis '(' is encountered. The '(' is then popped and discarded.

5. What is the rule for popping operators from the stack when a new operator is read during infix-to-postfix conversion?

Show the answer

Pop and output operators from the stack while they have higher or equal precedence to the new operator (for left-associative operators). Then push the new operator onto the stack.

6. Given the infix expression `A + B * C`, what is the postfix equivalent?

Show the answer

`A B C * +`

7. Given the infix expression `(A + B) * C`, what is the postfix equivalent?

Show the answer

`A B + C *`

8. What is the postfix form of the infix expression `A * (B + C) / D`?

Show the answer

`A B C + * D /`

9. What is the postfix form of the infix expression `A + B * C - D`?

Show the answer

`A B C * + D -`

10. What is the postfix form of the infix expression `A * B + C / D`?

Show the answer

`A B * C D / +`

11. What is the postfix form of the infix expression `(A + B) * (C - D)`?

Show the answer

`A B + C D - *`

12. What is the postfix form of the infix expression `A + B + C`?

Show the answer

`A B + C +`

13. What is the postfix form of the infix expression `A ^ B ^ C` (assuming right-associative exponentiation)?

Show the answer

`A B C ^ ^`

14. What is the prefix form of the infix expression `A + B * C`?

Show the answer

`+ A * B C`

15. What is the prefix form of the infix expression `(A + B) * C`?

Show the answer

`* + A B C`

16. What is the prefix form of the infix expression `A * (B + C) / D`?

Show the answer

`/ * A + B C D`

17. What is the prefix form of the infix expression `A + B * C - D`?

Show the answer

`- + A * B C D`

18. What is the prefix form of the infix expression `A * B + C / D`?

Show the answer

`+ * A B / C D`

Make your own

Your notes can be a kit like these

Every kit here was made from real study material. Point Veda at a chapter, a PDF, a photo or a link and get notes, flashcards, practice MCQs, games and a scored test — free, in 42 languages.

  • Chapter notes
  • Flashcards
  • Practice MCQs
  • Scored tests
  • Exam prep

Get Veda free See what students get

Free to start · No ads · Works in 42 languages