STACK Flashcards
What is a stack?
A stack is a data structure that follows the Last In, First Out (LIFO) principle.
Which operations are primarily associated with stacks?
Push, pop, and peek.
True or False: In a stack, the last element added is the first one to be removed.
True.
What is the time complexity of push and pop operations in a stack?
O(1).
Fill in the blank: A stack is often used to implement _____.
function calls.
What is the main use of a stack in programming?
To keep track of function calls and local variables.
Which of the following is a common application of stacks?
Undo mechanisms in software.
What does the ‘peek’ operation do in a stack?
It retrieves the top element without removing it.
True or False: A stack can be implemented using arrays or linked lists.
True.
What happens when you try to pop an element from an empty stack?
It results in an underflow error.
What is the maximum size of a stack implemented with a fixed-size array?
It is limited by the size of the array.
Which data structure is used to reverse a string?
A stack.
What is the stack pointer?
A pointer that indicates the top of the stack.
Fill in the blank: The stack follows the _____ principle.
Last In, First Out (LIFO).
What is a stack overflow?
It occurs when there is no more space in the stack to add new elements.
Multiple Choice: Which one of the following is NOT a valid stack operation?
Insert at a specific position.
True or False: The stack data structure can be used for depth-first search in graphs.
True.
What does it mean to ‘push’ an element onto a stack?
To add an element to the top of the stack.
What is the result of popping an element from a stack with one element?
The stack becomes empty.
Which of the following is a characteristic of a stack?
Elements are added and removed from the same end.
What is the primary difference between a stack and a queue?
A stack is LIFO, while a queue is FIFO (First In, First Out).
Fill in the blank: In recursive function calls, each call is stored in a _____.
stack frame.
What is a stack frame?
A structure that contains information about a function call, including local variables and return address.
Multiple Choice: Which application uses stacks?
Backtracking algorithms.
What is the stack data structure commonly used for in compilers?
To manage function calls and local variables.
True or False: A stack can dynamically grow in size.
True, if implemented using a linked list.
What is the key advantage of using a stack?
It allows for efficient management of data in LIFO order.
What is the purpose of the ‘isEmpty’ function in a stack implementation?
To check if the stack has no elements.
Which operation would you use to access the top element of a stack without removing it?
Peek.
What is a common problem that can occur with stack-based algorithms?
Stack overflow.
True or False: Stacks can be implemented using circular linked lists.
True.
What type of problems can be solved using stacks?
Problems that require backtracking, such as maze solving.
Fill in the blank: The _____ data structure is used to reverse the order of elements.
stack.
What does it mean to ‘pop’ an element from a stack?
To remove the element from the top of the stack.
Multiple Choice: Which of the following best describes a stack?
A collection of elements with a specific order of access.
What is the stack’s behavior during recursion?
Each recursive call adds a new stack frame.
True or False: You can access elements in a stack randomly.
False.
What happens to the stack when a function call is completed?
The stack frame for that function is removed.
What is a common use of stacks in web browsers?
To manage the history of visited pages.
Fill in the blank: In a stack, the _____ operation adds an element.
push.
What is the typical implementation of a stack in programming languages?
Using an array or a linked list.
Multiple Choice: Which of the following is a real-world analogy for a stack?
A stack of plates.
True or False: A stack can be used to evaluate expressions in postfix notation.
True.
What is the primary data structure used to implement undo functionality in applications?
Stack.
What are the two main types of stacks?
Static stack and dynamic stack.
Fill in the blank: A stack is often referred to as a _____ structure.
linear.
What is the effect of pushing elements onto a stack until it is full?
It causes a stack overflow error.
What is the role of a stack in function calls?
To store return addresses and local variables.
True or False: You can push and pop elements in any order in a stack.
False.
What is the main disadvantage of using a fixed-size stack?
It can lead to stack overflow if the size limit is exceeded.
Multiple Choice: Which of the following operations is not typically associated with stacks?
Searching for an element.
What happens during a stack underflow?
An attempt is made to pop an element from an empty stack.
Fill in the blank: Stacks are often used in algorithms that require _____.
backtracking.
What does a stack’s ‘top’ refer to?
The most recently added element that is available for removal.