Stacks
Question 1 |
Which of the following permutations can be obtained in the output (in the same order) using a stack assuming that the input is the sequence 1, 2, 3, 4, 5 in that order?
3, 4, 5, 1, 2 | |
3, 4, 5, 2, 1 | |
1, 5, 2, 3, 4 | |
5, 4, 3, 1, 2 |
Question 1 Explanation:
Push 1 Push 2 Push 3 Pop 3 Push 4 Pop 4 Push 5 Pop 5 Pop 2 Pop 1.
→ Remaining options are not possible.
→ Remaining options are not possible.
Question 2 |
Which of the following is essential for converting an infix expression to the postfix from efficiently?
An operator stack | |
An operand stack | |
An operand stack and an operator stack | |
A parse tree |
Question 2 Explanation:
An operator stack ⇒ Infix to (Postfix or Prefix)
An operand stack ⇒ Postfix to Prefix
Operator & operand stack ⇒ We don't use two stacks
Parse tree ⇒ No use
An operand stack ⇒ Postfix to Prefix
Operator & operand stack ⇒ We don't use two stacks
Parse tree ⇒ No use