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);
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.
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 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
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.
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.
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!!!!
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.
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.
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?
@@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
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
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
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?
Back in Image/3000 days(70s, 80s, 90s, early 2000s), master tables(manual and automatic) were hashed with collisions resolved exactly as in this video. The rule was to create such tables with a capacity of a prime number. If you need a million rows in your table, set the capacity to the next prime number. it wasn't enforced by the database, actually, but later, utilities were created to help in resizing tables and these would actually tell you what your capacity should be based on what you requested.
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));
}
}
}
more python tutorials please bro🙏
Bro can you please make a video on Library Management System in JAVA. It's my request please!
nice
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));
}
}
}
Can you explain how to create hash table in mysql
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.
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😎
whats a graphic library im new sorry
@@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
@@intifadayuri Yea I learnt this by now it's been 11 months! Haha but still thank you very much?
@@blu5175 It's been 11 months again! did you complete it? What else have you achieved in your career? Asking for just motivation
@@intifadayuri well, you tried to help, that's what counts ❤
Bro, We just started going through Hash Tables in our CompSci class and now you release a video. Thank you!
Level of teaching of Bro is just on another level👍
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.
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.
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!!!!
Wow, this is a really good introduction to hash tables!
thanks Grayson!
@@BroCodez it bad
@@deepakr1945 nah
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
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.
Your videos are awesome, far better and easier to understand than my useless, confusing lectures, thanks!
Oh My Goodness... The best video on HashMap data structure. You're the man! 👍
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.
Can you explain the bitwise with table size if the power is 2?
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?
@@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
Simply, subtly & nearly explained Bro Sir 👌🏼
#KeelItUp ✌🏼 #LoveFromINDIA🇮🇳
Thank you, I have been having questions on HashTable and wanted to understand hashCode, excellent explanation, keep doing more videos.
I didn't pay attention during lecture and I have a quiz tomorrow, so this is a lifesaver!
Watched 3 vids on this. Yours was best.
Unbelievably good video
Brooo!!!!....you just explain so good!....got it just by watching it once!
I studied this last term but didn't understand what I do now. Thank you.
Really good, no babbling, just information.
i didn't understand the other videos but you clearly explained how it works, thanks for the content
bro save my lots of time to learn this all by reading some article or docs , amazing video thank you sir
good surface level info
thank you for this tutorial, now i can finally understand the HashTable.
I love this channel so, so much
Hash table is my favoriate data structure😉
Bro, you Rock. Best and simple explanation of Hash tables. Thanks
Thanks! love your videos!
It’s beautiful lecture I like this hash , I’m always favourite your lecture bro due to your best explanation , keep going bro
Simple and understandable. Thank you so much for this tutorial!
thank you sir , best explanation.
This video is amazingly helpful
Great video, thank you
As always, an excellent presentation. thank you
This is a great video, thank you. It's much clearer than my course material.
Thank you for this video
Nice explanation 👍
I love you Bro
you are the best
Better explanation than my computer science teacher, and my native language isn't event english! :)
the only video I found that has explained hash tables clearly
I thought I understood what a hash table was till I saw this video 🙏
Thanks a lot for providing a valuable video.
Awesome
Excellent!
how we can deal with HashTable of Classes? Like in place of int and string key it is some sort of class. Like Hashtable;
The BRO is BACK!
Nice class
Wow! Nice.
thanks bro... greetings from Ecuador
Bro is an absolute legend
good quality content!
The best video I've seen today ❤
top quality content. great job, Bro!
Thank you so much sir.
helpful, thank you
Good explanation . Liked it a lot !
bro you are insane
Thanks sir
I really appreciate
Does google uses hash tables to display instant results ?
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
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
sweeet
Nice video!
Wow 👍👍
Wow thank you so much, this was super clear!!!!
Good work👍👍👍👍
Very good, thank you!
what do you call when u give that type of solution in collision, is it open hashing or not?
thank you bro. Student from Poland :>
GOAT Video of HashTable
Very nice lesson, like every other!
I love youuu🥺🥺
Respectfully BUT sincerely
Many thanks!
Nice👍
Thanks
Is it possible to design the table to have a dynamic capacity that can be adjusted if there are collisions?
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
Sir , please provide use app development course , It's a very helpful .
I learn how to use hash table without tutorial now :)
Bro 🤜🤛
Bro 🤩 Tq 4 your Quality coding Video.
& Now i am busy with your python 🐍course.
Tnx again ☺️. Bro ✌️🎈✌️
I love that man. Thanks mate
What's the difference between Hash tables and hash maps?
@@dispatch-indirect9206 he/she asked for the difference, not your opinion on the subject
What’s the difference between hashtable and hashmaps?
🙌
Could you go over the A star algorithm next pls
Bro thx for the free videos. How can I apply this topic in real life maybe in GUI?
Thank you ❤
how do you access a vlue from a bucket it only shows the head (first) value.
Thanks for this videos Bro!
THANK YOU YOU SAVED ME
Well done, TY!
tooo cool man
very nice tutorial. BIG LIKE
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?
10:15
Keep going ❤
In cars stuff we have Chrisfix in computer stuff we have my bro right here.
Can you find the values in your hash table from its address?
thanks bro
Thanks man I really appreciate ❤️
anytime! Thanks for commenting
Your videos are really helpful...you deserved it❤️
I was thinking the table size should be a prime to reduce collisions, no? Should have tried 13 first.
Back in Image/3000 days(70s, 80s, 90s, early 2000s), master tables(manual and automatic) were hashed with collisions resolved exactly as in this video. The rule was to create such tables with a capacity of a prime number. If you need a million rows in your table, set the capacity to the next prime number. it wasn't enforced by the database, actually, but later, utilities were created to help in resizing tables and these would actually tell you what your capacity should be based on what you requested.
thank you soooo much!!!
thanks!