Data Structures & AlgorithmsHardInfosys · Accenture pattern
A hash table of size 10 uses linear probing. Slots 2, 3, 4, 7 and 8 are occupied and all others are empty (no deletions have happened). An UNSUCCESSFUL search is made for a key whose hash is 2. How many slots are examined?
- A. 3
- B. 4
- C. 1
- D. 6
Correct answer: B. 4
The search walks 2, 3, 4 (all occupied, none match) and stops at the first empty slot, 5: 4 slots examined. The empty slot must be checked too – that is how the search knows the key is absent – so '3' undercounts.
Practise more Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questionsArrays, Strings, Linked Lists, Stacks, Queues and Hashing: notes and key points
More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions
- Quickselect with Lomuto partition (pivot = last element) looks for the 3rd smallest element of [7, 2, 9, 4, 3, 8], recursing only into the…
- Binary search finds the index of the minimum of the rotated sorted array [15, 18, 22, 3, 6, 9, 12] using: mid = (lo + hi) / 2; if a[mid] >…
- The sorted array [3, 4, 7, 10, 11] contains some positive integers. What is the 4th positive integer MISSING from it?
- For [2, 3, 0, 4], out[i] is the product of all elements except a[i], computed with prefix and suffix products (no division). What is out?
- The intervals [1, 4], [6, 8], [2, 3], [8, 10], [12, 13] are sorted by start and merged (intervals that touch at an endpoint also merge)…
- A 'leader' is an element strictly greater than every element to its right (the last element is always a leader). Scanning from the right…