Define stack in data structures.
A linear data structure that follows the Last In First Out (LIFO) principle.
What is the top of a stack?
The most recently added element in the stack.
True or false: A stack allows insertion and deletion at both ends.
FALSE
A stack only allows operations at one end.
Fill in the blank: The push operation adds an item to the ______.
top of the stack.
What does the pop operation do?
Removes the top element from the stack.
Define peek in the context of stacks.
Retrieves the top element without removing it.
What is a stack overflow?
An error that occurs when too many elements are added to a stack.
True or false: Stacks can be implemented using arrays or linked lists.
TRUE
What is the size of a stack?
The number of elements currently stored in the stack.
Fill in the blank: The empty operation checks if the stack is ______.
empty.
What is the time complexity of push and pop operations?
Both operations have a time complexity of O(1).
Define stack underflow.
An error that occurs when trying to pop from an empty stack.
What is the main use of stacks?
To manage function calls and maintain execution order.
True or false: Stacks are used in depth-first search algorithms.
TRUE
Fill in the blank: In a stack, the last element added is the first to be ______.
removed.
What is a stack frame?
A section of the stack that contains function call information.
Define dynamic stack.
A stack that can grow and shrink in size during runtime.
What is the main difference between a stack and a queue?
A stack uses LIFO while a queue uses FIFO.
True or false: Stacks can be used to reverse strings.
TRUE
Fill in the blank: The base of a stack is where ______.
the first element is added.
What is a bounded stack?
A stack with a fixed maximum size.
Define stack data structure in one sentence.
A collection of elements with restricted access to the last added item.
What is the push operation’s time complexity?
O(1), as it adds an element directly to the top.