Learn Hash Tables in 13 minutes

แชร์
ฝัง
  • เผยแพร่เมื่อ 21 ก.ย. 2024
  • Hash Table tutorial example explained
    #Hash #Table #Hashtable
    // Hashtable = A data structure that stores unique keys to values
    Each key/value pair is known as an Entry
    FAST insertion, look up, deletion of key/value pairs
    Not ideal for small data sets, great with large data sets

ความคิดเห็น • 175

  • @BroCodez
    @BroCodez  2 ปีที่แล้ว +135

    import java.util.*;
    public class Main{

    public static void main(String args[]) {
    // Hashtable = A data structure that stores unique keys to values ex.
    // Each key/value pair is known as an Entry
    // FAST insertion, look up, deletion of key/value pairs
    // Not ideal for small data sets, great with large data sets

    // hashing = Takes a key and computes an integer (formula will vary based on key & data type)
    // In a Hashtable, we use the hash % capacity to calculate an index number

    // key.hashCode() % capacity = index

    // bucket = an indexed storage location for one or more Entries
    // can store multiple Entries in case of a collision (linked similarly a LinkedList)

    // collision = hash function generates the same index for more than one key
    // less collisions = more efficiency

    // Runtime complexity: Best Case O(1)
    // Worst Case O(n)
    Hashtable table = new Hashtable(10);

    table.put(100, "Spongebob");
    table.put(123, "Patrick");
    table.put(321, "Sandy");
    table.put(555, "Squidward");
    table.put(777, "Gary");

    for(Integer key : table.keySet()) {
    System.out.println(key.hashCode() % 10 + "\t" + key + "\t" + table.get(key));
    }
    }
    }

    • @ihateorangecat
      @ihateorangecat 2 ปีที่แล้ว

      more python tutorials please bro🙏

    • @ashutoshsoni9723
      @ashutoshsoni9723 2 ปีที่แล้ว

      Bro can you please make a video on Library Management System in JAVA. It's my request please!

    • @masternobody1896
      @masternobody1896 2 ปีที่แล้ว

      nice

    • @joyceasante8292
      @joyceasante8292 ปีที่แล้ว

      import java.util.*;
      public class Main
      {
      public static void main(String[] args) {
      Hashtabletable = new Hashtable(10);
      table.put(254,"Irene");
      table.put(802,"Derrek");
      table.put(671,"Alonso");
      table.put(545,"Veronica");
      //System.out.println(table.get(545));
      //table.remove(671);
      for(Integer key : table.keySet()){
      //System.out.println(key + "\t" + table.get(key));
      System.out.println(key.hashCode() % 10 + "\t" + key + "\t" + table.get(key));
      }
      }
      }
      _____________________________________________
      import java.util.*;
      public class Main
      {
      public static void main(String[] args) {
      Hashtabletable = new Hashtable(10);
      table.put("254","Irene");
      table.put("802","Derrek");
      table.put("671","Alonso");
      table.put("545","Veronica");

      //table.remove(671);
      for(String key : table.keySet()){
      //System.out.println(key.hashCode() + "\t" + key + "\t" + table.get(key));
      //System.out.println(key.hashCode() % 10 + "\t" + key + "\t" + table.get(key));
      //System.out.println(key.hashCode() % 11 + "\t" + key + "\t" + table.get(key));
      System.out.println(key.hashCode() % 21 + "\t" + key + "\t" + table.get(key));
      }
      }
      }

    • @pavanimaddala8060
      @pavanimaddala8060 ปีที่แล้ว

      Can you explain how to create hash table in mysql

  • @Aussiesnrg
    @Aussiesnrg 7 หลายเดือนก่อน +45

    Was a programmer on a statewide court system back in the late 80's that needed a surname search to return a full page of results in less than a second. We used hashing tables and progressive searches to keep the speed amazingly fast. I think we had it down to about 0.2 of a second.
    They are fantastic with really large collections of data that needs searching.

  • @marius.y6360
    @marius.y6360 2 ปีที่แล้ว +114

    Hey Bro, I just wanna thank you for teaching me all this stuff. 7 months ago I was almost nowhere not even knowing how to write a main method in Java but now I'm programming my own graphics library. You're truly a legend😎

    • @blu5175
      @blu5175 2 ปีที่แล้ว

      whats a graphic library im new sorry

    • @intifadayuri
      @intifadayuri ปีที่แล้ว +5

      @@blu5175 libraries in java are a series of already build methods that you can use. For example, whenever you want to write something in the java console you need to import the java.util.Scanner library.
      My guess is that this guy is talking about a library to build a 3d engine with java

    • @blu5175
      @blu5175 ปีที่แล้ว +7

      @@intifadayuri Yea I learnt this by now it's been 11 months! Haha but still thank you very much?

    • @AMZ_official
      @AMZ_official 11 หลายเดือนก่อน

      @@blu5175 It's been 11 months again! did you complete it? What else have you achieved in your career? Asking for just motivation

    • @RonnieBanerjee007
      @RonnieBanerjee007 4 หลายเดือนก่อน +3

      ​@@intifadayuri well, you tried to help, that's what counts ❤

  • @dmitriivlasov3728
    @dmitriivlasov3728 2 ปีที่แล้ว +31

    Bro, We just started going through Hash Tables in our CompSci class and now you release a video. Thank you!

  • @WorkSmarter__
    @WorkSmarter__ 2 ปีที่แล้ว +17

    Level of teaching of Bro is just on another level👍

  • @thomashansknecht1898
    @thomashansknecht1898 ปีที่แล้ว +9

    I am surprised my computer science curriculum barely even mentioned hash tables. They have been such a game changer to me at work as a software engineer. Way faster and easier than using an array and nested loops.

    • @randomrun1
      @randomrun1 10 หลายเดือนก่อน

      That's interesting, I'm about to start my BSCS and I'm pregaming with the popular Java MOOC. It has an explanation of how to use hash tables in the 8th week and how to make them from scratch in the 12th week. Glad I got the info there if it's not going to be in my curriculum.

  • @clashclans9783
    @clashclans9783 9 หลายเดือนก่อน +2

    that actually makes so much sense!! was looking at the profssors notes and watching his lectures and not understanding it one single bit!!!! long live the BRO!!!!

  • @VERY_TALL_MAN
    @VERY_TALL_MAN 2 ปีที่แล้ว +69

    Wow, this is a really good introduction to hash tables!

    • @BroCodez
      @BroCodez  2 ปีที่แล้ว +14

      thanks Grayson!

    • @deepakr1945
      @deepakr1945 2 ปีที่แล้ว +2

      @@BroCodez it bad

    • @elielvieira3041
      @elielvieira3041 ปีที่แล้ว +6

      @@deepakr1945 nah

    • @windigo77
      @windigo77 10 หลายเดือนก่อน

      It's too bad it violates the ADA with its use of camelCase for method names, and is therefore an illegal language to use in the workplace

  • @crossfadez5521
    @crossfadez5521 ปีที่แล้ว +5

    This was a very insightful video, thanks a lot. Although I really wished you also went over how to treat a bucket as a linked list and iterate through it to find the key you're looking for.

  • @PratikThisSide
    @PratikThisSide 2 ปีที่แล้ว +3

    Simply, subtly & nearly explained Bro Sir 👌🏼
    #KeelItUp ✌🏼 #LoveFromINDIA🇮🇳

  • @dbvs007
    @dbvs007 2 ปีที่แล้ว +2

    Thank you, I have been having questions on HashTable and wanted to understand hashCode, excellent explanation, keep doing more videos.

  • @hwstar9416
    @hwstar9416 11 หลายเดือนก่อน +5

    Things to note:
    If you have collisions the best course of action is to change your hash function. In your example, a good hash function would be taking the ascii code of the rightmost number and subtracting 48, that way you'd have 0 collisions and don't need to do % anymore.
    Another thing, if your table size is a power of 2 you don't have to do % anymore, you can instead do bitwise and with table size.

    • @mikoalt
      @mikoalt 9 หลายเดือนก่อน

      Can you explain the bitwise with table size if the power is 2?

    • @ThomasEdits
      @ThomasEdits 9 หลายเดือนก่อน

      I just found out about hashtables so I would appreciate some input:
      If you are using a hashtable for storing dynamic data, how would you know what hash function always guarantees no collisions?

    • @hwstar9416
      @hwstar9416 9 หลายเดือนก่อน +1

      @@ThomasEdits your data is never truly random. You can always make your hash function avoid collisions (not always completely) by analyzing your data and coming up with a good hash

  • @confused6526
    @confused6526 7 หลายเดือนก่อน

    Oh My Goodness... The best video on HashMap data structure. You're the man! 👍

  • @patriciale6647
    @patriciale6647 5 หลายเดือนก่อน

    I didn't pay attention during lecture and I have a quiz tomorrow, so this is a lifesaver!

  • @mjjrr1331
    @mjjrr1331 4 หลายเดือนก่อน +2

    Simple and understandable. Thank you so much for this tutorial!

  • @hazmi96
    @hazmi96 2 ปีที่แล้ว +4

    Thanks! love your videos!

  • @ruleoflawedutainment
    @ruleoflawedutainment 2 ปีที่แล้ว +2

    I studied this last term but didn't understand what I do now. Thank you.

  • @oogshow2809
    @oogshow2809 2 ปีที่แล้ว +1

    It’s beautiful lecture I like this hash , I’m always favourite your lecture bro due to your best explanation , keep going bro

  • @robertedwards4401
    @robertedwards4401 หลายเดือนก่อน

    Great video, thank you

  • @umut_satir
    @umut_satir 3 หลายเดือนก่อน

    i didn't understand the other videos but you clearly explained how it works, thanks for the content

  • @collectick
    @collectick 3 หลายเดือนก่อน

    Better explanation than my computer science teacher, and my native language isn't event english! :)

  • @aryankumar313
    @aryankumar313 ปีที่แล้ว

    Brooo!!!!....you just explain so good!....got it just by watching it once!

  • @nischalofchrist
    @nischalofchrist ปีที่แล้ว

    Bro, you Rock. Best and simple explanation of Hash tables. Thanks

  • @ukaszkiepas57
    @ukaszkiepas57 7 หลายเดือนก่อน

    thank you bro. Student from Poland :>

  • @daviduntalan
    @daviduntalan ปีที่แล้ว

    thank you for this tutorial, now i can finally understand the HashTable.

  • @rmsoft
    @rmsoft 7 หลายเดือนก่อน

    Really good, no babbling, just information.

  • @ferencbesenyei6713
    @ferencbesenyei6713 2 หลายเดือนก่อน

    Excellent!

  • @randomrun1
    @randomrun1 10 หลายเดือนก่อน

    This is a great video, thank you. It's much clearer than my course material.

  • @joeyfarrell4399
    @joeyfarrell4399 6 หลายเดือนก่อน

    I love this channel so, so much

  • @nageshmh
    @nageshmh 3 หลายเดือนก่อน

    Awesome

  • @stephanieezat-panah7750
    @stephanieezat-panah7750 2 ปีที่แล้ว +1

    As always, an excellent presentation. thank you

  • @acatisfinetoo3018
    @acatisfinetoo3018 9 หลายเดือนก่อน

    Hash table is my favoriate data structure😉

  • @alexh3143
    @alexh3143 2 หลายเดือนก่อน

    the only video I found that has explained hash tables clearly

  • @musicHighspeed
    @musicHighspeed 6 หลายเดือนก่อน

    I love youuu🥺🥺
    Respectfully BUT sincerely
    Many thanks!

  • @stillpickinganame5350
    @stillpickinganame5350 2 หลายเดือนก่อน

    Very good, thank you!

  • @robdimmitt3204
    @robdimmitt3204 ปีที่แล้ว +1

    Unbelievably good video

  • @eugenezuev7349
    @eugenezuev7349 21 วันที่ผ่านมา

    sweeet

  • @patahgaming
    @patahgaming 10 หลายเดือนก่อน

    I learn how to use hash table without tutorial now :)

  • @mistersir3185
    @mistersir3185 ปีที่แล้ว +1

    good surface level info

  • @Code_JAVA268
    @Code_JAVA268 5 หลายเดือนก่อน

    tooo cool man

  • @jordimorenosanchez584
    @jordimorenosanchez584 ปีที่แล้ว

    I thought I understood what a hash table was till I saw this video 🙏

  • @zeeg1529
    @zeeg1529 6 หลายเดือนก่อน

    top quality content. great job, Bro!

  • @P0K0
    @P0K0 ปีที่แล้ว

    The best video I've seen today ❤

  • @Seth_Sun
    @Seth_Sun 2 ปีที่แล้ว +1

    In cars stuff we have Chrisfix in computer stuff we have my bro right here.

  • @recipeFor
    @recipeFor 2 ปีที่แล้ว

    Thanks a lot for providing a valuable video.

  • @callmesuraj4257
    @callmesuraj4257 2 ปีที่แล้ว +1

    Bro 🤩 Tq 4 your Quality coding Video.
    & Now i am busy with your python 🐍course.
    Tnx again ☺️. Bro ✌️🎈✌️

  • @abdalwahedhajomar3898
    @abdalwahedhajomar3898 ปีที่แล้ว +2

    This video is amazingly helpful

  • @ChristianRodriguez-tm3jg
    @ChristianRodriguez-tm3jg ปีที่แล้ว

    thanks bro... greetings from Ecuador

  • @TheFlexath
    @TheFlexath 7 หลายเดือนก่อน

    thank you sir , best explanation.

  • @HarryInShape
    @HarryInShape 4 หลายเดือนก่อน

    I love you Bro

  • @joseluizdurigon8893
    @joseluizdurigon8893 ปีที่แล้ว +1

    Ok, but the bucket we're talking about is a memory address? I mean, if we have a collision, we must create a linked list. Fine with that I get it, but that linked list will be stored in the same memory address? I don't think I'm rationalizing right. The linked list will be stored like a vector and the data that has a collision will have a pointer to that new node right? I'm sorry if I sound a little bit confusing but that's what I've figured out

    • @kylebelle246
      @kylebelle246 4 หลายเดือนก่อน

      What if it was always a linked list? even if there are no collisions and the linked list only contains one node. I think that'd make more sense

  • @Mohamed-uf5jh
    @Mohamed-uf5jh ปีที่แล้ว

    Good explanation . Liked it a lot !

  • @victors8718
    @victors8718 8 หลายเดือนก่อน

    Bro is an absolute legend

  • @tavwalt1973
    @tavwalt1973 ปีที่แล้ว

    Wow thank you so much, this was super clear!!!!

  • @hypnos9336
    @hypnos9336 5 หลายเดือนก่อน

    helpful, thank you

  • @WizardMoDz
    @WizardMoDz 21 วันที่ผ่านมา

    🙌

  • @mohitjain957
    @mohitjain957 2 ปีที่แล้ว

    bro you are insane
    Thanks sir
    I really appreciate

  • @akmalbukhariev7932
    @akmalbukhariev7932 5 หลายเดือนก่อน

    Thank you so much sir.

  • @ldpenrose
    @ldpenrose 2 ปีที่แล้ว

    The BRO is BACK!

  • @khushalsinghsaini805
    @khushalsinghsaini805 ปีที่แล้ว

    how we can deal with HashTable of Classes? Like in place of int and string key it is some sort of class. Like Hashtable;

  • @mugosimon717
    @mugosimon717 ปีที่แล้ว

    you are the best

  • @skillR-243
    @skillR-243 2 ปีที่แล้ว +1

    Thanks for this videos Bro!

  • @ethio15code
    @ethio15code 6 หลายเดือนก่อน

    Nice explanation 👍

  • @StephanHaloftis
    @StephanHaloftis ปีที่แล้ว +2

    Is it possible to design the table to have a dynamic capacity that can be adjusted if there are collisions?

    • @kylebelle246
      @kylebelle246 4 หลายเดือนก่อน

      i could see this taking more work and end up being slower than just appending to the linked list, since you the existing element now also need to be moved since their table index may no longer be the same give the remainder will likely be different. i would say just make sure the hashtable is sized appropriately and at that point you've done the best you could

  • @coder4937
    @coder4937 2 ปีที่แล้ว

    Good work👍👍👍👍

  • @KiranNaragam
    @KiranNaragam 2 หลายเดือนก่อน

    GOAT Video of HashTable

  • @wrizu
    @wrizu 2 หลายเดือนก่อน

    how do you access a vlue from a bucket it only shows the head (first) value.

  • @lucacodastefano2409
    @lucacodastefano2409 2 ปีที่แล้ว

    Very nice lesson, like every other!

  • @flammabletfm3405
    @flammabletfm3405 2 ปีที่แล้ว

    Wow! Nice.

  • @kosolomon123
    @kosolomon123 2 ปีที่แล้ว

    good quality content!

  • @trevorphilipsindustries1046
    @trevorphilipsindustries1046 ปีที่แล้ว

    I'm wondering if these hashcodes been written incorrectly here 3:49
    Because the hashcode of String "100" would be 47155, not 48625.
    and here is why:
    Initialize hash to 0: hash = 0.
    Multiply hash by 31 and add the numeric value of the first character '1': hash = (0 * 31) + 49 = 49.
    Multiply hash by 31 and add the numeric value of the second character '0': hash = (49 * 31) + 48 = 1517.
    Multiply hash by 31 and add the numeric value of the third character '0': hash = (1517 * 31) + 48 = 47155.
    so, am I right, these numbers in the example's hashcode are just random numbers and have nothing to do with the righ hashcodes?

    • @SaiMoen
      @SaiMoen ปีที่แล้ว

      10:15

  • @emiralpkilic5669
    @emiralpkilic5669 11 หลายเดือนก่อน

    Eyyo Brooooo you are a legend!!!

  • @punzalanchristine2442
    @punzalanchristine2442 8 หลายเดือนก่อน

    what do you call when u give that type of solution in collision, is it open hashing or not?

  • @facuz4170
    @facuz4170 ปีที่แล้ว

    Nice video!

  • @alpeshamriwala1740
    @alpeshamriwala1740 2 ปีที่แล้ว +2

    Thanks bro 😭

  • @joseoterol
    @joseoterol ปีที่แล้ว

    I love that man. Thanks mate

  • @touzaikokon
    @touzaikokon ปีที่แล้ว

    thanks bro

  • @xxmsdxx
    @xxmsdxx 2 ปีที่แล้ว

    Keep going ❤

  • @gerxisander5294
    @gerxisander5294 2 ปีที่แล้ว

    very nice tutorial. BIG LIKE

  • @KaptainLuis
    @KaptainLuis 2 หลายเดือนก่อน

    thank you soooo much!!!

  • @justinbanza4079
    @justinbanza4079 2 ปีที่แล้ว

    Thank you for this video

  • @mostafayounes9490
    @mostafayounes9490 2 หลายเดือนก่อน

    Thank you ❤

  • @ztipster
    @ztipster 5 หลายเดือนก่อน

    Does google uses hash tables to display instant results ?

  • @hermansiisengbae
    @hermansiisengbae 2 ปีที่แล้ว

    Wow 👍👍

  • @gksw_g1437
    @gksw_g1437 2 ปีที่แล้ว +1

    thanks!

  • @katendetimothy6542
    @katendetimothy6542 2 ปีที่แล้ว

    Bro thx for the free videos. How can I apply this topic in real life maybe in GUI?

  • @victorrezende6002
    @victorrezende6002 11 หลายเดือนก่อน

    Nice class

  • @issac17
    @issac17 2 ปีที่แล้ว +1

    Thanks man I really appreciate ❤️

    • @BroCodez
      @BroCodez  2 ปีที่แล้ว +1

      anytime! Thanks for commenting

    • @issac17
      @issac17 2 ปีที่แล้ว

      Your videos are really helpful...you deserved it❤️

  • @MrLoser-ks2xn
    @MrLoser-ks2xn ปีที่แล้ว

    Thanks!

  • @bluekrazykris
    @bluekrazykris 2 ปีที่แล้ว +2

    What's the difference between Hash tables and hash maps?

    • @migelangelcarrillo1710
      @migelangelcarrillo1710 ปีที่แล้ว +3

      @@dispatch-indirect9206 he/she asked for the difference, not your opinion on the subject

  • @SlashKilll
    @SlashKilll ปีที่แล้ว

    THANK YOU YOU SAVED ME

  • @ToanPham-wr7xe
    @ToanPham-wr7xe 7 หลายเดือนก่อน

    😮

  • @visitor404
    @visitor404 ปีที่แล้ว

    Bro 🤜🤛

  • @alanfrost2973
    @alanfrost2973 2 ปีที่แล้ว

    Another day Thank you so much if you ever have membership for no reason ill try to join to money you deserve it

  • @thedojoclub
    @thedojoclub ปีที่แล้ว

    thank god for Bro!

  • @Heyleang
    @Heyleang 3 หลายเดือนก่อน

    Thank man

  • @adheesh2secondsago630
    @adheesh2secondsago630 2 ปีที่แล้ว

    Nice👍

  • @TylerBriggs-m2y
    @TylerBriggs-m2y 10 หลายเดือนก่อน

    Well done, TY!

  • @maratmkhitaryan9723
    @maratmkhitaryan9723 9 หลายเดือนก่อน

    I remember doing hash(string)%16777216 to generate hex color based on a string

  • @gamermachine4048
    @gamermachine4048 2 ปีที่แล้ว

    Nice, can you make a video on suppliers and consumers next?