Hash Tables Quiz (1)

¡Supera tus tareas y exámenes ahora con Quizwiz!

Consider a hash table with 100 slots. Collisions are resolved using chaining. Assuming simple uniform hashing, what is the probability that the first 3 slots are unfilled after the first 3 insertions?

(97 × 97 × 97)/100^3 Probability that the first 3 slots are unfilled after the first 3 insertions = (probability that first item doesn't go in any of the first 3 slots)* (probability that second item doesn't go in any of the first 3 slots)* (probability that third item doesn't go in any of the first 3 slots) = (97/100) * (97/100) * (97/100)

How many different insertion sequences of the key values using the hash function h(k) = k mod 10 and linear probing will result in the hash table shown below? 0 - 1 - 2 - 42 3 - 23 4 - 34 5 - 52 6 - 46 7 - 33 8 - 9 -

Answer: 30 Question 2 Explanation: In a valid insertion sequence, the elements 42, 23 and 34 must appear before 52 and 33, and 46 must appear before 33. Total number of different sequences = 3! x 5 = 30 In the above expression, 3! is for elements 42, 23 and 34 as they can appear in any order, and 5 is for element 46 as it can appear at 5 different places.

A hash table with ten buckets with one slot per bucket is shown in the following figure. The symbols S1 to S7 initially entered using a hashing function with linear probing.The maximum number of comparisons needed in searching an item that is not present is 0 - S7 1 - S1 2 - 3 - S4 4 - S2 5 - 6 - S5 7 - 8 - S6 9 - S3

Answer: 5 Question 15 Explanation: We have to consider different cases to find the maximum number of comparisons needed in searching an item that is not present. If searching starts at 0 index : 3 comparisons will be made at index 0, index 1 and finally at index 2 and terminate searching when index 2 found empty. Similarly after checking on different indexes, the maximum number of comparisons will be required if searching starts from index 8, as in this case, total 5 comparisons will be made at index 8, 9, 0, 1 and 2.

8. What is simple uniform hashing? a) Every element has equal probability of hashing into any of the slots b) A weighted probabilistic method is used to hash elements into the slots c) Elements has Random probability of hashing into array slots d) Elements are hashed based on priority

Answer: a Explanation: In simple uniform hashing, any given element is equally likely to hash into any of the slots available in the array.

7. What is the load factor? a) Average array size b) Average key size c) Average chain length d) Average hash table length

Answer: c Explanation: In simple chaining, load factor is the average number of elements stored in a chain, and is given by the ratio of number of elements stored to the number of slots in the array.

6. Which of the following is not a technique to avoid a collision? a) Make the hash function appear random b) Use the chaining method c) Use uniform hashing d) Increasing hash table size

Answer: d Explanation: On increasing hash table size, space complexity will increase as we need to reallocate the memory size of hash table for every collision. It is not the best technique to avoid a collision. We can avoid collision by making hash function random, chaining method and uniform hashing.

9. In simple uniform hashing, what is the search complexity?

Answer: d Explanation: There are two cases, once when the search is successful and when it is unsuccessful, but in both the cases, the complexity is O(1+alpha) where 1 is to compute the hash function and alpha is the load factor.

An advantage of chained hash table (external hashing) over the open addressing scheme is

Deletion is easier Question 12 Explanation: In Open Addressing scheme sometimes though element is present we can't delete it if empty bucket comes in between while searching for that element. External hashing scheme is free from this limitations .

10. In simple chaining, what data structure is appropriate?

Doubly linked list

Which of the following statement(s) is TRUE? - A hash function takes a message of arbitrary length and generates a fixed length code. - A hash function takes a message of fixed length and generates a code of variable length. - A hash function may give the same hash value for distinct messages.

I and III only

Assume that the number of elements in a linear probing hash table is N. What is a good choice for the size of the internal array M?

The size M of the internal array has to be larger than N, by some factor.

3. What is direct addressing?

a) Distinct array position for every possible key Explanation: Direct addressing is possible only when we can afford to allocate an array that has one position for every possible key.

5. What is a hash function?

b) A function that computes the location of the key in the array Explanation: In a hash table, there are fewer array positions than the keys, so the position of the key in the array has to be computed, this is done using the hash function.

1. What is a hash table?

b) A structure that maps keys to values Explanation: A hash table is used to implement associative arrays which has a key-value pair, so the has table maps keys to values.

What is the main reason to use a hash table instead of a red-black BST?

better performance in practice on typical inputs

What is the average running time of delete in a linear-probing hash table? Assume that your hash function satisfies the uniform hashing assumption and that the hash table is at most 50% full.

constant

4. What is the search complexity in direct addressing?

d) O(1) Explanation: Since every key has a unique array position, searching takes a constant time.

Which one of the following hash functions on integers will distribute keys most uniformly over 10 buckets numbered 0 to 9 for i ranging from 0 to 2020?

h(i) =i^3 mod 10


Conjuntos de estudio relacionados

ECO 102- practice questions exam 2

View Set

CASM C10 Lesson 10 - Scrum Events

View Set

Building Blocks of the Nervous System

View Set

Types and Characteristics of Fixed Income Securities

View Set

Anatomy Exam 1- Chapter 4: The Integumentary System New

View Set