Give an example of a probe sequence produced by quadratic probing that does not reach the entire hash table, even if the size of the table is a prime number.
Let the size of the hash table be 7.
The input sequence be : 1 4 8 15 10 22
Index | Key |
0 | |
1 | 1 |
2 | 8 |
3 | 10 |
4 | 4 |
5 | 15 |
6 |
In the above hash table, first 1 is inserted.
hash(1) = 1 mod 7 = 1 and the element is at index 1 in the hash table.
The next element inserted is 4.
hash(4) = 4 mod 7 = 4 and the element is at index 4 in the hash table.
The next element inserted is 8.
hash(8) = 8 mod 7 = 1 but index 1 is already filled up in the hash table.
So, apply quadratic hashing for i^2 = 1^2
hash(8) = (( 8 mod 7 ) + 1) mod 7 = 2 and so, 8 is inserted at index 2.
The next element to be inserted is 15.
hash(15) = 15 mod 7 = 1
but index 1 is already filled up in the hash table.
So, apply quadratic hashing for i^2 = 1^2
hash(15) = (( 15 mod 7 ) + 1) mod 7 = 2 but index 2 is also filled up.
Apply quadratic hashing for i^2 = 2^2 = 4
hash(15) = (( 15 mod 7 ) + 4) mod 7 = 5 and so, 15 is inserted at index 5.
The next element to be inserted is 10.
hash(10) = 10 mod 7 = 3 and the key 10 is placed at index 3.
The next element to be inserted is 22.
hash(22) = 22 mod 7 = 1
but index 1 is already filled up in the hash table.
So, apply quadratic hashing for i^2 = 1^2
hash(22) = (( 22 mod 7 ) + 1) mod 7 = 2 but index 2 is also filled up.
Apply quadratic hashing for i^2 = 2^2 = 4
hash(22) = (( 22 mod 7 ) + 4) mod 7 = 5 but index 5 is already filled up.
Apply quadratic hashing for i^2 = 3^2 = 9
hash(22) = (( 22 mod 7 ) + 9) mod 7 = 3 but index 3 is already filled up.
So, to check key 22 is suffering from secondary clusterting or not, let there be the following table :
i^2 for i = 0,1,2 .. | 0 | 1 | 4 | 9 | 16 | 25 | 36 | 49 | 63 | 81 | 100 | 121 | 144 | 169 | 196 |
((22 mod 7) + i ) | 1 | 2 | 5 | 10 | 17 | 26 | 37 | 50 | 64 | 82 | 101 | 122 | 145 | 170 | 197 |
((22 mod 7) + i ) mod 7 | 1 | 2 | 5 | 3 | 3 | 5 | 2 | 1 | 2 | 5 | 3 | 3 | 5 | 2 | 1 |
Is index empty | False | False | False | False | False | False | False | False | False | False | False | False | False | False | False |
It can be seen from the above table that the value of ( ((22 mod 7) + i ) mod 7 ) is following a pattern as :
1 2 5 3 3 5 2 1 2 5 3 3 5 2 1
This means the quadratic probing wants 22 to be placed in either 1,2 ,3 or 5. But all the 4 places have been filled up and the other empty spaces would remain unutilized. This is a phenomenon known as secondary clustering which is the disadvantage of quadratic probing. Hence, the value 22 does not reach the entire hash table.
Give an example of a probe sequence produced by quadratic probing that does not reach the...
6. A hash table has size 7, uses quadratic probing (f(i) = 1), and has hash function h(2) = 2%7. (Recall, % is the Java "mod" function.) Draw the contents of the hash table after the following sequence of insertions: insert 0, insert 7, insert 14, insert 21. The hash table is initially empty.
Python: Write a program that inserts numbers from a file into a quadratic probing hash table and records the amount of collisions that occur after each insertion. Hash Table size is 191, so 100 random numbers are to be inserted to the table to collect number of collisions.
True or False? 1. Duplicate hash codes create collisions. 2. In open addressing with linear probing, a successful search for an entry that corresponds to a given search key could potentially follow a different probe sequence used to add the entry to the hash table. 3. Completely balance binary trees are not necessarily full. 4. A preorder traversal of a binary tree is an example of a depth-first traversal.
Canvas → XCO Question 4 5 pts When using a hash table with quadratic probing, and the table size is prime, then a new element can always be inserted if the table is at least half empty the table is at least half full the table is full the table is larger than any data value Question 5 5 pts The general strategy of inorder traversal is: process the left subtree, then process the current node and finally process the...
ZOOM Page 7. Apply the following operations on the following Quadratic probing haslh table. Write down all your calculations and changes to the hash table Hashi (key): key % 16 Hash2(key): 11-key % 11 Double hashing probing sequence (Hashi (key) + i * Hash2(key)) % 16 149 3 88 a. (5 points)HashInsert(Table, 17) 6 16 7 23 8 24 10 42 12 99 13 14 15 b. (5 points)Hashremove(Table,16) ZOOM Page 7. Apply the following operations on the following Quadratic...
You are given the following data 659, 230, 751, 291, 433, 955, 518, 34, 189, 239 to insert into a table of size 10. The hash function is hash(key) = key mod tableSize. Assume that the table is allowed to get full without starting a rehashing. Draw the resulting hash table when open addressing with quadratic probing is used. You must write the indices calculated by the hash function hash(key) and by the probing strategy hi(key) for all reattempts, for...
#3 [3 points] Sketch a hash table of size N=11, where the hash function is hash(key) = key mod N and quadratic probing is used to resolve collisions, after the following elements are inserted: 20, 42, 45, 49, 62, 72, 95. The probes are based on this equation: (H+c1∗i+c2∗i2)mod(N) and c1=1, c2=1. If direct hashing was used to store the same elements as the previous problems (20, 42, 45, 49, 62, 72, 95), what should be the minimum size of...
(in Java) We wish to insert the following strings into a hash table: BEN AL SUE CHUCK KAREN MIKE SAM MIKE ALICE TARA TIM BOB Let's make the hash table size p=19 ( 19 is a prime ). Use letter encodings where A maps to 1, B maps to 2, etc and strings map to powers of 26. For example, "ABC" would map to 1*(26^2) + 2*(26^1)+ 3*(26^0) mod 19 (you might find the web site Wolfram Alpha helpful. Just...
8. In plain English, explain how Mergesort, and QuickSort algorithms work and give your reasons why QuickSort is considered to be the fastest algorithm in practice even so the Mergesort runs always as Θ(MogN) and Quicksort as θ(NlogN) only on average while for some inputs can run as long as o(N-)? 9. On simple examples, explain how quadratic probing works and why it can fail if a hash table is over half full. 8. In plain English, explain how Mergesort,...
13) consider the following sequence of keys to be inserted in a hash table of size 13 that uses a quadratic probing to resolve collisions select the choice that indicateds what the hash table looks like after all the keys are inserted (0 indicates an empty slot) {23, 4, 78 , 17 , 30, 81, 41, 5} a) 78, 41, 0, 81, 4, 5, 17, 0, 30, 0, 23, 0, 0 b) 78, 17, 41, 81, 4, 5, 0, 30,...