1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Aliun [14]
3 years ago
14

Provided below is the implementation of the hashtable data structure we went over together in class. You are to implement the re

hash method, which will be called with a new size for the internal buckets array. rehash will create a new buckets array, copy all the key/value pairs from the old buckets array into the new one, using linked list chains as before to support collisions, then switch to using the new buckets array. rehash should run in O(N) time, where N is the number of key/value pairs,. Your implementation of rehash should not make use of any other hashtable or list methods (other than those demonstrated in __setitem__ and __getitem__). Note that the first and last lines of rehash are given; you should not alter them.
Computers and Technology
1 answer:
Sati [7]3 years ago
3 0

Answer:

numBuckets = 47

def create():

global numBuckets

hSet = []

for i in range(numBuckets):

hSet.append([])

# print "[XYZ]: create() hSet: ", hSet, " type(hSet): ",type(hSet)

return hSet

def hashElem(e):

global numBuckets

return e % numBuckets

def insert(hSet,i):

hSet[hashElem(i)].append(i)

# print "[XYZ]: insert() hSet: ", hSet, " type(hSet): ",type(hSet)

def remove(hSet,i):

newBucket = []

for j in hSet[hashElem(i)]:

if j != i:

newBucket.append(j)

hSet[hashElem(i)] = newBucket

print "[XYZ]: remove() i: ", i," hashElem[i]: ", hashElem(i), " hSet[hashElem(i): ", hSet[hashElem(i)]

def member(hSet,i):

return i in hSet[hashElem(i)]

def testOne():

s = create()

for i in range(40):

insert(s,i)

print "[XYZ]: S: ", s

insert(s,325)

insert(s,325)

insert(s,9898900067)

print "[XYZ]: S: ", s

print "[XYZ]: ,member(s,325): ",member(s,325)

remove(s,325)

print "[XYZ]: After Remove, member(s,325): ",member(s,325)

print "[XYZ]: member(s,9898900067)",member(s,9898900067)

testOne()

You might be interested in
This motherboard already has 1GB of RAM installed in the DIMM1 slot. The customerwould like to upgrade to 4GB total memory, use
Luden [163]

Answer:

The two phases to the context of this discussion are listed follows.

Explanation:

  • <u>Solution 1</u>: Delete 1 GB of current RAM as well as install another DIMM0 Chan A slot through one 2 GB of double-channel RAM. (thinkable unless the 2 GB RAM is provided by the motherboard in what seems like a DIMM0 Chan A slot)  
  • <u>Solution 2</u>: whether there's an unused or blank slot, perhaps one 1 GB dual-channel Ram could be mounted in some other slot at around the same speed or frequency.  

It's quite safer to mount memory with appropriate frequencies across both situations.

6 0
3 years ago
What changes might you make to a circuit in order to slow the flow of electrical energy?
Brilliant_brown [7]
it’s gravity that’s what my teacher said
3 0
3 years ago
In excel what happens when rename a sheet from sheet1 to inventory​
makvit [3.9K]

Answer:

Explanation:

The sheet name at the footer of the screen gets changed from sheet1 to inventory.

4 0
3 years ago
Describe the steps to play a presentation the way your audience will see it. A)Go to the View tab and select Editing View. B)Go
Sonbull [250]

C) Go to the View tab and select Slide Show.

Explanation:

Steps for Slide Show View to Deliver a Presentation:

  • Go to the Slide Show view from the Task bar at the bottom of the slide window.
  • Use the Slide Show view to deliver your presentation to your audience.
  • Slide Show view occupies the full computer screen.

5 0
3 years ago
Geraldo would like to compare two areas of text, Text1 and Text2, to each other. What steps should he take?
Phoenix [80]

Answer:

Can you elaborate on this?

7 0
3 years ago
Other questions:
  • Explain what might happen if two stations are accidentally assigned the same hardware address?
    15·1 answer
  • What is the unit of electric power?
    15·1 answer
  • Write a fragment of code that will read words from the keyboard until the word done is entered. For each word except done, repor
    14·1 answer
  • An _____image is an image that appears on a web page
    8·1 answer
  • Users report that the network access is slow. After questioning the employees, the network administrator learned that one employ
    10·1 answer
  • Which of these is an off-site metric for social media marketing?
    8·2 answers
  • What is required to view other users’ calendars in Schedule view? Check all that apply.
    15·1 answer
  • An intruder with malicious intent breaks into an office and steals a hard drive containing sensitive information about the compa
    12·1 answer
  • Can i get some help please .
    5·2 answers
  • What component of a change management program includes final testing that the software functions properly
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!