Lesson 4.2.7.1
4.2.7.1 Dictionaries and key-value pairs Quiz: AQA Computer Science, Unit 2
20 questions
In partnership with Revision Ninja
Lesson 4.2.7.1, Dictionaries and key-value pairs: 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 dictionary in the context of data structures?
- A first-in, first-out queue of records processed in arrival order
- A sequence of values accessed only by their numeric position starting from zero
- A fixed-length block of memory holding values of one data type
- A collection of key-value pairs in which each value is accessed through its associated key
-
In a dictionary, which part of each entry must be unique?
- The data type of the value
- The position of the entry
- The value
- The key
-
Which Python expression creates an empty dictionary?
- []
- ()
- <>
- {}
-
In an information retrieval dictionary built from a document, what does each key typically represent?
- A word taken from the document
- The position of the document in a folder
- The number of lines in the document
- A random identifier generated for each sentence
-
Which Python syntax retrieves the value stored against a key k in dictionary d?
- d[0], indexing with the first position
- d.sort(k), sorting the dictionary by key
- d[k], indexing with the key in square brackets
- d.find(k) only
-
The document 'The green, green grass grows' is stored as {'grass': 1, 'green': 2, 'grows': 1, 'the': 1}. What value is associated with 'green'?
- The string 'green' itself
- 1
- 2
- 3
-
Why are dictionaries well suited to information retrieval?
- They require every key to be an integer
- They store each value only as a single character
- They keep entries in the order in which they were typed
- They look up a value directly from its key without scanning every entry
-
A dictionary d holds {'apple': 3, 'pear': 5}. After d['apple'] = d['apple'] + 1, what is d['apple']?
- 5
- 8
- 3
- 4
-
A word-count dictionary is built from the text 'The cat sat on the mat', ignoring letter case. What is the count stored for 'the'?
- 2
- 3
- 6
- 1
-
Dictionary d = {'a': 1, 'b': 2}. After executing d['c'] = 3, what does len(d) return?
- 4
- An error, because keys cannot be added after creation
- 3
- 2
-
Dictionary scores = {'Ali': 55, 'Bea': 72, 'Cal': 61}. What does max(scores, key=scores.get) return?
- 'Cal'
- 72
- 'Ali'
- 'Bea'
-
Which statement removes the key 'pear' from dictionary d in Python?
- d.delete(pear)
- d.remove('pear')
- d['pear'].clear()
- del d['pear']
-
Using a list of key-value pairs instead of a dictionary, what is the worst-case number of key comparisons needed to find one key among 1000 entries?
- 500
- 1000
- 1
- 10
-
A dictionary is built ignoring letter case from the sentence 'The cat and the hat'. What are the final entries for 'the'?
- 'the': 2
- 'the': 1
- 'The': 1 and 'the': 1 as separate keys
- 'The': 2 as the stored key
-
A student database is keyed by student ID rather than by name. Which reason best justifies this design?
- Names cannot be stored as strings in Python
- IDs are unique, so each key maps to exactly one record
- IDs are quicker to type than names
- Dictionaries cannot use strings as keys
-
Dictionary d = {'x': [1, 2], 'y': [3]}. After d['x'].append(4), what is d['x']?
- An error, because values cannot be changed
- [1, 2]
- [1, 2, 4]
- [4]
-
Dictionary lookup in Python is typically which order of complexity on average?
- Exponential time, O(2^n)
- Linear time, O(n)
- Logarithmic time, O(log n)
- Constant time, O(1)
-
A sparse vector of length 1,000,000 has only three non-zero entries. Why might a dictionary be preferred to a list?
- Dictionaries cannot store zero values, so a list would be invalid
- Dictionaries store every index automatically
- Only the three non-zero entries need storing as key-value pairs, which saves memory
- Lists cannot hold floating-point numbers
-
Dictionary d = {'a': 1, 'b': 2, 'a': 5}. What are len(d) and d['a']?
- Length 3, and d['a'] is 1
- Length 2, and d['a'] is 1
- An error, because keys repeat
- Length 2, and d['a'] is 5
-
A dictionary can be used to represent a vector. Which mapping best matches this idea?
- Index to entry value
- Index to index only
- Value to index only
- Entry to entry name only
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
- Stack operations Quiz · 4.2.3.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
- Vectors and vector operations Quiz · 4.2.8.1 · 20 questions
- Data types Quiz · 4.1.1.1 · 20 questions