Computer Science
State TRUE or FALSE for the following cases:
(a) Stack is a linear data structure.
(b) Stack does not follow LIFO rule.
(c) PUSH operation may result into underflow condition.
(d) In POSTFIX notation for expression, operators are placed after operands.
Answer
(a) True
Reason — A stack is a linear data structure following the Last In, First Out (LIFO) principle, where elements are arranged sequentially.
(b) False
Reason — A stack follows the Last In, First Out (LIFO) rule. In a stack, the last element added is the first one to be removed from the stack.
(c) False
Reason — When attempting to remove an element (POP operation) from an empty stack, it leads to an underflow condition, resulting in an exception being raised.
(d) True
Reason — In POSTFIX notation for expression, operators are placed after the corresponding operands.
Related Questions
Find the output of the following code:
result = 0 numberList = [10, 20, 30] numberList.append(40) result = result + numberList.pop() result = result + numberList.pop() print("Result=", result)Find the output of the following code:
answer = []; output = '' answer.append('T') answer.append('A') answer.append('M') ch = answer.pop() output = output + ch ch = answer.pop() output = output + ch ch = answer.pop() output = output + ch print("Result=", output)Write a program to reverse a string using stack.
For the following arithmetic expression:
((2 + 3) * (4 / 2)) + 2
Show step-by-step process for matching parentheses using stack data structure.