Prepare for the A Level Computer Science OCR Exam with engaging quizzes, detailed explanations, and effective study tips. Maximize your readiness and boost your confidence for exam day!

Practice this question and more.


In what structure are elements accessed in last-in first-out (LIFO) order?

  1. Array

  2. Queue

  3. Stack

  4. List

The correct answer is: Stack

Elements are accessed in last-in first-out (LIFO) order in a stack. This data structure allows for the most recently added element to be the first one to be removed. Stacks operate on the principle that the last element added to the collection is the first one to be removed, which is akin to a stack of plates where you can only take the top plate off. In practical terms, when using a stack, operations such as push (to add an element) and pop (to remove the element) are performed at the top of the stack. This behavior is very useful in scenarios such as function call management in programming, where the last function called must finish its execution before the previous function can continue. The other structures mentioned do not operate on LIFO principles. Arrays allow for random access based on their index, queues operate in a first-in first-out (FIFO) manner, and lists may have various access patterns but typically do not adhere to LIFO without being explicitly defined as a stack. Thus, the stack uniquely fits the definition of accessing elements in LIFO order.