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.
The 20 questions
-
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
-
Which operation adds an item to the top of a stack?
- Peek
- Push
- Pop
- Enqueue
-
Which operation removes the top item of a stack?
- Dequeue
- Push
- Pop
- Peek
-
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
-
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
-
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
-
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
-
Values 4, 7 and 9 are pushed onto an empty stack in that order. What value is popped first?
- 4
- 16
- 7
- 9
-
A stack has 2 items. Which sequence leaves the stack with 1 item?
- Pop twice
- Peek twice
- Push twice
- Pop once
-
Given the operations push(3), push(5), pop(), push(8), pop(), pop(), what is left on the stack?
- Empty
- 3
- 5
- 8
-
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
-
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
-
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
-
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
-
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
-
A program needs to undo the most recent action in an editor. Which ADT is most appropriate?
- Graph
- Hash table
- Queue
- Stack
-
What is the result of pushing 1, 2, 3, then popping twice and peeking?
- Empty
- 1
- 3
- 2
-
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
-
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
-
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
Related quizzes
- Data structures and abstract data types Quiz · 4.2.1.1 · 20 questions
- Single- and multi-dimensional arrays Quiz · 4.2.1.2 · 20 questions
- Reading and writing text and binary files Quiz · 4.2.1.3 · 20 questions
- Linear, circular and priority queues Quiz · 4.2.2.1 · 20 questions
- Graphs: weighted, directed and adjacency representations Quiz · 4.2.4.1 · 20 questions
- Trees and binary trees Quiz · 4.2.5.1 · 20 questions
- Hash tables, hashing and collisions Quiz · 4.2.6.1 · 20 questions
- Dictionaries and key-value pairs Quiz · 4.2.7.1 · 20 questions
- Vectors and vector operations Quiz · 4.2.8.1 · 20 questions
- Data types Quiz · 4.1.1.1 · 20 questions