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.

Host this setFree Play

The 20 questions

  1. 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
  2. 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
  3. Which Python expression creates an empty dictionary?

    • []
    • ()
    • <>
    • {}
  4. 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
  5. 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
  6. 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
  7. 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
  8. A dictionary d holds {'apple': 3, 'pear': 5}. After d['apple'] = d['apple'] + 1, what is d['apple']?

    • 5
    • 8
    • 3
    • 4
  9. 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
  10. 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
  11. Dictionary scores = {'Ali': 55, 'Bea': 72, 'Cal': 61}. What does max(scores, key=scores.get) return?

    • 'Cal'
    • 72
    • 'Ali'
    • 'Bea'
  12. Which statement removes the key 'pear' from dictionary d in Python?

    • d.delete(pear)
    • d.remove('pear')
    • d['pear'].clear()
    • del d['pear']
  13. 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
  14. 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
  15. 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
  16. 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]
  17. 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)
  18. 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
  19. 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
  20. 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

All AQA Computer Science quizzes