Hash Table – Data Structures & Algorithms Tutorials In Python #5
[ad_1]
Hash map or hash table is a very popular data structure. It allows to store key, value pairs and using key you can locate a value in O(1) or constant time. We will implement simple hash table in python in this tutorial and in part 2 we will see how to handle collisions.
Code: https://github.com/codebasics/data-structures-algorithms-python/tree/master/data_structures/4_HashTable/4_HashTable.ipynb
Topics
00:00 Introduction
00:34 Array vs hashmap Scenario
03:52 Memory presentation (array vs hashmap)
04:15 Hash function
07:09 Big O Analysis
07:17 Hashmap in Python/JAVA/C++
07:47 Implement Hash Table in python
#datastructures #algorithms #python
Next Video: https://www.youtube.com/watch?v=54iv1si4YCM&list=PLeo1K3hjS3uu_n_a__MI_KktGTLYopZ12&index=6
Previous video: https://www.youtube.com/watch?v=qp8u-frRAnU&list=PLeo1K3hjS3uu_n_a__MI_KktGTLYopZ12&index=4
Complete playlist:https://www.youtube.com/playlist?list=PLeo1K3hjS3uu_n_a__MI_KktGTLYopZ12
Website: http://codebasicshub.com/
Facebook: https://www.facebook.com/codebasicshub
Twitter: https://twitter.com/codebasicshub
Patreon: https://www.patreon.com/codebasics
Source
[ad_2]
Part 2: https://youtu.be/54iv1si4YCM
i have a question w/ hashmaps/tables, in your example of using h = 0 and h += ord(char), and h % 100, isn't it possible for multiple occurrences of different h values getting the same h % 100, for example h = 309, 209, 109 all equal h % 100 = 9, additionally I would imagine there are multiple waysof getting the sum_total h = 309 depending on the characters, wouldn't these multiple occurrences overwrite each other in the hash table?
Thank you 💕 sir 😊
very well explained…
Thank you sir
You have been incredibly helpful to me and many others. Thank you!
Hello, That was really a nice illustration. I have a question if you could help me with that…I have to store binary matrices and further, I want to retrieve that matrices on some similarity(exact or approximate) basis with the query matrix, not on the index basis. Can you suggest a suitable data structure for this task? I mean should I use the Hash-table or Tree or any user-defined data structure?
But how to cook lasagna?
This video is amazing thank you
so writing into a dictionary or writing into list which is more complex by time
amazing video thank you so so much
Dude, you are cool and your videos are awesome. Best wishes from NYC.
thumbs up
finally i got the concept of hash table. thank you so much.
Can you please share how the retrieving function is changing when the add function is changed to __getitem__?
Hey, why do we need to set the size of the hash table? Can't we change it dynamically?
You're amazing dude!
6:52
I have been python developer for past 4 years.
Just used dictionary many times. But never knew how the internals of it worked.
This was great explanation. Thanks.
Okay few questions:
1. Where is the hash table stored?
2. Are these objects(key, value) pairs stored contiguously in memory?
3. If my self.arr has 5 elements and I try to add the 6th one the first added hash-value is overwritten in self.arr but I can still access the new value with the first added hash, why is that so?
@codebasics.. I really like and Appreciate your effort and i understand much better now.. thank you for that… while i have a qq:
Q: what if the modulo returns a value which is out of the 100 (MAX) like 101.. or some thing..? i mean if ord(char) returns a value which is out of bounds..?
8:10 , why not use the hash function instead of ord(). Are there trade offs for using either?