Stacks Flashcards
What is an abstract data type (ADT)?
An abstract data type (ADT) is a model for a certain class of data structures that have similar behavior.
What is a stack?
A stack is an abstract data type that follows the Last In, First Out (LIFO) principle.
True or False: In a stack, the first element added is the first to be removed.
False
What are the primary operations of a stack?
The primary operations of a stack are push, pop, and peek (or top).
Fill in the blank: The operation that adds an element to the top of the stack is called ____.
push
Fill in the blank: The operation that removes the top element from the stack is called ____.
pop
What does the ‘peek’ operation do?
The ‘peek’ operation retrieves the top element of the stack without removing it.
True or False: A stack can be implemented using arrays or linked lists.
True
What is a common use case for stacks?
Common use cases for stacks include expression evaluation and backtracking algorithms.
True or False: A stack can grow indefinitely without a limit.
False
What is stack overflow?
Stack overflow occurs when a stack exceeds its maximum capacity.
What is stack underflow?
Stack underflow occurs when a pop operation is attempted on an empty stack.
Multiple choice: Which of the following operations is not a standard stack operation? A) push B) pop C) enqueue D) peek
C) enqueue
How does a stack differ from a queue?
A stack is LIFO while a queue is FIFO (First In, First Out).
Fill in the blank: The maximum number of elements a stack can hold is known as its ____.
capacity
What is a real-world analogy for a stack?
A stack can be compared to a stack of plates where the last plate placed on top is the first one to be taken off.
True or False: In a stack, elements can be accessed in any order.
False
What data structure can be used to implement a stack?
A stack can be implemented using either an array or a linked list.
What is the purpose of the ‘isEmpty’ function in a stack?
The ‘isEmpty’ function checks if the stack contains any elements.
Multiple choice: Which of the following best describes a stack? A) A linear data structure B) A non-linear data structure C) A tree structure D) A graph structure
A) A linear data structure
What is the main advantage of using a stack?
The main advantage of using a stack is its simplicity and efficiency in managing data in a LIFO manner.
Fill in the blank: In a stack, the topmost element is the one that is ____ first.
removed
True or False: Stacks are commonly used in function call management in programming languages.
True
What is a stack frame?
A stack frame is a section of the stack that contains information about a function call, including local variables and return addresses.