Hash Tables in Python [004]

preview_player
Показать описание

In this video, I'll explain the concepts behind a Hash Table and show you how to create your very own in Python.

Lecture: 0:00
Code: 6:19
Challenges: 10:19

Рекомендации по теме
Комментарии
Автор

Thank you for your effort to make the video! It really helped me!

jingyuchang
Автор

This was a great explanation and using linked list. Thank you for making for this video!

CaptainLungi
Автор

Great content, One thing I wanted to share that we can decrease the insert time to the bucket in O(1) - Constant time by inserting an element to the head(Front) of the LinkedList.Thanks

anirvansen
Автор

Dude, thanks for the video. What would make this better, is putting it into action on some data and having a look at the outputs. Then I can really understand what each part of the Class is doing and apply/tweak to my issue.

sabinkstudio
Автор

good explainer, thanks! your teaching is very good

shawn
Автор

I wish I could follow what you were doing. Seemed like you did a really good job, I'm just not at the level to follow yet.

amorestperpe
Автор

Your hash method returns 1 for every character in the alphabet. This makes it hard to solve the 3 challenges you proposed. I had to modify it you " * ord(c)" instead of " ** ord(c)". For full strings works fine.
Besides that, great implementation!
Thank you!

ionutztkd
Автор

I thought my monitor suddenly had very thick bezels. Great video btw.

anjelpatel
Автор

Good One...
It would be great if you add the print function, which prints the buckets with the inserted key, values

LakshmiKarthikFilms
Автор

Subscribed, You helped me so much. Thank you a lot.

bu
Автор

There is an issue with the remove function. Its not working properly. Suppose if the node is first node, then it is not handling the case properly and secondly the error is coming because the prev is not initialised.

himanshu
Автор

Can the actual hash function you are using be replaced by any of more popular ones like SHA- or MD-? I assume for the scope of the example problems it shouldnt matter?

russellzheng
Автор

Your delete method does not initialize prev if the first node is a match. a prev = None declaration is missing.

benjaminfloyd
Автор

Hey ! I was wondering if you could review 2 quick hashtable classes I've made. They're using the djb2, crc32 and K&R algorithm for the hash function and your video helped me a lot so feedback would really mean a lot to me :) Thanks for your superb videos !

hisaohorii
Автор

thanks for the video but I think in line 52 there is a mistake because prev can never be None
edit: I think you should initialize prev with None

mhdimhdi
Автор

how would you define the character code?

hakankanplay
Автор

Hi, the link of the blog article is 404 Not Found

christys
Автор

INITIAL_CAPACTIY = 50

class Node:
def __init__(self, key, value):
self.key = key
self.value = value
self.next = Node

class HashTable:
def __init__(self):
self.capacity = INITIAL_CAPACTIY
self.size = 0
self.buckets = [None] * self.capacity

def hash(self, key):
hash_sum = 0
for idx, c in enumerate(key):
hash_sum += (idx + len(key)) ** ord(c)
hash_sum %= self.capacity
return hash_sum

def insert(self, key, value):
self.size += 1
index = self.hash(key)
node = self.buckets[index]
if node is None:
self.buckets[index] = Node(key, value)
return
prev = node
while node is not None:
prev = node
node = node.next
prev.next = Node(key, value)

def find(self, key):
index = self.hash(key)
node = self.buckets[index]
while node is not None and node.key != key:
node = node.next
if node is None:
return None
else:
return node.value

def remove(self, key):
index = self.hash(key)
node = self.buckets[index]
while node is not None and node.key != key:
prev = node
node = node.next
if node is None:
return None
else:
self.size -= 1
result = node.value
if prev is None:
node = None
else:
prev.next = prev.next.next
return result

kvelez
Автор

why the hashsum is so convoluted? couldn't we just have used a simpler coding?

almuntasirabir
Автор

Could you please help me in hash table
please share you contact detail so that i can share the problem statement with you

mukulprasad