What is a key advantage of using a linked list to implement a stack?
A linked list stack can grow and shrink dynamically without a fixed size limit, so it uses memory efficiently for varying stack sizes.
Click to reveal answer
beginner
What is a main disadvantage of using an array to implement a stack?
An array stack has a fixed size, so it can run out of space if the stack grows beyond the array capacity, requiring resizing or causing overflow.
Click to reveal answer
intermediate
How does the time complexity of push and pop operations compare between linked list and array stacks?
Both linked list and array stacks have O(1) time complexity for push and pop operations in the average case.
Click to reveal answer
intermediate
Why might an array stack be faster in practice than a linked list stack?
Array stacks have better cache locality because elements are stored contiguously in memory, making access faster than linked list nodes scattered in memory.
Click to reveal answer
intermediate
What is a memory overhead disadvantage of linked list stacks compared to array stacks?
Each node in a linked list stack stores extra memory for a pointer to the next node, increasing memory usage compared to arrays which store only the data.
Click to reveal answer
Which stack implementation can dynamically grow without a fixed size limit?
ABoth linked list and array stacks
BArray stack
CLinked list stack
DNeither linked list nor array stacks
✗ Incorrect
Linked list stacks grow dynamically by adding nodes, while array stacks have a fixed size unless resized.
What is a common problem when using an array stack with a fixed size?
AStack overflow when full
BSlower push operation
CExtra memory per element
DCannot pop elements
✗ Incorrect
Array stacks can overflow if the fixed size is exceeded.
Which stack implementation typically has better cache performance?
ALinked list stack
BArray stack
CBoth equal
DDepends on data type
✗ Incorrect
Array stacks store elements contiguously, improving cache locality and speed.
What extra memory cost does a linked list stack have per element?
ANo extra cost
BExtra data copy
CArray resizing buffer
DPointer to next node
✗ Incorrect
Each linked list node stores a pointer to the next node, increasing memory usage.
What is the time complexity of push operation in both linked list and array stacks?
AO(1)
BO(n)
CO(log n)
DO(n^2)
✗ Incorrect
Push operation is constant time O(1) in both implementations.
Explain the main trade-offs between using a linked list stack and an array stack.
Think about memory use, speed, and size flexibility.
You got /5 concepts.
Describe scenarios where you would prefer a linked list stack over an array stack and vice versa.
Consider size flexibility and performance needs.
You got /4 concepts.
Practice
(1/5)
1. Which of the following is a key advantage of using a linked list to implement a stack compared to using an array?
easy
A. Accessing elements by index is faster.
B. The stack size can grow dynamically without a fixed limit.
C. Memory usage is always less than an array.
D. It uses less pointer memory.
Solution
Step 1: Understand stack size behavior in linked list
A linked list stack can grow dynamically because nodes are created as needed without a fixed size.
Step 2: Compare with array stack size limits
An array stack has a fixed size or requires resizing, which is costly. Linked list avoids this limitation.
Final Answer:
The stack size can grow dynamically without a fixed limit. -> Option B
Quick Check:
Dynamic size = Linked list advantage [OK]
Hint: Linked list stacks grow dynamically; arrays have fixed size [OK]
Common Mistakes:
Thinking arrays always use less memory
Confusing access speed advantages
Assuming linked lists use less pointer memory
2. Which of the following is the correct way to declare a stack using an array in C++?
easy
A. int stack[10]; int top = -1;
B. int stack; int top = 0;
C. int stack[]; int top = -1;
D. int stack(10); int top = -1;
Solution
Step 1: Check array declaration syntax
In C++, arrays are declared with size inside square brackets, e.g., int stack[10];
Step 2: Check top initialization
Top is initialized to -1 to indicate empty stack.
Final Answer:
int stack[10]; int top = -1; -> Option A
Quick Check:
Correct array syntax and top init = C [OK]
Hint: Array size in [] brackets; top starts at -1 [OK]
Common Mistakes:
Using parentheses instead of brackets for array
Not initializing top correctly
Declaring array without size
3. Consider the following code snippet implementing a stack push operation using a linked list:
struct Node {
int data;
Node* next;
};
Node* top = nullptr;
void push(int x) {
Node* newNode = new Node();
newNode->data = x;
newNode->next = top;
top = newNode;
}
push(10);
push(20);
push(30);
What will be the order of elements from top to bottom after these pushes?
medium
A. 10 -> 20 -> 30 -> null
B. 20 -> 30 -> 10 -> null
C. 30 -> 20 -> 10 -> null
D. 30 -> 10 -> 20 -> null
Solution
Step 1: Trace push operations on linked list stack
Each push adds new node at the top, so last pushed is on top.
Hint: Last pushed is always on top in linked list stack [OK]
Common Mistakes:
Assuming order is 10->20->30
Confusing push with append at end
Ignoring pointer update order
4. The following code attempts to pop an element from an array-based stack but has a bug:
int stack[5];
int top = -1;
void pop() {
if (top == 0) {
cout << "Stack Underflow" << endl;
return;
}
top--;
}
What is the bug in this pop function?
medium
A. It should print "Stack Overflow" instead of "Stack Underflow".
B. It should increment top instead of decrementing.
C. The stack array size is too small.
D. It should check if top == -1 for underflow, not top == 0.
Solution
Step 1: Understand stack underflow condition
Underflow occurs when stack is empty, which is when top == -1.
Step 2: Check condition in code
Code checks top == 0, which is wrong; top == 0 means one element is present.
Final Answer:
It should check if top == -1 for underflow, not top == 0. -> Option D
Quick Check:
Empty stack top = -1, check must match [OK]
Hint: Empty stack top is -1, check underflow with top == -1 [OK]
Common Mistakes:
Checking top == 0 instead of -1
Confusing overflow and underflow messages
Incorrectly incrementing top on pop
5. You want to implement a stack that can handle millions of push and pop operations without worrying about maximum size. Which implementation is better and why?
Array-based stack with dynamic resizing
Linked list-based stack
hard
A. Linked list stack is better because it grows dynamically without resizing overhead.
B. Array stack is better because it uses less memory per element.
C. Array stack is better because dynamic resizing is always faster than linked list allocation.
D. Linked list stack is worse because it cannot grow beyond initial size.
Solution
Step 1: Consider dynamic resizing cost in array stack
Array stack needs to resize and copy elements when full, which is costly for millions of operations.
Step 2: Consider linked list stack growth
Linked list stack allocates nodes on demand, no resizing needed, so it handles large operations smoothly.
Final Answer:
Linked list stack is better because it grows dynamically without resizing overhead. -> Option A
Quick Check:
Dynamic growth without resizing = Linked list advantage [OK]
Hint: Linked list avoids resizing overhead for large stacks [OK]
Common Mistakes:
Assuming array resizing is always faster
Ignoring memory overhead of pointers
Thinking linked list has fixed size
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.