Which data structure is used to implement a LIFO (Last In, First Out) buffer?
a) Stack
b) Queue
c) Priority Queue
d) Deque
Answer:
a) Stack
Explanation:
A stack is used to implement a LIFO (Last In, First Out) buffer, meaning the last element added to the stack is the first to be removed. This structure is used in various algorithms where backtracking is needed, such as in recursion and depth-first search (DFS).
The two main operations of a stack are push() (to add an element) and pop() (to remove the most recently added element). These operations have constant time complexity O(1).
Stacks are commonly used in applications such as expression evaluation, function call management (system call stack), and reversing sequences.
Reference:
DSA (Data Structures and Algorithms) MCQ Questions and Answers