AlgoFrames

Predict degraded complexity

Standard · Trace the algorithm · about 6 min

A table has 8 buckets and uses key mod 8. An insert first scans its chain for a duplicate. Insert 8, 16, 24, 32, 40, then search for 40. Answer each question before the step plays.

Example 1

Input:

{"size":8,"keys":[8,16,24,32,40],"search":40}

Output:

5

Every key is a multiple of 8.

Constraints

  • 8 buckets, hash = key mod 8
  • An insert compares with every key already in its chain

Learn the idea first: Collisions, worst cases and mutable keys, a visual lesson.

More Collisions, worst cases and mutable keys problems