Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Suppose you insert() an item into a hashtable and then immediately do a lookup() on that item as the methods shown below. What is the
Suppose you insert() an item into a hashtable and then immediately do a lookup() on that item as the methods shown below. What is the worst-case complexity of the program in this situation? Briefly explain the answer please. Thanks!
public void insert(T item) { int initSize = tableSize; if (hashTable == null) { throw new NullPointerException(); // hash index int hashIndex = hashTable.hashCode() % initSize; if (hashIndex (); hashTable[hashIndex]. add(item); } else { hashTable[hashIndex].add(item); // increment number of items in the list numItems++; // check is the size of table is enough, resize if needed if (double) (numitems / initSize) > loadFactor || (hashTable[hashIndex]).size() + 1 > maxChainLength && maxChainLength > 1) { // resize tableSize = initSize * 2 + 1; // new table with new size newTable = (LinkedListStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started