题目
单项选择题
Htables_fsl_3 Consider the following _find_slot function and the corresponding test setup: The following test setup is used to evaluate the behavior of this function, load factor is ignored. # Create a hash map with a small size for testinghash_map = ProbeHashMap(7) # Assume a small table size of 7 for simplicity# Manually fill all slots except onehash_map._table = [ hash_map._Item('keyX', 'valueX'), hash_map._Item('keyY', 'valueY'), hash_map._Item('keyZ', 'valueZ'), hash_map._Item('keyW', 'valueW'), None, hash_map._Item('keyQ', 'valueQ'), hash_map._Item('keyR', 'valueR')]# Call the function with the following parameters:found, slot = hash_map._find_slot(5, 'keyM') What will the call to hash_map._find_slot(5, 'keyM') return? ProbeHashMap is shared below for your reference:
选项
A.(False, 4) because index 4 is the first empty slot found during probing.
B.(True, 4) because the function finds an available slot.
C.(True, 5) because the key matches the one at index 5.
D.(False, 6) because it wraps around to continue searching.
查看解析
标准答案
Please login to view
思路分析
The question presents a hash map with a small, manually filled table and asks what hash_map._find_slot(5, 'keyM') will return when probing begins at index 5.
First, note the table contents by index (0 to 6):
0 -> 'keyX', 1 -> 'keyY', 2 -> 'keyZ', 3 -> 'keyW', 4 -> None, 5 -> 'keyQ', 6 -> 'keyR'.
The probe starts at index 5 due t......Login to view full explanation登录即可查看完整答案
我们收录了全球超50000道考试原题与详细解析,现在登录,立即获得答案。
类似问题
Consider an implementation of a hash table with linear probing where the hash function runs in constant time and the cost of comparison is also constant. What is the best-case time complexity of the __getitem__ method? Consider n is the number of items in the hash table.
Which is TRUE?
What is the best case time complexity of deleting a key from a linear probe table?
Question at position 2 About how many steps would be needed when searching for a particular key in a hash map with 1000 nodes?1000150010
更多留学生实用工具
希望你的学习变得更简单
加入我们,立即解锁 海量真题 与 独家解析,让复习快人一步!