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

Поділитися
Вставка
  • Опубліковано 21 лип 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...

КОМЕНТАРІ • 226

  • @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 роки тому +63

    "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 11 місяців тому +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

  • @codebasics
    @codebasics  4 роки тому +17

    Part 2: ua-cam.com/video/54iv1si4YCM/v-deo.html

  • @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!

  • @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. ❤💖

  • @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

  • @neilgibson88
    @neilgibson88 3 роки тому +7

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

  • @ozgeylmaz8685
    @ozgeylmaz8685 6 місяців тому

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

  • @njoy2075
    @njoy2075 4 роки тому +16

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

  • @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?

  • @mtc2046
    @mtc2046 3 роки тому +2

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

  • @RaNd0MiZeD
    @RaNd0MiZeD Рік тому

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

  • @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! 😀😀😀

  • @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

  • @swarajshinde3950
    @swarajshinde3950 3 роки тому

    Loved your crisp and clear teaching

  • @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.

  • @shahgolsabeti9436
    @shahgolsabeti9436 Рік тому

    This was a very helpful video for anyone struggling in DS

  • @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.

  • @aandresriera7927
    @aandresriera7927 Рік тому

    Great implementation, you got a subscriber !

  • @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 :)

  • @SoumyaRanjanBeheraed21b064
    @SoumyaRanjanBeheraed21b064 8 днів тому

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

  • @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

  • @michaelqu6732
    @michaelqu6732 2 роки тому

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

  • @hermanunspieters6969
    @hermanunspieters6969 2 роки тому

    Top quality free education right here!!

  • @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?

  • @anmjubaer
    @anmjubaer 3 роки тому

    Superb. Very clean and understandable.

  • @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.

  • @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?

  • @deepdive1585
    @deepdive1585 3 роки тому

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

  • @dantedt3931
    @dantedt3931 2 роки тому

    Amazing content.Subscribed.

  • @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?

  • @FitnessChaos
    @FitnessChaos 4 роки тому +1

    Easy to follow and good video

  • @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?

  • @Baljindersingh-nb9jy
    @Baljindersingh-nb9jy 2 роки тому

    Thanks. Very Nice and elaborative video on this topic.

  • @khajamohiddien9163
    @khajamohiddien9163 4 роки тому +3

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

  • @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?

  • @ntumbaeliensampi6305
    @ntumbaeliensampi6305 2 роки тому

    Very excellent explanation

  • @WeakCoder
    @WeakCoder 4 роки тому

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

  • @OM-el6oy
    @OM-el6oy 3 роки тому

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

  • @akumasdeception
    @akumasdeception 3 роки тому +1

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

  • @lisandroiaffar4501
    @lisandroiaffar4501 2 роки тому

    Excelent!! Thank you for this tutorial!!

  • @peterpete5214
    @peterpete5214 5 місяців тому

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

  • @panashemureyi1599
    @panashemureyi1599 Рік тому

    this chanel is massively underrated.

  • @ramyavidiyala1293
    @ramyavidiyala1293 3 роки тому

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

  • @muhammadumarsotvoldiev9555
    @muhammadumarsotvoldiev9555 Рік тому

    Thank you very much, for your work!

  • @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

  • @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 ?

  • @sujeetkumar.
    @sujeetkumar. 3 роки тому

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

  • @amandaahringer7466
    @amandaahringer7466 2 роки тому

    Well done!

  • @houcemmadhkour6190
    @houcemmadhkour6190 9 місяців тому

    Thank you codebasics!

  • @fahad_mihran2286
    @fahad_mihran2286 Рік тому

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

  • @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?

  • @josiahdavid7735
    @josiahdavid7735 2 роки тому

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

  • @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.

  • @parvathirajan.n
    @parvathirajan.n 2 роки тому

    Loved it. Thank you so much.

  • @elenakusevska6266
    @elenakusevska6266 2 роки тому

    Great video. Great explanation.

  • @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?

  • @jenil16
    @jenil16 4 місяці тому +1

    awesome sir

  • @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?

  • @pushkarguptamusic
    @pushkarguptamusic 11 місяців тому

    thanks for the amazing content!

  • @typeer
    @typeer 3 роки тому

    thanks very much for taking the time

  • @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!

  • @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?

  • @TheAmazingGeniusMinecraft
    @TheAmazingGeniusMinecraft 2 роки тому

    This is a very useful video, thank you alot!

  • @carefree_ladka
    @carefree_ladka 2 роки тому

    Amazing explanation to be honest

  • @saiyedali561
    @saiyedali561 4 роки тому

    Great work

  • @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...??

  • @ParthivShah
    @ParthivShah Місяць тому +1

    Thank You Sir.

  • @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

  • @likhithdasari7794
    @likhithdasari7794 2 роки тому

    the best tutorial i have ever listen great explanation tqq 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!

  • @san9870
    @san9870 Місяць тому

    superb vid!!

  • @yummysoup
    @yummysoup 3 роки тому

    Iam soo glad i found this channel.

  • @anonymoushuman8153
    @anonymoushuman8153 Рік тому

    if i skip self.arr step, i still get the same answer, so why should id use self.arr statement?

  • @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

  • @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.

  • @TheGaneshshow
    @TheGaneshshow Рік тому

    Thank you sir:)

  • @shivanisehdev8817
    @shivanisehdev8817 3 роки тому

    very well explained...
    Thank you sir

  • @madmannedme
    @madmannedme 3 роки тому

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

  • @Jay_OwO
    @Jay_OwO 2 роки тому

    8:25 : what "h % 100" does is divide h by 100 and returning the remainder:
    "march 9" in ascii is 609 so "609 / 100 = 6.09", the remainder is 09, so the result shown is 9

  • @ViratKohli-jj3wj
    @ViratKohli-jj3wj 3 роки тому +1

    Sir you are the BEST

  • @sezermezgil9304
    @sezermezgil9304 3 роки тому

    Hi How do i download the files for practices ?

  • @user-vc9xz2sl8c
    @user-vc9xz2sl8c 11 місяців тому

    can I use pycharm instead of jupyter?

  • @DiasDenny
    @DiasDenny 4 роки тому

    This dictionary is not showing key error likewise in python

  • @md.ashrafulislam5926
    @md.ashrafulislam5926 2 роки тому

    how size of array can be 10. I can't understand(6:24)

  • @agnelamodia
    @agnelamodia 3 роки тому

    very well explained.

  • @nerdscientist7427
    @nerdscientist7427 2 роки тому

    hello sir, is this full course for dsa with python

  • @EW-mb1ih
    @EW-mb1ih 3 роки тому

    very nice explanation!

  • @priyanshupurohit5431
    @priyanshupurohit5431 Рік тому

    Thankyou sir

  • @harishbhatt901
    @harishbhatt901 Рік тому

    thank you sir

  • @meralmaradia4774
    @meralmaradia4774 2 роки тому

    Hello Sir, can you please create a video developing of project using only DSA ?

  • @M.I.S
    @M.I.S 2 роки тому

    thank You !

  • @aswath8265
    @aswath8265 3 роки тому

    If hash value of 2 name is same then one exchanges other know sir

  • @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 😊

  • @koushik7604
    @koushik7604 Рік тому

    Now I have really understood how the dictionary works in Python... But what will happen when you will try to add more element than 100 (self. MAX)?

  • @vinayakshukla2879
    @vinayakshukla2879 4 роки тому

    what if i want to check whether if key exist in dictionary or not then i have to use in operator and it will going to take o(n) time so how to overcome from it

    • @codebasics
      @codebasics  4 роки тому +1

      in operation for a given key will not take o(n). Look up in a hashmap by a key is O(1) on average.

  • @ulrikisdahl7555
    @ulrikisdahl7555 3 роки тому

    Great!