What should be done when a left parenthesis ‘(‘ is encountered?
a) It is ignored
b) It is placed in the output
c) It is placed in the operator stack
d) The contents of the operator stack is emptied
Explanation: When a left parenthesis is encountered, it is placed on to the operator stack. When the corresponding right parenthesis is encountered, the stack is popped until the left parenthesis and remove both the parenthesis.
Which of the following is an infix expression?
a) (a+b)*(c+d)
b) ab+c*
c) +ab
d) abc+*
Explanation: (a+b)*(c+d) is an infix expression. +ab is a prefix expression and ab+c* is a postfix expression.
What is the time complexity of an infix to postfix conversion algorithm?
a) O(N log N)
b) O(N)
c) O(N2)
d) O(M log N)
Explanation: The time complexity of an infix to postfix expression conversion algorithm is mathematically found to be O(N).
Reversing a word using stack can be used to find if the given word is a palindrome or not.
a) True
b) False
Explanation: This application of stack can also be used to find if the given word is a palindrome because, if the reversed is same as that of the original word, the given word is a palindrome.
Which is the most appropriate data structure for reversing a word?
a) queue
b) stack
c) tree
d) graph
Explanation: Stack is the most appropriate data structure for reversing a word because stack follows LIFO principle.
Operations required for reversing a word or a string using stack are push() and pop().
a) True
b) False
Explanation: Push operation inserts a character into the stack and pop operation pops the top of the stack.