Lesson 4.2.3.1

4.2.3.1 Stack operations Quiz: AQA Computer Science, Unit 2

20 questions

In partnership with Revision Ninja

Lesson 4.2.3.1, Stack operations: 20 multiple choice questions for the AQA Computer Science (7517), Unit 2: Fundamentals of data structures, written with Revision Ninja.

Host it live on the board and students join with a game code on their own devices, or revise alone with Free Play. The answers are revealed in the game.

Host this setFree Play

The 20 questions

  1. What is a stack?

    • An ADT in which the first item added is the first item removed
    • A tree with several roots
    • An ADT in which the last item added is the first item removed
    • A set of unordered key-value pairs
  2. Which operation adds an item to the top of a stack?

    • Peek
    • Push
    • Pop
    • Enqueue
  3. Which operation removes the top item of a stack?

    • Dequeue
    • Push
    • Pop
    • Peek
  4. What does peek (or top) do on a stack?

    • Adds an item to the bottom of the stack, so the next pop removes the newly added item
    • Empties the whole stack, removing every item and leaving the stack ready for new values
    • Returns the value of the top item without removing it
    • Removes the top item and returns it, so the stack is one item smaller after the operation
  5. Which test is needed before a pop on a stack?

    • Test for a palindrome
    • Test for a graph cycle
    • Test for a hash collision
    • Test for an empty stack
  6. What is the purpose of testing for a stack being full?

    • To convert the stack to a queue, so the items can be removed in first-in, first-out order
    • To prevent a push when no space is left in the fixed-size structure
    • To make the stack return values faster, since a full stack is searched more efficiently
    • To remove the item at the bottom, so that space is freed for the next value to be pushed
  7. A stack is implemented in an array. What does the stack pointer usually track?

    • The number of links in a tree
    • The number of frames in memory
    • The position of the top item
    • The colour of the first item
  8. Values 4, 7 and 9 are pushed onto an empty stack in that order. What value is popped first?

    • 4
    • 16
    • 7
    • 9
  9. A stack has 2 items. Which sequence leaves the stack with 1 item?

    • Pop twice
    • Peek twice
    • Push twice
    • Pop once
  10. Given the operations push(3), push(5), pop(), push(8), pop(), pop(), what is left on the stack?

    • Empty
    • 3
    • 5
    • 8
  11. A stack of capacity 3 has 3 items. What happens if another push is attempted?

    • The stack is cleared automatically
    • An overflow error, because the stack is full
    • The bottom item is removed silently
    • The item is added and the stack holds 4 items
  12. Which of these is a common use of a stack in programming?

    • Tracking subroutine calls and return addresses
    • Finding the shortest path in a road network
    • Storing the order of arrival of print jobs
    • Looking up a value by its key in a phone book
  13. Why is a stack suitable for checking whether brackets are balanced in an expression?

    • Brackets must be stored in alphabetical order, so that each pair can be matched by its letter
    • The stack stores only numbers, so each bracket is converted to a number before it is checked
    • Each closing bracket must match the most recent unmatched opening bracket
    • Brackets are always removed from the front, so the first bracket read is the first to close
  14. A stack is used to reverse the characters of the string ABC. Pushing A, B, C then popping all of them gives which output?

    • ACB
    • CBA
    • BCA
    • ABC
  15. An array-based stack has a top index of -1 when empty. What does pushing change the top index to?

    • -1 for the first item
    • The top index is not used
    • 1 for the first item
    • 0 for the first item
  16. A program needs to undo the most recent action in an editor. Which ADT is most appropriate?

    • Graph
    • Hash table
    • Queue
    • Stack
  17. What is the result of pushing 1, 2, 3, then popping twice and peeking?

    • Empty
    • 1
    • 3
    • 2
  18. Which is a disadvantage of a fixed-size array implementation of a stack?

    • It removes the item at the bottom on every push, so older values are lost as new ones arrive
    • It cannot hold any items at all, because an array can only store values of a single type
    • It can overflow if more items are pushed than the array can hold
    • It makes peek impossible, since the array has no position that can be read without popping
  19. A stack is implemented with a linked list instead of an array. Which benefit does this give?

    • The stack can grow as needed without a fixed capacity
    • The stack can only hold numbers, which keeps every node the same size in the linked list
    • The stack no longer needs a top pointer, because each item finds the next one by its index
    • The stack always has exactly 10 places, which makes it the same size whatever is pushed on it
  20. Which statement best compares the stack and the queue?

    • A stack preserves arrival order, while a queue reverses it, so the oldest item leaves first in a stack
    • Both remove the most recently added item, so the two structures behave the same way in use
    • Neither can be implemented with an array, so both must be built using a linked list of nodes
    • A stack reverses the order of the items, while a queue preserves their arrival order

All AQA Computer Science quizzes