logo

SEO Suggestions for Desklib

7 Pages1158 Words304 Views
   

Added on  2020-06-06

About This Document

This article provides SEO suggestions for Desklib, an online library for study material. It includes tests for Hash Table, Table Size, Collision Count, and Hash Function. It also includes functions for linear and quadratic probing, chain hash table, and word frequency. The output is strictly in JSON format.

SEO Suggestions for Desklib

   Added on 2020-06-06

ShareRelated Documents
Task1:from task1 import Hash_Tabledef testlen(): #Correct test lengthtest = Hash_Table() lengthtest.__setitem__("favNumber", "5") length = lengthtest.__len__() assert length == 1, "Oops! Wrong number!"def testGetItem(): test = Hash_Table() test.__setitem__("bf", "PM") bfTest = test.__getitem__("bf") assert bfTest == "PM", "Get item Non-functional"def testSetItem(): #Correct test setItemTest = Hash_Table() setItemTest.__setitem__("favNumber", "Five") #You need to set the item first favNumber = setItemTest.__getitem__("favNumber") assert favNumber == "Five", "Set item Non-functional!"def testcontains(): test = Hash_Table() test.__setitem__("favSubject", "Maths") subjectTest = test.__contains__("favSubject") assert subjectTest == False, "incorrect input __contains__"print(myHash)if __name__ == '__main__': testSetItem() testlen() #testcontains() testGetItem() print("All tests were passed !")
SEO Suggestions for Desklib_1
Task2:Table SizeWall timeComments210000209987400000399989202361Task 3:n = 1500global collision_countcollision_count = 0class Foo(): def __eq__(self, other): global collision_count collision_count += 1 return id(self) == id(other) def __hash__(self): #return id(self) # @John Machin: yes, I know! return 1objects = [Foo() for i in xrange(n)]d = {}for o in objects: d[o] = 1print collision_count
SEO Suggestions for Desklib_2
Task 4import randomimport mathdef linear_probe(random_list, m): hash_table = [None]*m count = 0 for i in random_list: stop = False hash = i % m while not stop: if hash_table[hash] == None: hash_table[hash] = i stop = True else: hash = (hash+1) % m count +=1 return countdef quadratic_probe(random_list, m): hash_table = [None]*m count = 0 for i in random_list: j = 1 stop = False hash = i % m while not stop: if hash_table[hash] == None: hash_table[hash] = i stop = True else: hash = (hash+j) % m count +=1 j = int((math.sqrt(j)+1) ** 2) return countdef comp_lists(list1, list2):
SEO Suggestions for Desklib_3

End of preview

Want to access all the pages? Upload your documents or become a member.

Related Documents
Python code for Merge Sort, Doubly Linked List and Binary Tree
|9
|1107
|290