Data Structures Questions and Answers Part-15

1. What is the postfix expression for the corresponding infix expression?
a+b*c+(d*e)
a) abc*+de*+
b) abc+*de*+
c) a+bc*de+*
d) abc*+(de)*+

Answer: a
Explanation: Using the infix to postfix expression conversion algorithm, the corresponding postfix expression is found to be abc*+de*+.

2. Parentheses are simply ignored in the conversion of infix to postfix expression.
a) true
b) false

Answer: b
Explanation: When a parenthesis is encountered, it is placed on the operator stack. When the corresponding parenthesis is encountered, the stack is popped until the other parenthesis is reached and they are discarded.

3. It is easier for a computer to process a postfix expression than an infix expression.
a) true
b) false

Answer: a
Explanation: Computers can easily process a postfix expression because a postfix expression keeps track of precedence of operators.

4. What is the postfix expression for the infix expression?
a-b-c
a) -ab-c
b) ab – c –
c) – -abc
d) -ab-c

Answer: b
Explanation: The corresponding postfix expression for the given infix expression is found to be ab-c- and not abc- -.

5. What is the postfix expression for the following infix expression?
a/b^c-d
a) abc^/d-
b) ab/cd^-
c) ab/^cd-
d) abcd^/-

Answer: a
Explanation: Using the infix to postfix conversion algorithm, the corresponding postfix expression for the infix expression is found to be abc^/d-.

6. Which of the following statement is incorrect with respect to infix to postfix conversion algorithm?
a) operand is always placed in the output
b) operator is placed in the stack when the stack operator has lower precedence
c) parenthesis are included in the output
d) higher and equal priority operators follow the same condition

Answer: c
Explanation: Parentheses are not included in the output. They are placed in the operator stack and then discarded.

7. In infix to postfix conversion algorithm, the operators are associated from?
a) right to left
b) left to right
c) centre to left
d) centre to right

Answer: b
Explanation: In infix, prefix and postfix expressions, the operators are associated from left to right and not right to left.

8. What is the corresponding postfix expression for the given infix expression?
a*(b+c)/d
a) ab*+cd/
b) ab+*cd/
c) abc*+/d
d) abc+*d/

Answer: d
Explanation: Using the infix to postfix conversion algorithm, the corresponding postfix expression is obtained as abc+*d/.

9. What is the corresponding postfix expression for the given infix expression?
a+(b*c(d/e^f)*g)*h)
a) ab*cdef/^*g-h+
b) abcdef^/*g*h*+
c) abcd*^ed/g*-h*+
d) abc*de^fg/*-*h+

Answer: b
Explanation: Using the infix to postfix expression conversion algorithm using stack, the corresponding postfix expression is found to be abcdef^/*g*h*+.

10. What is the correct postfix expression for the following expression?
a+b*(c^d-e)^(f+g*h)-i
a) abc^de-fg+*^*+i-
b) abcde^-fg*+*^h*+i-
c) abcd^e-fgh*+^*+i-
d) ab^-dc*+ef^gh*+i-

Answer: c
Explanation: The postfix expression for the given infix expression is found to be abcd^e-fgh*+^*+i- when we use infix to postfix conversion algorithm.