Question

In: Computer Science

Write a program to insert the following elements into a hash table of size 17. The...

Write a program to insert the following elements into a hash table of size 17. The hash function is X mod 17 where X is the input element.  

6, 12, 34, 29, 28, 11, 23, 7, 0, 33, 30, 45

Use linear probing to resolve any collisions.

Solutions

Expert Solution

Q-> Write a program to insert the following elements into a hash table of size 17. The hash function is X mod 17 where X is the input element.  

6, 12, 34, 29, 28, 11, 23, 7, 0, 33, 30, 45

  1. Insert 6: Index = 6 mod 17 = 6

Hash table =

0
1
2
3
4
5

6

6
7
8
9
10
11
12
13
14
15
16

2. Insert 12: Index = 12 mod 17 = 12

Hash table =

0
1
2
3
4
5

6

6
7
8
9
10
11
12 12
13
14
15
16

3. Insert 34: Index = 34 mod 17 = 0

Hash table =

0

34

1
2
3
4
5

6

6
7
8
9
10
11
12 12
13
14
15
16

4. Insert 29: Index = 29 mod 17 = 12

Collision occurred, use linear probing, => index = 13

Hash table =

0

34

1
2
3
4
5

6

6
7
8
9
10
11
12 12
13 29
14
15
16

5. Insert 28: Index = 28 mod 17 = 11

Hash table =

0

34

1
2
3
4
5

6

6
7
8
9
10
11 28
12 12
13 29
14
15
16

6. Insert 11: Index = 11 mod 17 = 11

Collision occurred: => use linear probing,=> index = 12

again Collision occurred: => use linear probing,=> index = 13

again Collision occurred: => use linear probing,=> index = 14

Hash table =

0

34

1
2
3
4
5

6

6
7
8
9
10
11 28
12 12
13 29
14 11
15
16

7. Insert 23: Index = 23 mod 17 = 6

Collision occurred: => use linear probing,=> index = 7

Hash table =

0

34

1
2
3
4
5

6

6
7 23
8
9
10
11 28
12 12
13 29
14 11
15
16

8. Insert 7: Index = 7 mod 17 = 7

Collision occurred: => use linear probing,=> index = 8

Hash table =

0

34

1
2
3
4
5

6

6
7 23
8 7
9
10
11 28
12 12
13 29
14 11
15
16

9. Insert 0: Index = 0 mod 17 = 0

Collision occurred: => use linear probing,=> index = 1

Hash table =

0

34

1 0
2
3
4
5

6

6
7 23
8 7
9
10
11 28
12 12
13 29
14 11
15
16

10. Insert 33: Index = 33 mod 17 = 16

Hash table =

0

34

1 0
2
3
4
5

6

6
7 23
8 7
9
10
11 28
12 12
13 29
14 11
15
16 33

11. Insert 30: Index = 30 mod 17 = 13

Collision occurred: => use linear probing,=> index = 14

Collision occurred: => use linear probing,=> index = 15

Hash table =

0

34

1 0
2
3
4
5

6

6
7 23
8 7
9
10
11 28
12 12
13 29
14 11
15 30
16 33

12. Insert 45: Index = 45 mod 17 = 11

next free index is 2 using linear probing

Final Hash table =

0

34

1 0
2 45
3
4
5

6

6
7 23
8 7
9
10
11 28
12 12
13 29
14 11
15 30
16 33

Related Solutions

1.Consider hashing with a table size of 100 and a hash function of key%tablesize. Insert 25...
1.Consider hashing with a table size of 100 and a hash function of key%tablesize. Insert 25 keys. Do you expect to see any collisions? Why or why not? Yes, because random values likely will land on same locations. No becase there are four times as many slots as needed. 2. Secondary clustering means that elements that hash to the same position will probe to the same alternate cells. Simple hashing uses key%tablesize as the hash function. Which of the following...
Use double hashing and the following hash functions: hash(key) = (key % table size) and hash2(key)...
Use double hashing and the following hash functions: hash(key) = (key % table size) and hash2(key) = (16 - (key % 10)) + 1 to insert the following numbers into a dictionary's hash table: 1, 12, 14, 3, 5 and 17. The table size is 11. Show the table and where each value is inserted. No coding required for this problem.
in JAVA, Hash table The goal is to count the number of common elements between two...
in JAVA, Hash table The goal is to count the number of common elements between two sets. Download the following data sets, and add them to your project: girlNames2016.txt boyNames2016.txt These files contain lists of the 1,000 most popular boy and girl names in the US for 2016, as compiled by the Social Security Administration. Each line of the file consists of a first name, and the number of registered births that year using that name. Your task is to...
Write an AFTER Insert trigger for the following Employee table. Check Date of Birth and calculate...
Write an AFTER Insert trigger for the following Employee table. Check Date of Birth and calculate age. Update AGE field with calculated value in Employee_Info table Employee (Emp_ID int, DOB date) Employee_Info (Emp_ID int, Fname char, Lname char, Age int) Set variable Current_Date to CURDATE() Substract DOB from Current_Date to find Age
Java Write a menu driven program that implements the following linked list operations : INSERT (at...
Java Write a menu driven program that implements the following linked list operations : INSERT (at the beginning) INSERT_ALPHA (in alphabetical order) DELETE (Identify by contents, i.e. "John", not #3) COUNT CLEAR
write C program to implement the priority queue with the operation insert
write C program to implement the priority queue with the operation insert
Write an algorithm to delete an element from a hash table that uses linear probing as...
Write an algorithm to delete an element from a hash table that uses linear probing as its clash resolution strategy. Analyze your algorithm and show the results using order notation?
Write a program that does the following:  Assume the canvas size of 500X500.  The...
Write a program that does the following:  Assume the canvas size of 500X500.  The program asks the user to enter a 3 digit number.  The program then checks the value of the first and last digit of the number.  If the first and last digits are even, it makes the background green and displays the three digit number at the mouse pointer.  If the two digits are odd, it makes the background red and displays...
Write a program that does the following:  Assume the canvas size of 500X500.  The...
Write a program that does the following:  Assume the canvas size of 500X500.  The program asks the user to enter a 3 digit number.  The program then checks the value of the first and last digit of the number.  If the first and last digits are even, it makes the background green and displays the three digit number at the mouse pointer.  If the two digits are odd, it makes the background red and displays...
SHOW WORK Draw the hash table that results using the hash function: h(k)=kmod7 to hash the...
SHOW WORK Draw the hash table that results using the hash function: h(k)=kmod7 to hash the keys 41, 16, 40, 47, 10, 55. Assuming collisions are handled by Double hashing. SHOW WORK
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT