Flashcards
Tap a card to flip it
20 flashcards in this kit — the app reviews them with
spaced repetition so the right card returns on the right day.
Question
What is a stack?
tap to flip ↻
Answer
A linear data structure that follows the Last In, First Out (LIFO) principle.
Question
What does LIFO stand for?
tap to flip ↻
Answer
Last In, First Out
Question
What are the primary operations on a stack?
tap to flip ↻
Answer
**Push** (insert), **Pop** (remove), **Peek** (access top), and **isEmpty** (check if empty).
Question
What does the push operation do?
tap to flip ↻
Answer
Adds an element to the top of the stack.
Question
What does the pop operation do?
tap to flip ↻
Answer
Removes and returns the top element of the stack.
Question
What does the peek operation do?
tap to flip ↻
Answer
Returns the top element without removing it.
Question
What is the time complexity of push and pop operations on a stack?
tap to flip ↻
Answer
$O(1)$
Question
What is the space complexity of a stack?
tap to flip ↻
Answer
$O(n)$ where $n$ is the number of elements in the stack.
Question
What is a stack overflow?
tap to flip ↻
Answer
An error that occurs when trying to push an element onto a full stack.
Question
What is a stack underflow?
tap to flip ↻
Answer
An error that occurs when trying to pop or peek from an empty stack.
Question
How can a stack be implemented?
tap to flip ↻
Answer
Using an **array** or a **linked list**.
Question
What is the advantage of implementing a stack using a linked list?
tap to flip ↻
Answer
It can dynamically grow and shrink, avoiding fixed capacity limitations.
Question
What is the disadvantage of implementing a stack using an array?
tap to flip ↻
Answer
The stack has a fixed capacity and cannot grow beyond it.
Question
What is a real-world example of a stack?
tap to flip ↻
Answer
A stack of plates, where you add and remove plates from the top.
Question
What is the application of a stack in function calls?
tap to flip ↻
Answer
The call stack keeps track of function calls and local variables.
Question
How is a stack used in expression evaluation?
tap to flip ↻
Answer
Stacks are used to evaluate arithmetic expressions, such as converting infix to postfix and evaluating postfix expressions.
Question
What is the postfix expression for the infix expression $A + B$?
tap to flip ↻
Answer
$A B +$
Question
How does a stack help in checking balanced parentheses?
tap to flip ↻
Answer
Push opening parentheses onto the stack; for each closing parenthesis, pop and check if it matches the corresponding opening one.
Question
What is the top of a stack?
tap to flip ↻
Answer
The most recently added element that is accessible for pop or peek.
Question
What is the bottom of a stack?
tap to flip ↻
Answer
The first element that was pushed onto the stack.