Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

. Consider the following definition of a hashtable with a partially implemented rehash method, which will either grow or shrink the buckets array to the

. Consider the following definition of a hashtable with a partially implemented rehash method, which will either grow or shrink the buckets array to the provided value n_buckets (while keeping all existing key/value mappings).

class Hashtable:

def rehash(self, n_buckets):

new_buckets = [None] * n_buckets

for b in self.buckets:

while b:

b_next = b.next

________________________________

________________________________

________________________________

b = b_next

self.buckets = new_buckets

Which correctly completes the rehash method?

(a) idx = hash(b.key) % n_buckets

b.next = new_buckets[idx]

new_buckets[idx] = b

(b) idx = hash(b.key) % len(self.buckets)

b.next = new_buckets[idx]

self.buckets[idx] = b

(c) idx = hash(b.key) % len(self.buckets)

self.buckets[idx] = new_buckets[idx]

b.next = new_buckets[idx]

(d) idx = hash(b.key) % n_buckets

new_buckets[idx].next = b

b.next = new_buckets[idx]

(e) idx = hash(b.key) % n_buckets

b.next = new_buckets[idx].next

new_buckets[idx].next = b

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_2

Step: 3

blur-text-image_3

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

More Books

Students also viewed these Databases questions