Playing as a guest? to earn XP and track your progress.
๐ฆ Data Structures (Stack) Quiz
๐ฆ Data Structures (Stack)
What does LIFO stand for in the context of a Stack data structure?
Last In First Out
List In First Out
Last In Fast Out
Latest Item First Out
LIFO stands for Last In First Out, meaning the last element added to the stack is the first one to be removed.
Which operation is used to insert an element into a Stack?
Insert
Add
Push
Append
The operation used to insert an element into a stack is called 'Push'.
Which operation is used to remove an element from a Stack?
Remove
Delete
Pop
Shift
The operation used to remove an element from the top of the stack is called 'Pop'.
What is the condition called when we try to POP an element from an empty stack?
Overflow
Underflow
Empty Exception
IndexError
Attempting to remove an element from an empty stack results in an Underflow condition.
What is the condition called when we try to PUSH an element into a stack that is already full?
Overload
Overflow
Out of Memory
Stack Full Error
Attempting to add an element to a stack that has reached its maximum capacity results in an Overflow condition.
Which built-in Python list method is commonly used to implement the PUSH operation of a stack?
insert()
add()
push()
append()
In Python, the list method append() adds an element to the end of the list, acting identically to a stack PUSH operation.
Which built-in Python list method is used to implement the POP operation of a stack?
remove()
delete()
pop()
discard()
The list method pop() removes and returns the last element of the list, identical to a stack POP operation.
How do you check if a Python list used as a stack is empty?
if stack == None:
if len(stack) == 0:
if stack.empty():
if stack.isEmpty():
You can check if a Python list is empty by verifying its length with len(stack) == 0.
Which variable is traditionally used to keep track of the index of the highest element in a stack?
TOP
HEAD
FRONT
TAIL
The 'TOP' variable (or pointer) is used to track the most recently added element in a stack.
If an initial stack st = [] undergoes st.append(10), st.append(20), and st.pop(), what is the final state of the stack?
[]
[20]
[10]
[10, 20]
10 is pushed, then 20 is pushed. The pop() operation removes the last element (20), leaving [10].
What is the primary application of a stack in modern text editors?
Spell Checking
Find and Replace
Undo / Redo Mechanism
Auto-Save
Stacks are heavily used for the Undo/Redo mechanism. The most recent action is popped first to undo it.
Which of the following expression formats places the operator AFTER its operands?
Infix
Prefix
Postfix
Outfix
Postfix expression (also known as Reverse Polish Notation) places the operator after its operands (e.g., AB+).
What is the Postfix equivalent of the Infix expression A + B?
+AB
A+B
AB+
B+A
In Postfix notation, the operands come first followed by the operator: AB+.
When converting an Infix expression to Postfix using a stack, what is primarily stored in the stack?
Operands (A, B, C)
Operators (+, -, *, /)
Both Operands and Operators
Final Result
During Infix to Postfix conversion, the stack is used to temporarily hold Operators based on their precedence.
In expression evaluation, what is the order of precedence from highest to lowest?
+, -, *, /, ()
(), ^, *, /, +, -
^, *, /, +, -, ()
*, /, +, -, ()
The order of precedence is Parentheses (), followed by Exponentiation (^ or **), Multiplication/Division (*, /), and finally Addition/Subtraction (+, -).
How can you view the TOP element of a stack st without removing it in Python?
st[top]
st.peek()
st[-1]
st[0]
In Python lists, st[-1] accesses the last element (the TOP of the stack) without removing it. This is commonly known as the PEEK operation.
Which of the following is NOT an application of a Stack?
Evaluating Postfix expressions
Checking balanced parentheses
Task scheduling (First Come First Serve)
Reversing a string
Task scheduling (First Come First Serve) uses a Queue (FIFO), not a Stack. Stacks are used for evaluating expressions, balancing parentheses, and reversing strings.
What happens if we execute stack.pop() on a Python list stack = []?
Returns None
Returns 0
Raises an IndexError
Raises an UnderflowError
Python lists raise an IndexError: pop from empty list when trying to pop an empty list. We usually catch this to print an 'Underflow' message.
What is the Prefix equivalent of the Infix expression (X + Y) * Z?
*+XYZ
XYZ+*
+*XYZ
Z*+XY
First, convert (X + Y) to +XY. Then multiply by Z: * goes to the front of the entire expression, resulting in *+XYZ.
A stack is implemented as a list s = [10, 20, 30]. What is the value of TOP if elements are added to the end of the list?
0
1
2
3
The elements are at indices 0, 1, and 2. The top element is 30, which is at index 2. Thus, TOP = 2.
What is the time complexity of pushing an element onto a stack implemented using a Python list (ignoring dynamic resizing)?
O(1)
O(N)
O(log N)
O(N^2)
The append() operation on a Python list generally takes O(1) constant time.
What is the time complexity of popping an element from the TOP of a stack implemented using a Python list?
O(1)
O(N)
O(log N)
O(N^2)
The pop() operation without arguments removes the last element of the list, which takes O(1) constant time.
When checking for balanced parentheses using a stack, what do we do when we encounter a closing bracket like '}'?
Push it to the stack
Ignore it
Pop an element from the stack and check if it's the matching opening bracket
Clear the entire stack
In a parenthesis matching algorithm, closing brackets trigger a POP operation. The popped bracket must match the opening type of the closing bracket.
Evaluate the Postfix expression: 4 2 + 5 *
30
14
22
11
First: 4 + 2 = 6. The expression becomes 6 5 *. Then: 6 * 5 = 30.
A web browser's 'Back' button is a classic example of which data structure?
Queue
Stack
Tree
Graph
The browser history operates on a Stack principle. When you visit a new page, it is PUSHED onto the history stack. Pressing 'Back' POPS the current page to reveal the previous one.