Practice mode Data Structures

Keys 15, 22 and 8 are inserted in that order into a hash table of size 7 using h(k) = k mod 7 and linear probing. At which index is 8 stored?

Correct answer B. 3

Explanation

15 mod 7 = 1, so 15 goes to index 1. 22 mod 7 = 1 collides, and linear probing tries the next slot, index 2. 8 mod 7 = 1 collides, index 2 is taken, so it moves on to index 3, which is free. Linear probing's tendency to build such runs of occupied slots is called primary clustering.

Report a problem

Answer checked How we write and check questions

Tip: press A, B, C or D to answer, and N for the next question.

Advertisement

Have a question about this answer?

Your email address will not be published. Required fields are marked *

Links and website addresses are not allowed in comments.