Data Structures & AlgorithmsHardProduct placement · Amazon/Microsoft
Keys 55, 63, 47, 69, 16, 97, 39, 99, 77, 43 are inserted in this order into a chained hash table with 7 buckets, h(k) = k mod 7, and each new key is placed at the HEAD of its chain. A successful search compares keys along the chain. How many key comparisons does a search for 55 make, and what is the longest chain length?
- A. comparisons: 1; longest chain: 3
- B. comparisons: 2; longest chain: 3
- C. comparisons: 3; longest chain: 4
- D. comparisons: 3; longest chain: 3
Correct answer: D. comparisons: 3; longest chain: 3
Bucket 6 receives 55, 69, 97 in that order; head insertion reverses them, so 55 (inserted first) is at the tail and takes 3 comparisons.
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
- Floyd's cycle detection on a list whose last node links back into the list. What does this print (meeting value, cycle-start value, cycle…
- What does this loop-counting code print? (Python) python n, c = 70000, 0 i = 2 while i <= n: c += 1 i = i i print(c)
- In the binary array [1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 0, 0] you may flip at most 2 zeros to ones. What is the length of the longest run…
- Evaluate an infix expression of single digits with two stacks (operands and operators, usual precedence, left-associative). What is…
- Swap every two adjacent nodes of a linked list by relinking (not by swapping values). What is printed? python def swappairs(h): d = p =…
- How many pairs (i < j) of [2, 15, 17, 10, 24, 2, 10, 2, 4, 9] have a[i] + a[j] divisible by 4? (Count remainders mod 4 and pair r with 4 −…