Question

Suppose you have the following hash table, implemented using linear probing. The hash function we are...

Suppose you have the following hash table, implemented using linear probing. The hash function we are using is the identity function, h(x) = x.

0

1

2

3

4

5

6

7

8

9

8

12

3

14

4

21

In which order could the elements have been added to the hash table? There are more than one correct answers, and you should give all of them. Assume that the hash table has never been resized, and no elements have been deleted yet.

  1. 9, 14, 4, 18, 12, 3, 21
  2. 12, 3, 14, 18, 4, 9, 21
  3. 12, 14, 3, 9, 4, 18, 21
  4. 9, 12, 14, 3, 4, 21, 18
  5. 12, 9, 18, 3, 14, 21,4

Give explanation for your answer.

0 0
Add a comment Improve this question Transcribed image text
Answer #1
1) [9, 14, 4, 18, 12, 3, 21]
Inserting 9
9 is inserted at position 0

Inserting 14
14 is inserted at position 5

Inserting 4
4 is inserted at position 4

Inserting 18
There is already an item in 0
So, checking at index 1
18 is inserted at position 1

Inserting 12
12 is inserted at position 3

Inserting 3
There is already an item in 3
So, checking at index 4
There is already an item in 4
So, checking at index 5
There is already an item in 5
So, checking at index 6
3 is inserted at position 6

Inserting 21
There is already an item in 3
So, checking at index 4
There is already an item in 4
So, checking at index 5
There is already an item in 5
So, checking at index 6
There is already an item in 6
So, checking at index 7
21 is inserted at position 7

HashTable
-----------
0   -      9
1   -      18
2   -
3   -      12
4   -      4
5   -      14
6   -      3
7   -      21
8   -

2) [12, 3, 14, 18, 4, 9, 21]
Inserting 12
12 is inserted at position 3

Inserting 3
There is already an item in 3
So, checking at index 4
3 is inserted at position 4

Inserting 14
14 is inserted at position 5

Inserting 18
18 is inserted at position 0

Inserting 4
There is already an item in 4
So, checking at index 5
There is already an item in 5
So, checking at index 6
4 is inserted at position 6

Inserting 9
There is already an item in 0
So, checking at index 1
9 is inserted at position 1

Inserting 21
There is already an item in 3
So, checking at index 4
There is already an item in 4
So, checking at index 5
There is already an item in 5
So, checking at index 6
There is already an item in 6
So, checking at index 7
21 is inserted at position 7

HashTable
-----------
0   -      18
1   -      9
2   -
3   -      12
4   -      3
5   -      14
6   -      4
7   -      21
8   -

3) [12, 14, 3, 9, 4, 18, 21]
Inserting 12
12 is inserted at position 3

Inserting 14
14 is inserted at position 5

Inserting 3
There is already an item in 3
So, checking at index 4
3 is inserted at position 4

Inserting 9
9 is inserted at position 0

Inserting 4
There is already an item in 4
So, checking at index 5
There is already an item in 5
So, checking at index 6
4 is inserted at position 6

Inserting 18
There is already an item in 0
So, checking at index 1
18 is inserted at position 1

Inserting 21
There is already an item in 3
So, checking at index 4
There is already an item in 4
So, checking at index 5
There is already an item in 5
So, checking at index 6
There is already an item in 6
So, checking at index 7
21 is inserted at position 7

HashTable
-----------
0   -      9
1   -      18
2   -
3   -      12
4   -      3
5   -      14
6   -      4
7   -      21
8   -

4) [9, 12, 14, 3, 4, 21, 18]
Inserting 9
9 is inserted at position 0

Inserting 12
12 is inserted at position 3

Inserting 14
14 is inserted at position 5

Inserting 3
There is already an item in 3
So, checking at index 4
3 is inserted at position 4

Inserting 4
There is already an item in 4
So, checking at index 5
There is already an item in 5
So, checking at index 6
4 is inserted at position 6

Inserting 21
There is already an item in 3
So, checking at index 4
There is already an item in 4
So, checking at index 5
There is already an item in 5
So, checking at index 6
There is already an item in 6
So, checking at index 7
21 is inserted at position 7

Inserting 18
There is already an item in 0
So, checking at index 1
18 is inserted at position 1

HashTable
-----------
0   -      9
1   -      18
2   -
3   -      12
4   -      3
5   -      14
6   -      4
7   -      21
8   -

5) [12, 9, 18, 3, 14, 21, 4]
Inserting 12
12 is inserted at position 3

Inserting 9
9 is inserted at position 0

Inserting 18
There is already an item in 0
So, checking at index 1
18 is inserted at position 1

Inserting 3
There is already an item in 3
So, checking at index 4
3 is inserted at position 4

Inserting 14
14 is inserted at position 5

Inserting 21
There is already an item in 3
So, checking at index 4
There is already an item in 4
So, checking at index 5
There is already an item in 5
So, checking at index 6
21 is inserted at position 6

Inserting 4
There is already an item in 4
So, checking at index 5
There is already an item in 5
So, checking at index 6
There is already an item in 6
So, checking at index 7
4 is inserted at position 7

HashTable
-----------
0   -      9
1   -      18
2   -
3   -      12
4   -      3
5   -      14
6   -      21
7   -      4
8   -

Answer:
---------
iii)    12, 14, 3, 9, 4, 18, 21
iv)     9, 12, 14, 3, 4, 21, 18
Add a comment
Know the answer?
Add Answer to:
Suppose you have the following hash table, implemented using linear probing. The hash function we are...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • A. What is the time complexity of Insertion Sort? B. Explain why Insertion Sort has the...

    A. What is the time complexity of Insertion Sort? B. Explain why Insertion Sort has the time complexity you listed above in Part A. C. Show the steps followed by the Quicksort algorithm given below in pseudocode when sorting the following array. Algorithm Quicksort (A, left, right) if (left < right) pivot Point + [(left+right)/2] // note central pivot it left - 1 j right + 1 do do iti + 1 while (i < A.size) and (A[i] = A[pivotPoint])...

  • The task of this project is to implement in Java Hash Table structure using Linear Probing...

    The task of this project is to implement in Java Hash Table structure using Linear Probing Collision Strategy.   You can assume that no duplicates or allowed and perform lazy deletion (similar to BST). Specification Create a generic class called HashTableLinearProbe <K,V>, where K is the key and V is the value. It should contain a private static class, HashEntry<K,V>. Use this class to create array to represent Hashtable:             HashEntry<K,V> hashtable[]; Implement all methods listed below and test each method...

  • Question 8: (a) We create a Hash Table of size 7, using open addressing and linear...

    Question 8: (a) We create a Hash Table of size 7, using open addressing and linear probing with the hash function h(n)=n%7. Write the content of the array after inserting the following values in sequence: 11, 28,46, 7,67, 88,0. (3 marks) . loj [1] [2] [3] [41-5] 问 (b) Explain the issue linear probing has and how it can be addressed. (3 marks)

  • Suppose we are inserting strings into a hash table of size 9. Suppose we have two...

    Suppose we are inserting strings into a hash table of size 9. Suppose we have two hash functions, h, and h2. The hash values for certain strings of these functions are shown in the table below: Fill in the hash table below assuming that we are using open-address, linear-probing style hashing, given that the table starts as it appears below, the hash function is h_1 and the order of insertion is "Fred", "Chloe", "Adam", "Rebecca" and "Reggie". Fill in the...

  • You have a hash table of length 7 (tablesize 7). You are given a hash function...

    You have a hash table of length 7 (tablesize 7). You are given a hash function f(x)-x % tablesize, where x is the value to be hashed and fix) is the hash address. Quadratic probing is used to resolve the collisions. The hash function receives the input 40, 26, 15, 12, 5, 17) in that order. Place each number in hash table in its correct address. The first two values are already placed in their correct positions If there isn't...

  • Let 'M' denote the hash table size. Consider the following four different hash table implementations: a....

    Let 'M' denote the hash table size. Consider the following four different hash table implementations: a. Implementation (I) uses chaining, and the hash function is hash(x)x mod M. Assume that this implementation maintains a sorted list of the elements (from biggest to smallest) for each chain. b. Implementation (II) uses open addressing by Linear probing, and the hash function is ht(x) - (hash(x) + f(i)) mod M, where hash(x)x mod M, and f(i)- c. Implementation (III) uses open addressing by...

  • Linear Hash Table 2. In this first question you will apply the specified operations to instances...

    Linear Hash Table 2. In this first question you will apply the specified operations to instances of LinearHashTable (i.e., hash tables that use the "linear probing" approach as it was discussed in class). When such a hash table is first created, it has dimension 1 and an initial length of 2, and subsequent operations might require that the underlying array be resized, so for each of the questions below, start with the hash table specified and demonstrate (by drawing the...

  • Tree & Hash Table & Heap Use the following integer keys 73, 58, 91, 42, 60,...

    Tree & Hash Table & Heap Use the following integer keys 73, 58, 91, 42, 60, 130, 64, 87 to perform the followings: a) Binary Search Tree - Draw a binary search tree - Retrieve the integers keys in post-order - Retrieve the integers keys in pre-order - Draw a binary search tree after node 58 is deleted b) Create a Hash Table using the methods described below. Show the final array after all integer keys are inserted. Assumes that...

  • please use Java!! We are storing the inventory for our fruit stand in a hash table....

    please use Java!! We are storing the inventory for our fruit stand in a hash table. The attached file shows all the possible key/fruit combinations that can be inserted into your hash table. These are the real price lookup values for the corresponding fruit. Problem Description In this programming assignment, you will implement a hash table class fruitHash. Your hash table must include the following methods: 1) hashFunction(key) This method takes a key as an argument and returns the address...

  • C++ assignment - Hash table with linear probing --- implement in single file - main.cpp You...

    C++ assignment - Hash table with linear probing --- implement in single file - main.cpp You are asked to implement a very specific hash table. The keys are lower-case English words (e.g., apple, pear). The length of a key is at most 10. The hash function is “simply using the last character”. That is, the hash value of apple should be e, and the hash value of pear should be r. Your hash table contains exactly 26 slots (hash value...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT