WorksheetsQuiz in Stack
Total questions: 40
Worksheet time: 50mins
A programmer uses a stack in a text editor to manage the Undo function. What principle makes this possible?
The most recent change is removed first.
The earliest change is restored first.
All changes are restored simultaneously.
The least frequent change is restored last.
When a new element is pushed into a stack, what happens to the “Top” pointer?
It moves to the first element of the stack.
It shifts one position upward to point to the new element.
It resets to the base address of the stack.
It skips to the last memory address.
A student compares a stack to a pile of books on a table. Which concept is being illustrated?
Each book can be removed from any position.
The last book placed can be removed first.
All books are removed in the order they were stacked.
The smallest book always stays at the bottom.
Why is stack called a restricted data structure?
It only allows one type of data.
It allows operations only at one end of the list.
It requires a linked list representation.
It cannot perform deletion.
What happens when an element is popped from an empty stack?
The stack resets itself.
A stack underflow condition occurs.
The system automatically inserts a null value.
A new memory block is created.
If a stack follows the LIFO principle, which operation sequence will remove elements in reverse order of insertion?
push(10), push(20), pop()
push(10), pop(), push(20), pop()
push(10), push(20), push(30), pop()
pop(), push(10), push(20), pop()
A developer chooses an array-based stack instead of a linked list implementation. What could be the reason?
It uses dynamic memory allocation.
It provides faster access when size is fixed.
It automatically resizes based on input.
It allows deletion from both ends.
When does a stack overflow occur in an array-based stack?
When the top pointer becomes -1.
When the top pointer reaches the maximum index.
When the array size is doubled.
When the stack has only one element.
A linked list-based stack rarely faces overflow errors. Why?
It has a fixed number of nodes.
It expands dynamically as memory allows.
It limits insertion operations.
It requires pre-declared capacity.
Before executing a pop operation, what must be verified?
If the stack is initialized properly.
If the stack is empty to avoid underflow.
If the top value is greater than zero.
If the stack contains identical elements.
A stack’s “Top” pointer is currently at index 3 in an array of size 5. After a push operation, what will its new index be?
2
3
4
5
Which of the following best differentiates stack overflow from stack underflow?
Overflow occurs on insertion into a full stack; underflow occurs on deletion from an empty stack.
Overflow happens when removing too many elements; underflow happens when inserting too many.
Overflow is caused by recursion; underflow by iteration.
Overflow and underflow are identical conditions in opposite order.
Which operation places a new element at the top of the stack?
Peek
Push
Pop
Display
What will the peek() function return after executing the sequence below? Push(8), Push(12), Pop(), Push(15)
8
12
15
Null
What should happen when the stack is full and push() is called again?
The operation should overwrite the top element.
The system should trigger a stack overflow error.
The new data replaces the bottom element.
The stack expands automatically.
Which situation best illustrates the concept of pop() operation in real life?
Placing a new book on top of a stack.
Taking off the top bangle from a pile.
Adding a car to a single-lane garage.
Counting plates in a stack.
If Push(5), Push(10), Push(15), Pop() are performed, what remains on the stack (from bottom to top)?
15, 10, 5
5, 10
10, 15
5, 10, 15
Why must programmers check isEmpty() before calling pop()?
To avoid retrieving the wrong element.
To prevent an underflow condition.
To ensure data order remains unchanged.
To identify duplicate values.
In an infix expression, operators are placed:
Before their operands.
Between their operands.
After their operands.
Independently of their operands.
What is the postfix equivalent of (A + B) * C?
A B + C *
A + B * C
C A B + *
A B C * +
Which of the following is the prefix form of A * (B + C)?
A B C + *
* + A B C
+ * A B C
* A + B C
Why is stack preferred for expression evaluation?
It stores operands and manages operator precedence effectively.
It allows random access to operands.
It stores operators in sorted order.
It simplifies syntax checking by ignoring parentheses.
What happens when two operators of equal precedence appear consecutively during conversion?
The one on the left is processed first.
The one on the right is processed first.
Both are skipped.
Evaluation stops temporarily.
If the expression A + B * C - D is converted to postfix, what is the correct result?
A B C * + D -
A B C + D * -
A B * C + D -
A + B C D * -
Which namespace allows access to the built-in Stack class in C#?
System.Data
System.Collections
System.IO
System.Stack
What does the following C# code display?
X
Y
Z
Null
What will be the final output?
A B D
D B A
A C D
C B A
What are the two numbers printed?
20 and 10
10 and 20
20 and 20
10 and 10
What is displayed on the screen?
Z Y X
W Y
W X
X W
What is the final stack content?
15 10 5
20 10 5
20 15 10
10 5 20
What is the output?
A B C
C B
Stack Underflow occurs
B A
Assume a custom stack class with maximum size = 3. What is the output?
False, True
True, True
True, False
False, False
What are the boolean values printed?
True, False
False, True
False, False
True, True
What is the final output?
300 200
300 100
100 300
200 100
What will be printed?
M
N
O
Error
What is the output?
Green
Blue
Yellow
Red
Evaluate the postfix expression: 2 3 4 * + 5 - What is the final result?
9
15
11
7
Convert the infix expression A * (B + C) to postfix.
A B C + *
A + B C *
A + B + C
A B * C +
Evaluate the postfix expression: 6 2 / 3 * 4 + 5 - What is the final result?
8
9
11
10
What is printed on the screen?
15
10
20
5
