Question bank › A-level Computer Science › Fundamentals of data structures

Hash tables, dictionaries and vectors

Answer on paper first, then reveal the mark scheme one mark at a time.

1Hard6 marks

A hash table has 11 locations, indexed 0 to 10. The hashing function is h(key) = key MOD 11. Collisions are handled by rehashing using linear probing (the next free location is used, wrapping round from 10 to 0).

Index012345678910
Key

(a) Show the contents of the hash table after the keys 23, 45, 70, 13, 81 are inserted in that order. [3]

(b) Explain the steps taken to search the table for the key 92 and state how many occupied locations are examined before the search ends. [2]

(c) State what is meant by a collision in a hash table. [1]

2Standard4 marks

The Python program below uses a dictionary.

words = "the cat sat on the mat the end".split()
counts = {}
for w in words:
    counts[w] = counts.get(w, 0) + 1
print(counts["the"], len(counts))

(a) State the output of the program. [2]

(b) Explain why a dictionary is a suitable data structure for counting how many times each word occurs in a very long document, rather than a list of [word, count] pairs. [2]

3Standard5 marks

The vectors u = [3, −1, 2] and v = [1, 4, −2] are defined over ℝ.

(a) Calculate u + v. [1]

(b) Calculate 2u − v. [1]

(c) Calculate the dot product u · v and state what the result tells you about the angle between the two vectors. [2]

(d) The vector w = 0.25u + 0.75v. Explain why w is a convex combination of u and v. [1]

Stuck on this topic?

Book a free 30-minute session on WhatsApp and we'll find exactly which step is costing you the marks. Or build a timed paper on it.

Free 30-minute session