CSC-2740 Quiz 5

Réussis tes devoirs et examens dès maintenant avec Quizwiz!

Given the following hash table, how many items are compared when searching for item 45 using the following search algorithm? # | Value ------------ 0 | 1 | 2 | 47 3 | 28 4 | 5 | 25, 45, 65 6 | 7 | HashSearch(hashTable, key) { bucketList = hashTable[Hash(key)] itemNode = ListSearch(bucketList, key) if (itemNode is not null) return itemNode⇢data else return null } ----------------------------------------------------------------------------- 3 items: 25, 45 and 65 4 items: 47, 28, 25, and 45 2 items: 25 and 45 1 item: only 45

2 items: 25 and 45

Consider a hash table using chaining with 10 buckets and a hash function of key % 10. What would bucket 3's list be after the following operations? HashInsert(hashTable, item 12) HashInsert(hashTable, item 23) HashInsert(hashTable, item 34) HashInsert(hashTable, item 45) HashInsert(hashTable, item 33) HashInsert(hashTable, item 31) HashInsert(hashTable, item 30) ----------------------------------------------------------------------------- 23, 33 23, 30, 31, 33 34, 33 24, 33, 31, 30

23, 33

Consider the following hash table, and a hash function of key % 10. How many list items will be compared for the search operations? # | Value ------------ 0 | 50 1 | 2 | 12, 72 3 | 63, 33 4 | 5 | 45, 95 6 | 7 | 27 8 | 9 | HashInsert(newTable, item 25) HashInsert(newTable, item 54) HashRemove(newTable, 27) HashInsert(newTable, item 84) HashInsert(newTable, item 83) HashSearch(newTable, 72) HashSearch(newTable, 77) HashSearch(newTable, 63) ----------------------------------------------------------------------------- 2; 0; 2 2; 0; 3 1; 0; 3 2; 0; 1

2; 0; 1

Given the following hash table and a hash function of key % 10, HashSearch(hashTable, 53) probes _____ buckets. EAR = Empty After Removal EFS = Empty From Start OCC = Occupied Type | # | Value ---------------------- (EAR) | 0 | (OCC) | 1 | 11 (EFS) | 2 | (OCC) | 3 | 33 (EAR) | 4 | (EFS) | 5 | 53 (OCC) | 6 | 66 (EFS) | 7 | (EFS) | 8 | (EFS) | 9 | ----------------------------------------------------------------------------- 0 1 2 3

3

A 5-bucket hash table has the items 45, 56, and 67. The hash table's items will be positive integers. Which of the following is the correct way of representing the hash table? ----------------------------------------------------------------------------- 0, 45, 56, 67, 0 45, 56, 67, 0, 0 -1, 45, 56, 67, 1 45, 56, 67, -1, -1

45, 56, 67, -1, -1

Consider a hash table with items 10, 31, 23, 54, 66, 88, and 9, and a hash function of key % 10. Which of the following items will result in a collision if the numbers are inserted in order? 55, 46, 77, 99, 93, 92, 97 ----------------------------------------------------------------------------- 55, 77, 99, 92 55, 77, 92, 97 46, 99, 93, 97 46, 77, 99, 93

46, 99, 93, 97

Consider a hash table named idTable that uses linear probing and a hash function of key % 10. What is printed after the following operations? HashInsert(idTable, item 45) HashInsert(idTable, item 67) HashInsert(idTable, item 76) HashInsert(idTable, item 78) HashInsert(idTable, item 79) HashInsert(idTable, item 92) HashInsert(idTable, item 87) Print HashSearch(idTable, 67) Print HashSearch(idTable, 77) Print HashSearch(idTable, 87) ----------------------------------------------------------------------------- 67, 87 67, null, 87 67, false, 87 true, false, true

67, null, 87

Consider the following hash table, and a hash function of key % 5. What would bucket 3's list be after the following operations? # | Value ------------ 0 | 25, 95, 50 1 | 2 | 3 | 68, 33, 48 4 | 84, 54 HashRemove(hashTable, 25) HashRemove(hashTable, 48) HashInsert(hashTable, item 53) ----------------------------------------------------------------------------- 33, 53 68, 33, 53 68, 33, 48 68, 33, 48, 53

68, 33, 53

A hash table named numTable uses a hash function of key % 10 and quadratic probing with c1 = 1 and c2 = 2. Into which bucket is item 44 inserted? HashInsert(numTable, item 1) HashInsert(numTable, item 12) HashInsert(numTable, item 23) HashInsert(numTable, item 34) HashInsert(numTable, item 44) ----------------------------------------------------------------------------- 5 6 7 8

7

Consider a hash table named marksTable that uses linear probing and a hash function of key % 5. What would be the location of the item 46? HashInsert(marksTable, item 49) HashInsert(marksTable, item 41) HashInsert(marksTable, item 42) HashInsert(marksTable, item 44) HashInsert(marksTable, item 46) ----------------------------------------------------------------------------- Bucket 0 Bucket 1 Bucket 2 Bucket 3

Bucket 3

Which collision resolution technique places the item in another empty bucket? ----------------------------------------------------------------------------- Chaining Open hashing Open addressing Closed addressing

Open addressing

A hash function uses an item's ___ to compute the item's bucket index. ----------------------------------------------------------------------------- bucket key function location

key

What operation is used to compute a bucket index in the range 0 to 16 from a key? ----------------------------------------------------------------------------- key * 17 key - 17 key / 17 key % 17

key % 17

Consider a hash table named numTable that uses linear probing and a hash function of key % 5. What is the status of bucket 4 after the following operations? HashInsert(numTable, item 24) HashInsert(numTable, item 33) HashInsert(numTable, item 51) HashInsert(numTable, item 44) HashInsert(numTable, item 52) HashRemove(numTable, 44) HashInsert(numTable, item 50) ----------------------------------------------------------------------------- empty-since-start empty-after-removal occupied removed from table

occupied

Which XXX completes the following algorithm? HashSearch(hashTable, key) { bucket = Hash(key) bucketsProbed = 0 while ((hashTable[bucket] is not EmptySinceStart) and (bucketsProbed < N)) { if ((hashTable[bucket] is not Empty) and (hashTable[bucket].key == key)) { XXX } bucket = (bucket + 1) % N ++bucketsProbed } return null } ----------------------------------------------------------------------------- return hashTable[key] return hashTable[bucket] return bucket return key

return hashTable[bucket]


Ensembles d'études connexes

Lecture 1 - Binary and Operator Overloading

View Set

CompTIA A+ 220-1101 Exam Acronyms Quiz

View Set

Walt Whitman and Emily Dickinson Test

View Set

Project Management - Ch. 10 MCQ only

View Set

Ch2: Life Insurance: Life Insurance - Life Basics

View Set