Answered step by step
Verified Expert Solution
Link Copied!

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!

image text in transcribed

image text in transcribed

image text in transcribed

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 = (LinkedList[] (new LinkedList[tableSize]); // go through all items in old table for (LinkedList 1 : hashTable) {

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

PostgreSQL 10 High Performance Expert Techniques For Query Optimization High Availability And Efficient Database Maintenance

Authors: Ibrar Ahmed ,Gregory Smith ,Enrico Pirozzi

3rd Edition

1788474481, 978-1788474481

More Books

Students also viewed these Databases questions