Hint: Use 'struct Node* next;' for linked list pointers in C [OK]
Common Mistakes:
Using 'Node* next;' without 'struct' in C
Declaring next as int instead of pointer
Missing typedef or incorrect struct syntax
3. What will be the output after pushing 10, 20, then 30 onto an empty linked list stack and then popping once?
medium
A. 20 -> 10 -> null
B. 30 -> 20 -> 10 -> null
C. 10 -> null
D. 20 -> null
Solution
Step 1: Push 10, 20, 30 onto stack
Stack after pushes: top = 30, then 20, then 10 at bottom.
Step 2: Pop once removes top (30)
After pop, top is 20, next is 10, then null.
Final Answer:
20 -> 10 -> null -> Option A
Quick Check:
Pop removes top = 20 -> 10 [OK]
Hint: Pop removes last pushed item; list shows remaining stack [OK]
Common Mistakes:
Confusing push order with pop order
Listing stack bottom first
Forgetting pop removes top element
4. Given this array stack code snippet, what is the error?
int stack[3];
int top = -1;
void push(int x) {
if(top == 3) {
printf("Stack Overflow\n");
return;
}
stack[++top] = x;
}
medium
A. The push function does not increment top
B. The stack array size is too large
C. The overflow condition should be 'top == 2' instead of 'top == 3'
D. The stack should be declared as a pointer
Solution
Step 1: Check array size and top index limits
Array size is 3, so valid indices are 0,1,2; top max should be 2.
Step 2: Analyze overflow condition
Condition 'top == 3' allows top to go out of bounds; should be 'top == 2'.
Final Answer:
The overflow condition should be 'top == 2' instead of 'top == 3' -> Option C
Quick Check:
Array max index = 2, overflow check must match [OK]
Hint: Array index max = size-1; check overflow accordingly [OK]
Common Mistakes:
Checking overflow with wrong index
Assuming top starts at 0
Confusing array size with max index
5. Which of the following is a disadvantage of using an array-based stack compared to a linked list stack in a system with limited memory fragmentation?
hard
A. Linked list stack has slower push and pop operations
B. Array stack requires contiguous memory, which may be unavailable
C. Array stack uses more memory per element due to pointers
D. Linked list stack cannot be resized dynamically
Solution
Step 1: Understand memory allocation for array stacks
Array stacks need a continuous block of memory, which can be hard to find if memory is fragmented.
Step 2: Compare with linked list memory allocation
Linked lists allocate nodes separately, so they handle fragmentation better.
Final Answer:
Array stack requires contiguous memory, which may be unavailable -> Option B
Quick Check:
Contiguous memory need = array stack disadvantage [OK]
Hint: Arrays need continuous memory; linked lists do not [OK]
Common Mistakes:
Thinking linked lists are slower always
Assuming arrays use more memory per element
Believing linked lists cannot resize dynamically
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.