Foundations-of-Computer-Science practice question 14 of 15
Which data structure follows the Last In, First Out (LIFO) principle?
Full set: 71 questionsA 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.
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.
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.
Keep practicing
Take the free Foundations-of-Computer-Science practice test
Ten exam-style questions with answers and explanations, plus the exam facts and study guides.
More questions
Other Foundations-of-Computer-Science practice questions
- Question 1What is the purpose of a parameter in a function definition?
- Question 2What is the primary purpose of an operating system?
- Question 3Which action is taken if the first number is the lowest value in a selection sort?
- Question 4What will the expression fam[3:6] return?
- Question 5What will the output be of this line?
- Question 6Which aspect is excluded from a NumPy array’s structure?
