Answer to Question #261065 in Python for kishan

Question #261065

Implementation of Hash Table with collision resolution techniques

in python with algorithm


1
Expert's answer
2021-11-04T08:37:58-0400
# Function to display hashtable 

def display_hash(hashTable): 


      

    for i in range(len(hashTable)): 


        print(i, end = " ") 


          

        for j in hashTable[i]: 


            print("-->", end = " ") 


            print(j, end = " ") 


              

        print() 


  
# Creating Hashtable as  
# a nested list. 

HashTable = [[] for _ in range(10)] 


  
# Hashing Function to return  
# key for every value. 

def Hashing(keyvalue): 


    return keyvalue % len(HashTable) 


  

  
# Insert Function to add 
# values to the hash table 

def insert(Hashtable, keyvalue, value): 


      

    hash_key = Hashing(keyvalue) 


    Hashtable[hash_key].append(value) 


  
# Driver Code 

insert(HashTable, 10, 'Allahabad') 


insert(HashTable, 25, 'Mumbai') 


insert(HashTable, 20, 'Mathura') 


insert(HashTable, 9, 'Delhi') 


insert(HashTable, 21, 'Punjab') 


insert(HashTable, 21, 'Noida') 


  
display_hash (HashTable)

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog