Stack Basics: 18 flashcards
All 18 flashcards from this kit, free and with no sign-up.
1. What is the fundamental principle of a stack?
Show the answer
Last In, First Out (LIFO) — the last element added is the first to be removed.
2. Name the two primary operations of a stack and their time complexities (array implementation).
Show the answer
Push (add to top) and Pop (remove from top). Both are O(1) in array implementation.
3. In an array-based stack, what does the 'top' index represent?
Show the answer
The index of the last element pushed onto the stack (or -1 if empty).
4. What is the condition for a stack overflow in an array implementation?
Show the answer
When top == capacity - 1 (i.e., the array is full) and a push is attempted.
5. What is the condition for a stack underflow in an array implementation?
Show the answer
When top == -1 (i.e., the stack is empty) and a pop or peek is attempted.
6. Given an array-based stack with capacity 5, initially empty. Push 10, 20, 30. What is the value of 'top'?
Show the answer
top = 2 (0-based index).
7. After pushing 10, 20, 30 onto a stack, what does pop() return?
Show the answer
30 (the last pushed element).
8. What does the peek() operation do?
Show the answer
Returns the top element without removing it. Time complexity O(1).
9. In an array-based stack, what is the time complexity of the isEmpty() operation?
Show the answer
O(1) — it checks if top == -1.
10. Write the pseudocode for the push operation in an array-based stack.
Show the answer
if top == capacity-1: overflow else: top = top + 1; arr[top] = value
11. Write the pseudocode for the pop operation in an array-based stack.
Show the answer
if top == -1: underflow else: value = arr[top]; top = top - 1; return value
12. What is a common real-world application of a stack?
Show the answer
Function call stack (recursion), expression evaluation, undo/redo in editors, backtracking algorithms.
13. Given an array-based stack with capacity 4, initially empty. Perform: push(5), push(9), pop(), push(2), pop(), pop(). What is the final state?
Show the answer
Stack is empty (top = -1).
14. What is the main disadvantage of a fixed-size array implementation of a stack?
Show the answer
It has a fixed capacity, which can lead to overflow if the maximum size is unknown or underestimated.
15. How can you implement a stack to avoid the fixed-size limitation?
Show the answer
Use a dynamic array (resizing) or a linked list.
16. In an array-based stack, what is the time complexity of the push operation when the array is not full?
Show the answer
O(1) — it simply assigns a value and increments top.
17. What is the value of 'top' after a single push operation on an empty stack?
Show the answer
0 (it becomes the index of the first element).
18. What is the space complexity of an array-based stack with capacity n?
Show the answer
O(n) — it uses an array of size n to store elements.
Your notes can be a kit like these
Every kit here was made from real study material. Point Veda at a chapter, a PDF, a photo or a link and get notes, flashcards, practice MCQs, games and a scored test — free, in 42 languages.
- Chapter notes
- Flashcards
- Practice MCQs
- Scored tests
- Exam prep
Get Veda free See what students get
Free to start · No ads · Works in 42 languages