OCR H446 A Level Computer Science · 1.4 Data Types, Data Structures and Boolean Algebra
Stretch tasks Data Structures
Quiz Challenge
A quiz game against four computer players, then short and long written answers.
- Quiz Blitz12 questions against the clock
- Quick Fire4 short answers
- Big Think2 long answers
About 20 minutes
This or That
Pixel the cat asks 8 questions. Each has two answers: pick the right one.
- Two answers to every question
- A fish treat for every right answer
- Streaks win Pixel shades, then a party hat
About 4 minutes
Memory Match
Flip the cards two at a time to match each term card to its meaning card.
- 12 cards: each term has a meaning
- One peek at every card
- Combo points for pairs found in a row
6 pairs, about 4 minutes
Sort It
Sort each statement into the right box, like the tick box tables in the exam.
- 12 cards to sort into 4 boxes
- Drag a card, tap a box or press its number
- Combo points for cards sorted in a row
12 cards, about 4 minutes
Code Word
Guess the lesson's secret words. Every guess shows which letters are right.
- A clue for every word
- Tiles turn green, amber or grey after each guess
- Fewer guesses win more points
3 words, about 4 minutes
Link Up
12 tiles hide 3 groups of 4. Work out what links them.
- Pick four tiles that belong together
- Four slips and the round is over
- Fewer slips win more points
3 groups, about 3 minutes
Bug Hunt
Two statements are true and one has a bug. Catch the bug before it gets away.
- Three statements in every round
- Tap the one with the mistake
- Streaks win bonus points
5 rounds, about 4 minutes
Brain games
Train your brain on this lesson
Logic, memory and speed, built from this lesson's own key ideas. Win up to three diamonds in each game.
Odd One Out
Four tiles: three share a link and one does not. Spot the odd one out, then see what links the rest.
- Three belong together, one does not
- A hint shows the link, for fewer points
- Quick answers and streaks win more
8 rounds, about 3 minutes
Memory Flash
Study the term cards, then they flip over. Find the card that goes with each clue, from memory.
- Three levels: 3, 4 and 6 cards
- Two tries to find each card
- Streaks win bonus points
3 levels, about 4 minutes
Fact or Fib
Statements fly in one at a time. Is each one a fact or a fib? Decide fast.
- Swipe, tap or use the arrow keys
- Every fib comes with its fix
- Streaks multiply your points
12 statements, about 3 minutes
The final challenge
City Run
Race a robot cat on inline skates through a neon cyber city, from Neon Station to the Hyper Tunnel. Every question is a row of neon gates across the tracks: skate through the one with the right answer, dodge the trains and barriers, and grab diamonds.
- 20 questions from this lesson, in four parts of the city
- Swipe, tap or use the arrow keys
- Dodge trains and holograms, and jump crates and cones
20 questions, about 6 minutes
Bonus challenge
Neon Roll
Roll a glowing ball down an endless neon slope, past towers lit up with neon signs of Pixel the cat. Steer, jump the gaps and dodge the blocks. Questions from this lesson wait at gates along the way: every right answer keeps the ball rolling.
- Questions from this lesson at every gate
- Hold the arrow keys or a side of the slope to steer
- 8 right answers win two diamonds, 15 win three
Endless, about 5 minutes
The games need JavaScript. Every question is below, with the answers at the end.
Read the lesson: Data Structures
Data Structures: the questions
Quiz Challenge, round 1: Quiz Blitz
Which structure suits an undo feature?
- Binary search tree
- Stack
- Queue
- Hash table
What problem does a circular queue solve?
- The queue can never become full
- Space at the front is reused instead of wasted
- The queue can hold mixed data types
- Items can be searched faster
Inserting into the middle of a linked list only needs pointers to change.
- True
- False
Which traversal visits the left subtree, then the node, then the right subtree?
- Post order
- Breadth first
- In order
- Pre order
Why does an adjacency matrix waste memory on a sparse graph?
- It stores every edge three times
- It needs a pointer for every vertex
- It cannot store weights
- It uses n squared cells however few edges there are
Which TWO are true of arrays compared with linked lists?
Tick 2.
- Stored in contiguous memory
- Inserting in the middle only changes pointers
- They grow and shrink easily
- Each item stores a pointer to the next
- Direct access by index in constant time
After push(3), push(7), push(1), pop() and push(5), order the stack from top to bottom.
Number these 1 to 3.
- 7
- 3
- 5
A binary search tree stays balanced whatever order items are inserted in.
- True
- False
What is it called when two keys hash to the same index?
A hash table holds 70 items in 100 slots. What should happen as its load factor passes about 0.7?
- The oldest items are deleted
- It is sorted into order
- Every key is hashed twice
- It is rehashed into a larger array
Which data structure does breadth first search use?
- Hash table
- Tuple
- Queue
- Stack
What makes a tuple different from a list?
- It can only hold numbers
- It is always sorted
- It has no order
- It cannot be changed once created
Quiz Challenge, round 2: Quick Fire
Explain why a linked list is better than an array when items are often inserted in the middle. [2 marks]
Describe the difference between a stack and a queue. [2 marks]
Explain why an in order traversal of a binary search tree outputs values in ascending order. [2 marks]
Explain how separate chaining deals with collisions in a hash table. [2 marks]
Quiz Challenge, round 3: Big Think
Compare an array and a linked list. [6 marks]
Recommend a data structure for a contacts app that must find a contact by name instantly, and justify it. [4 marks]
This or That: tick the right answer
A graph has a million vertices and few edges. Which representation suits it?
- Adjacency list
- Adjacency matrix
Which suits a print queue?
- A queue
- A stack
Which gives direct access by index in constant time?
- A linked list
- An array
Which traversal suits deleting a whole tree?
- Pre order
- Post order
Which way of resolving collisions can cause clustering?
- Linear probing
- Separate chaining
Which structure is ordered but cannot be changed once made?
- A tuple
- A list
Items go into a binary search tree in sorted order. What does it become?
- Effectively a linked list
- A balanced tree
Which traversal suits copying a tree?
- In order
- Pre order
Memory Match: match each term to its meaning
| Term | Meaning |
|---|---|
| A Stack | 1 Items stored divided by slots available |
| B Queue | 2 A tree node with no children |
| C Load factor | 3 Each vertex stores its neighbours |
| D Leaf | 4 Nodes joined by pointers |
| E Adjacency list | 5 Last in, first out |
| F Linked list | 6 First in, first out |
Sort It: tick one box in each row
Which data structure suits each job best?
| Statement | Stack | Queue | Hash table | Binary search tree |
|---|---|---|---|---|
| Undo in a word processor | ||||
| Finding every score between 50 and 70 | ||||
| Caching web pages by their address | ||||
| A print spooler | ||||
| Keeping data sorted as items are added | ||||
| A keyboard buffer | ||||
| Return addresses when subroutines are called | ||||
| Breadth first search | ||||
| Depth first search | ||||
| Finding a user's record by username instantly | ||||
| Looking up a price from a product code | ||||
| Listing names in alphabetical order |
Code Word: write the word that fits each clue
A first in, first out structure, like a line at a bus stop. (5 letters)
A node in a graph, joined to others by edges. (6 letters)
An ordered collection that cannot be changed once it is made. (5 letters)
Link Up: find the three groups
These 12 tiles make 3 groups of 4. Write each group in the table, and what links its tiles.
- Chaining
- Linked list
- Rehashing
- Queue
- Root
- Load factor
- Child node
- Parent node
- Leaf
- Stack
- Array
- Collision
| Group | The 4 tiles | What links them |
|---|---|---|
| Group 1 | ||
| Group 2 | ||
| Group 3 |
Bug Hunt: tick the statement that is wrong
In each set, two statements are true and one has a mistake in it.
- A circular queue wastes the space at the front of the array.
- A queue is first in, first out.
- A stack is last in, first out.
- A linked list gives direct access to any item by its index.
- An array is stored in contiguous memory.
- A linked list node holds data and a pointer to the next node.
- Pre order traversal visits the left subtree before the node.
- Post order traversal suits deleting a tree.
- In order traversal of a binary search tree gives ascending order.
- An adjacency list suits a sparse graph.
- An adjacency matrix makes checking for one edge quick.
- An adjacency matrix uses less memory than a list for a sparse graph.
- Two keys that hash to the same index cause a collision.
- Linear probing can cause clustering.
- A hash table gets faster as its load factor rises.
Brain game: Odd One Out
Three tiles in each set share a link. Tick the odd one out, then write what links the other three.
- Rehashing
- Queue
- Stack
- Array
What links the other three?
- Load factor
- Child node
- Parent node
- Leaf
What links the other three?
- Chaining
- Rehashing
- Queue
- Load factor
What links the other three?
- Linked list
- Queue
- Array
- Collision
What links the other three?
- Root
- Parent node
- Leaf
- Stack
What links the other three?
- Chaining
- Rehashing
- Root
- Collision
What links the other three?
Brain game: Memory Flash, on paper
Which term means this? Write your answer from memory.
Items stored divided by slots available
A tree node with no children
Each vertex stores its neighbours
Nodes joined by pointers
Last in, first out
First in, first out
Brain game: Fact or Fib
Tick Fact if the statement is true and Fib if it is not.
A queue is first in, first out.
- Fact
- Fib
An adjacency matrix uses less memory than a list for a sparse graph.
- Fact
- Fib
A linked list gives direct access to any item by its index.
- Fact
- Fib
Two keys that hash to the same index cause a collision.
- Fact
- Fib
Linear probing can cause clustering.
- Fact
- Fib
An adjacency list suits a sparse graph.
- Fact
- Fib
Pre order traversal visits the left subtree before the node.
- Fact
- Fib
A hash table gets faster as its load factor rises.
- Fact
- Fib
An array is stored in contiguous memory.
- Fact
- Fib
Post order traversal suits deleting a tree.
- Fact
- Fib
A circular queue wastes the space at the front of the array.
- Fact
- Fib
A binary search tree stays balanced whatever order items are inserted in.
- Fact
- Fib
City Run
City Run is a race through a neon cyber city, played on screen. It asks 20 of the questions above, from the quiz, This or That, Memory Flash and Fact or Fib.
Neon Roll
Neon Roll is a ball rolling down an endless neon slope, played on screen. Every right answer keeps it rolling. It asks the questions above, from the quiz, This or That, Memory Flash and Fact or Fib.
Answers
Round 1: Quiz Blitz
- Stack The last change made is the first one undone, which is last in, first out.
- Space at the front is reused instead of wasted The pointers wrap round using MOD, so slots freed at the front are used again.
- True The new node points at the next node and the previous node points at the new one. No items move.
- In order In order traversal of a binary search tree gives the values in ascending order.
- It uses n squared cells however few edges there are Most of the cells record that there is no edge, so an adjacency list is far smaller.
- Direct access by index in constant time; Stored in contiguous memory Arrays are contiguous with direct access. The other three describe linked lists.
- 5 → 7 → 3 pop() removes the 1 that was pushed last, then 5 goes on top of 7 and 3.
- False Inserting items in sorted order sends every item down the same side, so the tree degenerates into a linked list.
- collision Collisions are resolved by separate chaining or by probing for the next free slot.
- It is rehashed into a larger array As the load factor rises collisions become frequent, so the table moves to a bigger array.
- Queue Breadth first search visits nodes in the order they were found: first in, first out.
- It cannot be changed once created A tuple is ordered but immutable.
Round 2: Quick Fire
- A linked list only changes pointers
- An array must shift every later element
Model answerInserting into a linked list only means changing two pointers, but an array must shift every later element along to make room.
- A stack is last in, first out
- A queue is first in, first out
- A stack works at one end; a queue adds at the rear and removes from the front
Model answerA stack is last in, first out, so the item pushed most recently is popped first. A queue is first in, first out, so items leave in the order they arrived.
- It visits the left subtree, then the node, then the right subtree
- Everything on the left is smaller and everything on the right is larger
Model answerIn order traversal visits the left subtree, then the node, then the right subtree, and in a binary search tree everything on the left is smaller and everything on the right is larger.
- Each slot holds a list
- Every item hashing to that index is added to its list
- A lookup hashes the key and searches that list
Model answerEach slot holds a linked list, and every item whose key hashes to that index is added to the list, so finding an item means hashing its key and searching that slot's list.
Round 3: Big Think
- An array is stored in contiguous memory
- A linked list is made of nodes connected by pointers
- An array has a fixed size, while a linked list grows and shrinks
- An array gives direct access by index in constant time
- A linked list must be traversed from the start
- Inserting in the middle shifts an array but only changes pointers in a list
- A linked list uses extra memory for each pointer
Model answerAn array is stored in contiguous memory and has a fixed size, while a linked list is made of nodes stored anywhere and connected by pointers, so it grows and shrinks dynamically. An array gives direct access to any element by its index in constant time, but a linked list must be traversed from the start. Inserting into the middle of an array means shifting every later element, but in a linked list only two pointers change. A linked list also uses extra memory to store a pointer in each node.
- Recommends a hash table
- A hash function maps each name to an index
- Lookup takes constant time on average, however many contacts there are
- Collisions are handled by chaining or probing
- The table is rehashed when the load factor gets too high
Model answerA hash table is the best choice. A hash function maps each name to an index in an array, so a contact is found in constant time on average, however many contacts there are. Collisions, where two names hash to the same index, can be handled by chaining, and the table is rehashed into a larger array when the load factor gets too high.
This or That
- Adjacency list A matrix needs n squared cells however few edges there are. A list only stores the edges that exist.
- A queue Jobs should print in the order they were sent: first in, first out.
- An array The address is the base plus the index times the element size, so no traversal is needed.
- Post order Post order visits both children before the node, so nothing is deleted while it is still needed.
- Linear probing Probing fills neighbouring slots, so items bunch together and later searches take longer.
- A tuple A tuple is immutable. A list can grow, shrink and change.
- Effectively a linked list Every new item goes down the same side, so searching becomes linear.
- Pre order Pre order visits each node before its children, so the copy can be built from the top down.
Memory Match
- A 5 Stack: Last in, first out
- B 6 Queue: First in, first out
- C 1 Load factor: Items stored divided by slots available
- D 2 Leaf: A tree node with no children
- E 3 Adjacency list: Each vertex stores its neighbours
- F 4 Linked list: Nodes joined by pointers
Sort It
- Stack Undo in a word processor The most recent change is undone first: last in, first out.
- Binary search tree Finding every score between 50 and 70 The tree keeps values ordered, so a range can be found without checking everything.
- Hash table Caching web pages by their address The address is the key, so a hash table finds the cached page at once.
- Queue A print spooler Documents print in the order they were sent: first in, first out.
- Binary search tree Keeping data sorted as items are added Each new item goes into its ordered place in the tree.
- Queue A keyboard buffer Key presses must be handled in the order they were typed.
- Stack Return addresses when subroutines are called The most recent call returns first, so return addresses go on a stack.
- Queue Breadth first search Breadth first search visits nodes in the order they were found, using a queue.
- Stack Depth first search Depth first search backtracks to the most recent branch, which a stack gives.
- Hash table Finding a user's record by username instantly A hash table finds a key in constant time on average.
- Hash table Looking up a price from a product code Lookup by key is exactly what a hash table is for.
- Binary search tree Listing names in alphabetical order An in order traversal of a binary search tree gives the names in order.
Code Word
- QUEUE A first in, first out structure, like a line at a bus stop.
- VERTEX A node in a graph, joined to others by edges.
- TUPLE An ordered collection that cannot be changed once it is made.
Link Up
- Linear structures Array; Stack; Queue; Linked list
- Parts of a tree Root; Leaf; Parent node; Child node
- Hash tables Collision; Load factor; Rehashing; Chaining
Bug Hunt: the wrong statement, and why
- A circular queue wastes the space at the front of the array. That is the problem with a linear queue. A circular queue wraps its pointers round so the space is reused.
- A linked list gives direct access to any item by its index. A linked list must be traversed from the start. Direct access by index is what an array gives.
- Pre order traversal visits the left subtree before the node. Pre order visits the node first, then the left subtree, then the right.
- An adjacency matrix uses less memory than a list for a sparse graph. A matrix always uses n squared cells, so on a sparse graph it wastes far more memory than a list.
- A hash table gets faster as its load factor rises. As the load factor rises, collisions become more frequent and performance falls, so the table is rehashed.
Odd One Out
- Rehashing is the odd one out: it goes with Hash tables. The other three: Linear structures.
- Load factor is the odd one out: it goes with Hash tables. The other three: Parts of a tree.
- Queue is the odd one out: it goes with Linear structures. The other three: Hash tables.
- Collision is the odd one out: it goes with Hash tables. The other three: Linear structures.
- Stack is the odd one out: it goes with Linear structures. The other three: Parts of a tree.
- Root is the odd one out: it goes with Parts of a tree. The other three: Hash tables.
Memory Flash
- Load factor Items stored divided by slots available
- Leaf A tree node with no children
- Adjacency list Each vertex stores its neighbours
- Linked list Nodes joined by pointers
- Stack Last in, first out
- Queue First in, first out
Fact or Fib
- Fact A queue is first in, first out.
- Fib An adjacency matrix uses less memory than a list for a sparse graph. The fix: A matrix always uses n squared cells, so on a sparse graph it wastes far more memory than a list.
- Fib A linked list gives direct access to any item by its index. The fix: A linked list must be traversed from the start. Direct access by index is what an array gives.
- Fact Two keys that hash to the same index cause a collision.
- Fact Linear probing can cause clustering.
- Fact An adjacency list suits a sparse graph.
- Fib Pre order traversal visits the left subtree before the node. The fix: Pre order visits the node first, then the left subtree, then the right.
- Fib A hash table gets faster as its load factor rises. The fix: As the load factor rises, collisions become more frequent and performance falls, so the table is rehashed.
- Fact An array is stored in contiguous memory.
- Fact Post order traversal suits deleting a tree.
- Fib A circular queue wastes the space at the front of the array. The fix: That is the problem with a linear queue. A circular queue wraps its pointers round so the space is reused.
- Fib A binary search tree stays balanced whatever order items are inserted in. The fix: Inserting items in sorted order sends every item down the same side, so the tree degenerates into a linked list.

