Java Simulate the behavior of a hash map. Assume the following: the hash table array has an initial capacity of 10 the hash table uses separate chaining to resolve collisions and adds new values at the beginning of the linked list. the hash function returns the absolute value of the integer key, mod the capacity of the hash table rehashing occurs at the end of an add where the load factor is ≥ 0.5 and doubles the capacity of the hash table Fill in the diagram to show the final state of the hash table after the following operations are performed. Write each bucket as key:value pairs with arrows between them, such as key1:value1 -> key2:value2 -> key3:value3 . Put a \ in the box if an array element is unused. Also write the size, capacity, and load factor of the final hash table. Write the load factor in 0.x format, such as 0.5 or 0.75. hashTable[ 0 ] : _____ hashTable[ 1 ] hashTable[ 2 ] hashTable[ 3 ] hashTable[ 4 ] hashTable[ 5 ] hashTable[ 6 ] hashTable[ 7 ] hashTable[ 8 ] hashTable[ 9 ] hashTable[ 10 ] hashTable[ 11 ] hashTable[ 12 ] hashTable[ 13 ] hashTable[ 14 ] hashTable[ 15 ] hashTable[ 16 ] hashTable[ 17 ] hashTable[ 18 ] hashTable[ 19 ] size: ____ capacity:___ load factor:____

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Java

Simulate the behavior of a hash map. Assume the following:

  • the hash table array has an initial capacity of 10
  • the hash table uses separate chaining to resolve collisions and adds new values at the beginning of the linked list.
  • the hash function returns the absolute value of the integer key, mod the capacity of the hash table
  • rehashing occurs at the end of an add where the load factor is ≥ 0.5 and doubles the capacity of the hash table

Fill in the diagram to show the final state of the hash table after the following operations are performed. Write each bucket as key:value pairs with arrows between them, such as key1:value1 -> key2:value2 -> key3:value3 . Put a \ in the box if an array element is unused. Also write the size, capacity, and load factor of the final hash table. Write the load factor in 0.x format, such as 0.5 or 0.75.

hashTable[ 0 ] : _____

hashTable[ 1 ]

hashTable[ 2 ]

hashTable[ 3 ]

hashTable[ 4 ]

hashTable[ 5 ]

hashTable[ 6 ]

hashTable[ 7 ]

hashTable[ 8 ]

hashTable[ 9 ]

hashTable[ 10 ]

hashTable[ 11 ]

hashTable[ 12 ]

hashTable[ 13 ]

hashTable[ 14 ]

hashTable[ 15 ]

hashTable[ 16 ]

hashTable[ 17 ]

hashTable[ 18 ]

hashTable[ 19 ]

size: ____

capacity:___

load factor:____

);
hashTable[ 0 ]
hashTable[ 1]
hashTable[ 2]
hashTable[ 3 ]
hashTable[ 4]
hashTable[ 5 ]
hashTable[ 6 ]
hashTable[ 7]
hashTable[ 8 ]
hashTable[ 9 1
[1‒‒‒‒‒‒
Transcribed Image Text:); hashTable[ 0 ] hashTable[ 1] hashTable[ 2] hashTable[ 3 ] hashTable[ 4] hashTable[ 5 ] hashTable[ 6 ] hashTable[ 7] hashTable[ 8 ] hashTable[ 9 1 [1‒‒‒‒‒‒
Map<Integer, Integer> map = new HashMap<Integer, Integer>();
map.put(3, 8);
map.put(25, 75);
map.put(34, 18);
map.put(23, 9);
map.put(75, 8);
map.put(14, 43);
map.put (43, 4);
map.put(5, 9);
map.put(3, 25);
map.remove(8);
map.remove(43);
map.put(14, 18);
map.put(24, 15);
if (map.count(map.containsKey(25)) {
map.put(75, 24);
map.remove(18);
} else {
}
map.put(34, 18);
if(map.size() > 7) {
map.put(24, 24);
}
map.remove(map.get(75));
map.put(8, 0);
Transcribed Image Text:Map<Integer, Integer> map = new HashMap<Integer, Integer>(); map.put(3, 8); map.put(25, 75); map.put(34, 18); map.put(23, 9); map.put(75, 8); map.put(14, 43); map.put (43, 4); map.put(5, 9); map.put(3, 25); map.remove(8); map.remove(43); map.put(14, 18); map.put(24, 15); if (map.count(map.containsKey(25)) { map.put(75, 24); map.remove(18); } else { } map.put(34, 18); if(map.size() > 7) { map.put(24, 24); } map.remove(map.get(75)); map.put(8, 0);
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps with 2 images

Blurred answer
Knowledge Booster
Hash Table
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education