Foundations-of-Computer-Science practice question 14 of 15

Which data structure follows the Last In, First Out (LIFO) principle?

Full set: 71 questions
Answer options
A:

A. Queue

B:

B. Stack

Correct answer
C:

C. Array

D:

D. Graph

Correct Answer:
B. B. Stack
Explanation

A stack is an abstract data type that operates on the Last-In, First-Out (LIFO) principle. In a stack, elements are added (pushed) and removed (popped) from the same end, referred to as the "top." Consequently, the last element to be added to the stack is always the first one to be removed. This behavior is analogous to a stack of physical objects, like plates, where you add and remove from the top.

Why Incorrect

A. A queue follows the First-In, First-Out (FIFO) principle, where the first element added is the first one removed.
C. An array is an indexed data structure that allows direct access to elements by their position, not inherently LIFO.
D. A graph is a non-linear data structure representing relationships between nodes and is not based on a LIFO access pattern.

References

1. Cormen, T. H., Leiserson, C. E., Rivest, R. L., & Stein, C. (2009). Introduction to Algorithms (3rd ed.). MIT Press. Chapter 10, "Elementary Data Structures," Section 10.1 Stacks and queues, p. 232.

2. Sedgewick, R., & Wayne, K. (2011). Algorithms (4th ed.). Addison-Wesley Professional. Chapter 1, "Fundamentals," Section 1.3 Bags, Queues, and Stacks.

3. University of California, Berkeley. CS 61B: Data Structures, Spring 2019. Lecture 7: Stacks, Queues, and Deques.

Scroll to Top