Hash Table - Data Structures & Algorithms Tutorials In Python #5

Поделиться
HTML-код
  • Опубликовано: 30 июл 2024
  • 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: github.com/codebasics/data-st...
    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
    #HashTable #HashMap #hashmappython #datastructures #algorithms #python
    Do you want to learn technology from me? Check codebasics.io/?... for my affordable video courses.
    Next Video: • Collision Handling In ...
    Previous video: • Linked List - Data Str...
    Complete playlist: • Data Structures And Al...
    🌎 My Website For Video Courses: codebasics.io/?...
    Need help building software or data analytics and AI solutions? My company www.atliq.com/ can help. Click on the Contact button on that website.
    #️⃣ Social Media #️⃣
    🔗 Discord: / discord
    📸 Dhaval's Personal Instagram: / dhavalsays
    📸 Codebasics Instagram: / codebasicshub
    🔊 Facebook: / codebasicshub
    📱 Twitter: / codebasicshub
    📝 Linkedin (Personal): / dhavalsays
    📝 Linkedin (Codebasics): / codebasics
    🔗 Patreon: www.patreon.com/codebasics?fa...

Комментарии • 227

  • @codebasics
    @codebasics  2 года назад +5

    Do you want to learn python from me with a lot of interactive quizzes, and exercises? Here is my project-based python learning course: codebasics.io/courses/python-for-beginner-and-intermediate-learners

    • @piyushkumarsahoo8771
      @piyushkumarsahoo8771 2 года назад

      What if hash function returns same value for 2 different keys

    • @syd6358
      @syd6358 Год назад

      @@piyushkumarsahoo8771 it is collision

  • @AmeerulIslam
    @AmeerulIslam 2 года назад +65

    "Dictionary is the python specific implementation of the hash table" This is gold!

    • @CHAN-xn9eq
      @CHAN-xn9eq 2 года назад

      yes

    • @zack176
      @zack176 Год назад

      5:55 bro i couldn't get this first method what does it called i can't hear it can you tell whats that table at right

    • @janardhanmukkamala2733
      @janardhanmukkamala2733 Год назад +1

      @@zack176 It is ASCII table, it is a fixed table of characters .
      in this table every alphabet has a specific number in which that number is converted to binary number

  • @siddharthsinghh
    @siddharthsinghh 2 года назад +3

    I watched this video and now my understanding of dict is much more clear how behind the scenes are actually handled .
    Thank you so much sir
    Please keep it up

  • @khangnguyendac7184
    @khangnguyendac7184 2 года назад +3

    Wow, I'm surprise. The way you explain the concept, how to use it, how to use it in the better way is so easy to understand. Thank you so much!

  • @neilgibson88
    @neilgibson88 3 года назад +7

    best explanation around!! and i've been through many hash table and dictionary videos. Thank you!!

  • @tharindusathsara3414
    @tharindusathsara3414 Год назад +5

    Really very happy about finding such an obvious and understood funny video series about data structures and algorithms. Everything is 100% clear with deeply explained theories and well-understood practicals. Also, the exercise series with the videos are highly appreciated. Dear sir thank you so much for the fantastic video series. ❤💖

  • @njoy2075
    @njoy2075 4 года назад +16

    it is an insanely awesome explanation. this I guess is the best explanation in youtube..

  • @goldschmiedejaqueline6339
    @goldschmiedejaqueline6339 Год назад +3

    An explanation about conflicts and how they are implemented like doing a linear search at each index would be great to show!

  • @nandkul
    @nandkul 2 года назад +1

    Thank you for being an amazing teacher, i was running around like a headless chicken with hash functions, you explanation is simply amazing

  • @ozgeylmaz8685
    @ozgeylmaz8685 6 месяцев назад

    It is unbelievable that learning all of these take really short time , thank you so much for that much clear explanation 😊

  • @mtc2046
    @mtc2046 3 года назад +2

    finally i got the concept of hash table. thank you so much.

  • @pranavsai
    @pranavsai 2 года назад +3

    Great Video! Really helped me understand Hash Tables. After watching this video I made my own video on the topic. You just got a new sub! 😀😀😀

  • @yashpreetkaur2042
    @yashpreetkaur2042 2 года назад +10

    My university doesn't give me DSA as they said they doesn't have teaching staff(for electrical engineering students). But I really want to learn it and I'm doing the same because of you.
    Thanku so much sir for this playlist, it means a lot to students like me.
    And also shared this playlist to my friends as well😁

  • @myrusEW
    @myrusEW 11 месяцев назад +4

    I got a little upset at how long it took me to learn the other one, but I read online that a good timeline for the whole topic of DSA can take up to a year. That actually makes me feel better, since spending a few days on a topic doesn't seem like too slow now. Hopefully I can get through these videos and start on leetcode and have a job by the end of the year. I wasted a lot of time in my younger years, but I'm ready to get this journey fully started. Thank you for the videos!

    • @looklook6075
      @looklook6075 2 месяца назад

      how did your job application go after learning dsa?

  • @anastasiyauraleva8123
    @anastasiyauraleva8123 3 года назад +2

    Thank you so much for your data structures video explanations!! Your explanation is amazing and I understand the material a lot better!

    • @codebasics
      @codebasics  3 года назад +1

      I am happy this was helpful to you.

  • @wilmerzuna6288
    @wilmerzuna6288 4 года назад +1

    Thank you so much for making this video! It's very informative and very well-explained. Really appreciate the effort!

    • @codebasics
      @codebasics  4 года назад +2

      Glad it was helpful Wilmer :)

  • @swarajshinde3950
    @swarajshinde3950 3 года назад

    Loved your crisp and clear teaching

  • @michaelqu6732
    @michaelqu6732 2 года назад

    Thank you so much for your video!! Well explained and it really let me better understand the concepts.

  • @RaNd0MiZeD
    @RaNd0MiZeD Год назад

    Thanks.. I have designed my hashmap by getting idea from you and that's good enough for basic understanding... Thanks

  • @WeakCoder
    @WeakCoder 4 года назад

    Thanks a lot man ! I hope the best for your channel

  • @khajamohiddien9163
    @khajamohiddien9163 4 года назад +3

    Thank you very much It's really very informative : )).

  • @anmjubaer
    @anmjubaer 3 года назад

    Superb. Very clean and understandable.

  • @OM-el6oy
    @OM-el6oy 3 года назад

    You have been incredibly helpful to me and many others. Thank you!

  • @deepdive1585
    @deepdive1585 3 года назад

    Good vid. Thanks!
    I loved implementing methods for standard operator library! Nice job!

  • @AaronBrand
    @AaronBrand 4 года назад +7

    Great explanation of the difference between a dictionary and a list. I'm new to programming. I've only just begun using libraries in some practice problems and I've been struggling to understand why the time is O(1). I'm still not sure how this is the case, but I'm hoping it becomes clear after the next video and a little more practice!

    • @josiahdavid7735
      @josiahdavid7735 2 года назад +1

      You made this comment a year ago how are you faring now?

    • @ruubesh3678
      @ruubesh3678 2 года назад

      @@josiahdavid7735 he quit programming

    • @josiahdavid7735
      @josiahdavid7735 2 года назад

      @@ruubesh3678 Are you serious?

  • @hermanunspieters6969
    @hermanunspieters6969 2 года назад

    Top quality free education right here!!

  • @sujeetkumar.
    @sujeetkumar. 3 года назад

    Thank You so much Sir. You are awesome. I do all the exercises.

  • @FitnessChaos
    @FitnessChaos 4 года назад +1

    Easy to follow and good video

  • @Realfairytale1
    @Realfairytale1 3 года назад

    Thank you so much for the simplify the hash map and dictionary concept, please keep making videos.

    • @codebasics
      @codebasics  3 года назад

      I am happy this was helpful to you.

  • @shahgolsabeti9436
    @shahgolsabeti9436 Год назад

    This was a very helpful video for anyone struggling in DS

  • @muhammadumarsotvoldiev9555
    @muhammadumarsotvoldiev9555 Год назад

    Thank you very much, for your work!

  • @tupaiadhikari
    @tupaiadhikari 2 года назад

    Too Good. Last time I attended your Pandas Tutorial. Its been more than 4 years since. And I am reliving my Pandas Memories through this Videos. Thank You. You continue to inspire and improve life of mine. :-)

    • @codebasics
      @codebasics  2 года назад +1

      Glad to hear that Ritish and wish you a happy learning

  • @peterpete5214
    @peterpete5214 5 месяцев назад

    This was a great explanation, thank you very much now I understand

  • @djalminya1
    @djalminya1 3 года назад +1

    Question:
    So, if I have to different string keys that hash function on them return same value, how can we distinguish between them? lets say 'march 6' returns 9 as the example here shows and 'MQ' also returns 9, how can I differ?

  • @parvathirajan.n
    @parvathirajan.n 2 года назад

    Loved it. Thank you so much.

  • @Baljindersingh-nb9jy
    @Baljindersingh-nb9jy 2 года назад

    Thanks. Very Nice and elaborative video on this topic.

  • @TheAmazingGeniusMinecraft
    @TheAmazingGeniusMinecraft 2 года назад

    This is a very useful video, thank you alot!

  • @lisandroiaffar4501
    @lisandroiaffar4501 2 года назад

    Excelent!! Thank you for this tutorial!!

  • @SuperBhavanishankar
    @SuperBhavanishankar 3 года назад

    Hi sir. Thank You for amazing content! my que is: so (in other words) are you simply saying we can use *keywords* and *dictionary-style operations* if we opt for standard operators? or is there any other conventions also?

  • @houcemmadhkour6190
    @houcemmadhkour6190 9 месяцев назад

    Thank you codebasics!

  • @virinchimsk83
    @virinchimsk83 4 года назад

    very nice sir..i have seen many videos on hashing but none of them were not as good as this video for begginers

  • @akumasdeception
    @akumasdeception 3 года назад +1

    8:10 , why not use the hash function instead of ord(). Are there trade offs for using either?

  • @fahad_mihran2286
    @fahad_mihran2286 Год назад

    mind blowing! this man is amazing......

  • @typeer
    @typeer 3 года назад

    thanks very much for taking the time

  • @aandresriera7927
    @aandresriera7927 Год назад

    Great implementation, you got a subscriber !

  • @sukurcf
    @sukurcf 3 года назад

    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.

  • @elenakusevska6266
    @elenakusevska6266 2 года назад

    Great video. Great explanation.

  • @pushkarguptamusic
    @pushkarguptamusic Год назад

    thanks for the amazing content!

  • @ntumbaeliensampi6305
    @ntumbaeliensampi6305 2 года назад

    Very excellent explanation

  • @dantedt3931
    @dantedt3931 2 года назад

    Amazing content.Subscribed.

  • @402varun
    @402varun 2 года назад

    @codebasics so, the hashmap looks to be using dynamic arrays, instead of like what we saw with dequeue. Is there a way to build a hashmap using something like dequeue then?

  • @panashemureyi1599
    @panashemureyi1599 Год назад

    this chanel is massively underrated.

  • @awsomeslayer1
    @awsomeslayer1 3 года назад

    Thanks for such a comprehensive explanation of how a dictionary works in python. I do have one query - Why is it that only the final hash map shows in my output and all the other operations done prior to the last one do not? Only the del item array is shown in the output and not those when we added the item in final call. Is it something to do with mutable and immutable datatypes?

  • @josiahdavid7735
    @josiahdavid7735 2 года назад

    Great video that explains what hash tables do under the hood!

  • @amandaahringer7466
    @amandaahringer7466 2 года назад

    Well done!

  • @ParthivShah
    @ParthivShah Месяц назад +1

    Thank You Sir.

  • @alooooshm
    @alooooshm 4 года назад +14

    Thanks for your effort! May I ask about why and when would I, as a python programmer, need to use hash tables data structure while I already have the dictionary data structure already implemented for my in python?

    • @codebasics
      @codebasics  4 года назад +33

      This is just for your own understanding on how data structures work internally. This understanding will be helpful when you are writing bit python programs and you can choose your data structures such as dictionary , list wisely. You are right that you will be using already available data structures such as dictionary

    • @aishwarysaxena5301
      @aishwarysaxena5301 3 года назад +6

      another advantage of hash over dictionary is that you can make your storage according to your choice where as in dictionary if we want to store 1000 values the process is lengthy so i think hash is good

    • @bgmx74
      @bgmx74 2 года назад

      @@codebasics thank you, 2 years later this response is still helping people!

  • @SoumyaRanjanBeheraed21b064
    @SoumyaRanjanBeheraed21b064 16 дней назад

    Dear Sir, You explain really well. I request you to kindly upload more videos of DSA in python if possible.

  • @carefree_ladka
    @carefree_ladka 2 года назад

    Amazing explanation to be honest

  • @jenil16
    @jenil16 5 месяцев назад +1

    awesome sir

  • @hsoley
    @hsoley 3 года назад

    Dude, you are cool and your videos are awesome. Best wishes from NYC.

    • @codebasics
      @codebasics  3 года назад +2

      Thanks hamid. I live one hour away from nyc in NJ

  • @rutwikhiwalkar9583
    @rutwikhiwalkar9583 3 года назад +2

    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?

  • @saiyedali561
    @saiyedali561 4 года назад

    Great work

  • @artitiwari7687
    @artitiwari7687 3 года назад +1

    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?

  • @sainathvarma1359
    @sainathvarma1359 4 месяца назад

    i have a doubt, if i want to assign the keys 'tea' and 'ate' how will the ascii method work as they give me the same sum of ascii ?

  • @ViratKohli-jj3wj
    @ViratKohli-jj3wj 3 года назад +1

    Sir you are the BEST

  • @yummysoup
    @yummysoup 3 года назад

    Iam soo glad i found this channel.

  • @ramyavidiyala1293
    @ramyavidiyala1293 3 года назад

    Can you please share how the retrieving function is changing when the add function is changed to __getitem__?

  • @tassoskat8623
    @tassoskat8623 4 года назад +5

    Hello there. This is a great video and I really enjoy the series on data structures.
    I suppose that there are more sophisticated hash functions that deal with collisions for example key: "Dec 1" has the same hash value with key: "1 Dec".
    My question is what is the initial memory allocation of a dictionary d = {} (for example 100 slots?)
    and what happens when this memory allocation is exceeded. Is it handled like the list.
    Thank you in advance

    • @zack176
      @zack176 Год назад

      5:55 whats thata table called on the right

  • @sasaglamocak2846
    @sasaglamocak2846 5 месяцев назад

    Really nice video. TY! Could it happen that using your hash function (ascii code sum and modulo), we get the same modulo result for two different strings? E.g., string x results in 709 mod 100 = 9 and string y results in 809 mod 100 = 9? TY!

  • @likhithdasari7794
    @likhithdasari7794 2 года назад

    the best tutorial i have ever listen great explanation tqq sir

  • @TheGaneshshow
    @TheGaneshshow Год назад

    Thank you sir:)

  • @shivanisehdev8817
    @shivanisehdev8817 3 года назад

    very well explained...
    Thank you sir

  • @benjaminandoh8524
    @benjaminandoh8524 Год назад

    hello there, Great content. at 6:40 you said the size of the array is 10 for "march 6", but I think it should be 7 instead. I didn't get the same values as you got in the collision handling video. can you help me make that explanation of the length of the array out?

  • @cleanit1583
    @cleanit1583 3 года назад

    I have a technical interview on Python for the Data engineer position. I would grateful If you could give me an overview which topic should I cover or mainly focus on. Thanks in advance for your suggestion

  • @M.I.S
    @M.I.S 2 года назад

    thank You !

  • @tesfatsionshiferaw3474
    @tesfatsionshiferaw3474 3 года назад +1

    You're amazing dude!

    • @codebasics
      @codebasics  3 года назад +1

      Thanks for your kind words my friend

  • @RamkumarGopikrishnan
    @RamkumarGopikrishnan Год назад

    What should we do, when we dont know the self.MAX value, and it varies based on data in the given csv. How can we handle this?

  • @JollyBeJolly
    @JollyBeJolly 3 года назад

    This video is amazing thank you

  • @ulrikisdahl7555
    @ulrikisdahl7555 3 года назад

    Great!

  • @janerikludwighorvath7761
    @janerikludwighorvath7761 Год назад

    The joke at the end got me laughing out loud XD

    • @codebasics
      @codebasics  Год назад

      ha ha.. to be honest I am not good in cracking jokes but I am making an attempt to learn that skill 😊

  • @harishbhatt901
    @harishbhatt901 Год назад

    thank you sir

  • @EW-mb1ih
    @EW-mb1ih 3 года назад

    very nice explanation!

  • @chikachuku6289
    @chikachuku6289 3 года назад

    amazing video thank you so so much

    • @codebasics
      @codebasics  3 года назад +1

      I am glad you liked it

  • @san9870
    @san9870 Месяц назад

    superb vid!!

  • @priyanshupurohit5431
    @priyanshupurohit5431 Год назад

    Thankyou sir

  • @agnelamodia
    @agnelamodia 3 года назад

    very well explained.

  • @samsunny4092
    @samsunny4092 3 года назад

    this is gold

  • @clg68
    @clg68 3 года назад

    Excellent, good sir

  • @RevvedUpGaming2024
    @RevvedUpGaming2024 6 дней назад

    But when I do march 9 and december 9 it got the same value, but i didn't add december 9?

  • @aneesa7207
    @aneesa7207 2 месяца назад

    thankyou sir

  • @pratikdokhe7198
    @pratikdokhe7198 2 года назад

    if we insert as 'March 1' and '1 march' both will have same hash value so it will overwrite the previous value and we will lose the prev value.
    Anyone knows how to overcome this..??
    Or is thr any solution for this...??

  • @danieldweebler3392
    @danieldweebler3392 4 года назад +3

    I'm confused, aren't dictionaries in python hash tables? Plus dictionaries will do the hashing and will deal with collisions. Why would you want to do this?

    • @codebasics
      @codebasics  4 года назад +9

      Yes they are hashtables. I did this so that you can an understanding of inner workings of it.

    • @ArjunRajaS
      @ArjunRajaS 2 года назад

      Sometimes interviewers would not be happy with using dictionaries directly

  • @kunalkadian6792
    @kunalkadian6792 3 года назад

    Great work sir

    • @codebasics
      @codebasics  3 года назад +1

      Glad it was helpful!

    • @kunalkadian6792
      @kunalkadian6792 3 года назад

      @@codebasics sir I want to become data scientist after dropping out for 4 years after college do I have any chance of getting a job

  • @fahad_mihran2286
    @fahad_mihran2286 Год назад

    i paid 30,000 for a course. i didn't understand what the guy was trying to tell. i saw this video and everything is clear. love you sir.

  • @hellloooworld1124
    @hellloooworld1124 3 года назад

    Cool way of dictionary

  • @hahahofhahaland3687
    @hahahofhahaland3687 3 года назад

    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?

    • @codebasics
      @codebasics  3 года назад

      Good question, collision handling techniques are discussed in part 2. Please watch it to get answer of your question

  • @madmannedme
    @madmannedme 4 года назад

    hey...
    how are you using __setitem__, __getitem__ and all??
    u didn't even import operators library

  • @miglioredroid9446
    @miglioredroid9446 Год назад

    Siempre😊 un turco enseña excelente programación

  • @ashish14Pradhan
    @ashish14Pradhan 2 года назад

    I would like to suggest a concept over here, which was wrong in the video if we use the map in C++ that means it is an ordered map which implements red-black tree hence the order becomes O(log(n)) for searching and other operations thus it is not the hash map and hash map for C++ is unordered_map.