Thank you :) I'm having a hard time deciding what to do next. I originally planned on covering topics like game engines, C, C++, the math needed, etc. Because of requests I have decided to start Android at the end of this month. Then I plan on making games in Android. I want to also make Android apps that will improve on the learning process for topics like math. I have BIG plans. I just have to work my head around completing them
Sorry about the confusion. When I print out the hashtable, I always print 10 cells per row even if they aren't in the array actually. Does that make sense?
Γεια σας Αγαπητέ προπονητής, Hashtable σειρά πρόκειται να είναι φοβερό. Όλα χάρη σε εσάς. Η κατανόησή μου πήρε καλύτερα. Απλά ήθελα να σας ευχηθώ κάθε ευτυχία και επιτυχία. ----- Παρακαλώ μετά στις 10 μ.μ. EST έτσι μπορώ να κερδίσω το χρυσό :) :) :)
My displayTheStack method always prints out boxes in multiples of 10 no matter how large the array is. You'll notice that nothing ever goes into any of the indexes higher than 60 in the video. Sorry if that caused confusion. Trust me the size of the hash table is 61 and not 69
It's great thought , Yes programming is like practical mathematical tool to come up creativity and test our knowledge. When you do things in programming it also leave us blue print of that which other people can use.
I always enjoyed learning about how to solve problems. I grew up without a tv and idolized Sherlock Holmes. I wanted to be just like him. Programming became the thing I wanted to be good at like he wanted to be the best at solving crimes. I think the problem is that people give up on their dreams too early because they aren't achieving them quick enough. I think we can all do most anything if we are willing to keep on learning a little more every day :)
A hashtable doesn't work very well in situations in which you have duplicates. If you base each words key off of the number of times it appears in a sentence that will cause many problems. It sounds like a different data structure is needed. Why are you trying to use a hashtable?
Hi , just a doubt, i have understood your tutorials, but what is my default hashtable going to do , why do we do all the stuff that is implemented by hashtable itself ? because i dont see you using Hashtable class, can you please clarify ..
Derek, you have a mistake in the isPrime function. First you need to check whether number == 2 and return true if it equals 2. In the function you wrote if number equals 2 it will return false, which is not correct. I know that it is a very special case, but I think that it should be considered. Great tutorial. Cheers!
hey Derek, I have a question about the data type in used. For C, I implement a trie before using array of structs, I think hashtables could be done similarly. How do I choose between using array or structs? Could you do the same thing using structs in java?
Hi Derek thank you for this tutorial. Hmm I would like to quote this " I think the problem is that people give up on their dreams too early because they aren't achieving them quick enough. I think we can all do most anything if we are willing to keep on learning a little more every day"
Hi Derek, thanks for the excellent work you are doing with your tutorials. I think I spotted three errors though. 1. theFunc.hashFunction2(elementsToAdd2, theFunc.theArray); should be called with first parameter being elementsToAdd3, shouldn't it? Errors regarding prime number calculation: "A prime number (or a prime) is a natural number greater than 1 that has no positive divisors other than 1 and itself." - Wiki So 1 is not a prime number, but 2 is a prime number. Any negative number is not a prime. 2. integer 2 is a prime number, so the function isPrime that currently starts with: if (number % 2 == 0) return false; should be corrected (imho) to something like this: if (number < 2) return false; if (number == 2) return true; if (number % 2 == 0) return false;
Hi Derek I just want to start by saying that I love your videos; though i do have a question for you are you going to ever get into game engine development because I think that would be a great series.
Stick with it and it will make sense. I hope to eventually cover math topics, but I want to do it the right way. I want it to be fun and interesting. If I could make math tutorials that really helped people, that would be awesome!
Your video is great! It helps me a lot! Though I have a question here. So 61 is the next prime number after 60. Why the array have a size of 69? I saw this at 11:23 in the video
Thank you for a great tutorial! I think you should have increased the value of the step. golden ratio (some step=37 and hash table size =61) might be the best because golden ratio has the worst chain fraction approximation and the lowest likelihood of collision.
for the programming up until 11.05, when I type prime number in increseArraySize(), it will throw arrayOutBound Exception. It works for non prime number because it will increase the size to next prime. But when I use prime number(assume is 67) for the new array size, it will get exception. I tried to fix this, but I failed. Derek, need help to explain why this will happen.
Hi Derek! I find your tutorials very useful. I just want to ask how to implement a quadratic probing method. I noticed that you used linear probing for hashFunction2 method. I appreciate any help or suggestion. Thanks
I believe instead of incrementing by 1 each time, you should increment by the number of rehash attempts squared. I would create variable that keeps track of every collision, and then instead of adding one to the arrayIndex add number of collisions squared. Hope this helps
Android development starts next week. I had a vote a while back on whether people wanted to see web or tablet development. Tablets won, so that is why I've been focusing on that path. I really just want to teach about game development because it requires so many other skills. I'll get to everything else ASAP
Hi, The function you used to generate a step distance int stepDistance = 7 - (Integer.parseInt(newElementVal) % 7); Can you use a random function "RAND" to generate random index. Will that solve the clustering problem. Please suggest..? Thanks
False. Pseudorandom number generators can be seeded and their emulated stochasticity can therefore be accessed in a deterministic fashion. Id est: rng.setSeed( hash1 ); // where rng = class member Random; ensures that the second line is deterministic int hash2 = rng.nextInt( arraySize ); // produces a second "random" hash within the range [0, arraySize)
I make everything 100% on my own. It isn't really that hard. The hardest part is to make them understandable. Once I figure out how to do that I draw a sequence diagram and crank out the code
WHere is the concept of key value pairs in these videos ?, I am feeling confused how the login you implemented is different from HashTable class in Java ?
Hey Derek, Firstly thanks for all your tutorial videos, they are pretty helpful. I was thinking of the example you used to explain why we use a prime number for the arraySize. Since "30", "60", "90", "120", "150", "180" these numbers are intentionally chosen and they are multiples of 30(which is the arraySize), so there will be a lot of collisions while storing. Then you mentioned if we change the arraySize to 31, the modulus for those numbers will be different, so a lot of collisions will be avoided. HOWEVER, what if the numbers added into hash table are "31", "62", "93", "124", "154", "185", which are multiples of 31? then I guess the same collisions will happen as well, no matter if 31 is a prime number or not. Thanks! Rich
When checking if a number is prime or not, a nice way to make things quicker is to check until the square root of the number, instead of until the number itself.
It should be noted that your displayStack() method isnt the same as it was in Video 1, took a while to figure out why my hashtable kept printing out differently than yours.
For the double hash, why not use the first hash as a parameter to a seeded number generator? Something along the lines of: rng.setSeed( hash1 ); int hash2 = rng.nextInt( arraySize ); // where rng = Random rng
Derek Banas I watched your all videos on Linked List, Binary tree and it helped me to learn concepts completely. In case I have any problem with any other concept, Is there anyway (like email) to contact you?
He clearly stated that patterns in real life data sets don't generally happen in primes. You are more likely to get numbers like 30,60,90 than 31,62,93. Furthermore, you should be looking at your dataset and basing your algorithm on that. In this case a higher prime would be better, but if all your numbers are like under 30, then it would make no sense to use 31.
Very informative and it's good to know how a hashtable works, but I'm going to stick to .Net's generic solutions + overriding hashCode as opposed to making my own. This was complicated enough, after adding on thread safety it would be a monster (er, well, at least in comparison to the objects I've been making lately; since I watched your refactoring series and started making smaller more specific objects). I really can't go back to large classes now that I've tasted the freedom of granularity.
i am making a project on auto summarization tool. so i am using stammer and lemma, to reduce the no and length of words in a given sentence . i only need to place them in a hash table according to there frequency (frequency= how many times a word is repeating in a whole input) so ,i am taking frequency of word as a key value and thts what i am not able to do it i need help in this
Hey Derek, Awesome tutorial. Couple of things though, any reason why you decided to use an ArrayList instead of doubling the size of the array? And you could use System.arraycopy method to do a lot of the work for you. Awesome tutorial anyways.
are you a troll? anyway if not, this is because the prime number check is being done to find the next possible arraysize that is prime number. now if you were to get 2 as your next possible arraysize that means the size of the prvevious array was 1 which is highly unlikely. even if the size of previous array was 1 then the arraysize being used would be 3. so you only skip 2 which should not make that much of a difference.
Hey, I am not sure if your isPrime function actually works ? ? Since I watched it at 11:14 that your hash table actually has 69 boxes and that is not a prime.
Με τη διδασκαλία γι 'αυτούς ήμουν σε θέση να καλύψει ένα σωρό άλλα πράγματα. Έχει ένα ενδιαφέρον θέμα. Χαίρομαι που σας αρέσει. Θα δω αν μπορώ να δημοσιεύσετε στο 10. Βοηθός μου έχει φύγει τώρα, ώστε να μπορεί να είναι πιο δύσκολο να δημοσιεύσετε βίντεο γρήγορα
+Verdy Rizaldi Its math stuff. number % 2 == 0 eliminates all even numbers. Then we only have to go up to the square root of number because when you list out all of the factors of the number the square root will always be in the middle.
Another little bug found in isPrime() method. I did a unit testing which resulted in: Next prime to -1 is 2 Next prime to -2 is 2 Next prime to -3 is 2 Next prime to -4 is 2 Next prime to 0 is 2 Next prime to 1 is 2 Process finished with exit code -1 Next prime to 2 is 2 junit.framework.AssertionFailedError: Next prime expected for 2 is 3 expected: but was: at numbers.PrimaryNumbersTest.testGetNextPrime(PrimaryNumbersTest.java:77) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at com.intellij.junit3.JUnit3IdeaTestRunner.doRun(JUnit3IdeaTestRunner.java:141) at com.intellij.junit3.JUnit3IdeaTestRunner.startRunnerWithArgs(JUnit3IdeaTestRunner.java:52) at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:211) at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:67) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at com.intellij.rt.execution.application.AppMain.main(AppMain.java:134) One way to fix it is to insert: if (isPrime(minNumberToCheck)){ minNumberToCheck++; } at the beginning of the method. Then for my unit test data: Next prime to -1 is 2 Next prime to -2 is 2 Next prime to -3 is 2 Next prime to -4 is 2 Next prime to 0 is 2 Next prime to 1 is 2 Next prime to 2 is 3 Next prime to 3 is 5 Next prime to 4 is 5 Next prime to 5 is 7 Next prime to 6 is 7 Next prime to 7 is 11 Next prime to 8 is 11 Next prime to 9 is 11 Next prime to 10 is 11 Next prime to 11 is 13 Next prime to 12 is 13 Next prime to 13 is 17 Next prime to 14 is 17 Next prime to 15 is 17 Next prime to 16 is 17 Next prime to 17 is 19 Next prime to 18 is 19 Next prime to 19 is 23 Next prime to 20 is 23 Next prime to 21 is 23 Next prime to 22 is 23 Next prime to 23 is 29 Next prime to 24 is 29 Next prime to 25 is 29 Next prime to 26 is 29 Next prime to 27 is 29 Next prime to 28 is 29 Next prime to 29 is 31 Next prime to 30 is 31
+spacepod100 Furthermore, you do not need to check for numbers larger than sqrt(n) where n is the target value. Solving for i in the equation, sqrt(n) = i, we find that i^2 should be less than n.
Why not make an clean array of size itemsInArray. instead of wasting time with a arrayList which you have to convert back to an array? And again, this search function won't work if the table is full.
When you say "clustering is not good", you need to explain why. We shouldn't be told to avoid something in programming just because someone tells us to. The reason may not be that apparent to some. Whenever developers write code, they should know exactly why something is being written. One thing I hate when reviewing someone else's code is seeing a comment like "This could be bad, so to avoid this, the following line of code fixes it" without writing why something was bad.
I thought about the same "why clustring bad" and a quick google search to contribute to Derek's great work, it seems like a performance concern: en.wikipedia.org/wiki/Primary_clustering "These long chains degrade the hash-table performance closer to O(n) performance instead of closer to O(1)."
I'm so baffled rn. You have made 3 tutorials named "Hash Table" but NOT ONCE do you ever declare a Hashtable in java and use the predefined package provided by java. Yes I understand that a hash table is a bunch of arrays but you are still confusing the heck outta me bro. Is there a reason you don't actually DECLARE a table? Because for my school project, we have to define a hastable and its size, then add a dictionary and spell checker to it. Then a GUI. good luck to me
+Derek Banas No problem, thanks for replying quickly. Do you have any recommendations for setting up a dictionary using a text document and using the hash table as a spell checker? Would you want to utilize two hash tables? Or just one and compare each word using hash functions. Our teacher isn't letting us use the "hash code" function, we have to do the math
+ThatBoyDunn If you are allowed to use the Java Collection Framework, try adding each word from your dictionary file to a HashSet. Then the text file that you want to spellcheck should be stored in another Set depending on your needs. I had a similar assignment where we didn't need a GUI, and we were to display each misspelled word in alphabetical order, so I stored the words in a TreeSet, that way they were in order. I also kept another Set to keep track of misspelled words, since we were not to show the same word twice. Again it'll depend on your specific assignment if you need that or not. There shouldn't be any need for custom hash functions if your supposed predefined packages. Just use the methods available with the collections you choose. But I would definitely use two collections. You're going to need to iterate through both and multiple times. I'm assuming you probably need to list possible corrections too? So you're likely going to be manipulating the incorrect words to find matches in your dictionary. This means you will be constantly searching for each manipulated string in your dictionary. Hope that kind of makes sense, and it's not too late for you. Good luck.
thanks for your input, we actually had completed the project before your comment, but that's okay, we actually asked one of our lab TA's who was a CSE from India and he gladly helped us with our project, thank the lord lol
Thank you :) I'm having a hard time deciding what to do next. I originally planned on covering topics like game engines, C, C++, the math needed, etc. Because of requests I have decided to start Android at the end of this month. Then I plan on making games in Android. I want to also make Android apps that will improve on the learning process for topics like math. I have BIG plans. I just have to work my head around completing them
Sorry about the confusion. When I print out the hashtable, I always print 10 cells per row even if they aren't in the array actually. Does that make sense?
Thank you :) Did you try the code I provide on my site, or do you have any errors?
Just wanted to say your videos are very well structured and to the point!!
Great job, thanks for putting these up.
+Gabe Montenegro You're very welcome :) Thank you
I have all my java algorithm videos here on one page newthinktank. com/videos/java-algorithms/
Γεια σας Αγαπητέ προπονητής,
Hashtable σειρά πρόκειται να είναι φοβερό.
Όλα χάρη σε εσάς.
Η κατανόησή μου πήρε καλύτερα.
Απλά ήθελα να σας ευχηθώ κάθε ευτυχία και επιτυχία.
-----
Παρακαλώ μετά στις 10 μ.μ. EST έτσι μπορώ να κερδίσω το χρυσό :) :) :)
These videos are amazing. I have a major CS test coming up and Ive watched all your videos and I feel super prepared
sagar vadalia Thank you :) I'm glad to hear they helped. Best of luck on your tests.
My displayTheStack method always prints out boxes in multiples of 10 no matter how large the array is. You'll notice that nothing ever goes into any of the indexes higher than 60 in the video. Sorry if that caused confusion. Trust me the size of the hash table is 61 and not 69
Thanks
Why not use regular expressions for that?
It's great thought , Yes programming is like practical mathematical tool to come up creativity and test our knowledge. When you do things in programming it also leave us blue print of that which other people can use.
This is really interesting stuff. Not just from a programmers point of view.
I always enjoyed learning about how to solve problems. I grew up without a tv and idolized Sherlock Holmes. I wanted to be just like him. Programming became the thing I wanted to be good at like he wanted to be the best at solving crimes. I think the problem is that people give up on their dreams too early because they aren't achieving them quick enough. I think we can all do most anything if we are willing to keep on learning a little more every day :)
A hashtable doesn't work very well in situations in which you have duplicates. If you base each words key off of the number of times it appears in a sentence that will cause many problems. It sounds like a different data structure is needed. Why are you trying to use a hashtable?
Hi , just a doubt, i have understood your tutorials, but what is my default hashtable going to do , why do we do all the stuff that is implemented by hashtable itself ? because i dont see you using Hashtable class, can you please clarify ..
Derek, you have a mistake in the isPrime function. First you need to check whether number == 2 and return true if it equals 2. In the function you wrote if number equals 2 it will return false, which is not correct. I know that it is a very special case, but I think that it should be considered.
Great tutorial.
Cheers!
You're very welcome :) I have a tutorial on Big O notations that should help with that here ruclips.net/video/V6mKVRU1evU/видео.html
hey Derek, I have a question about the data type in used. For C, I implement a trie before using array of structs, I think hashtables could be done similarly. How do I choose between using array or structs? Could you do the same thing using structs in java?
Hi Derek thank you for this tutorial. Hmm I would like to quote this " I think the problem is that people give up on their dreams too early because they aren't achieving them quick enough. I think we can all do most anything if we are willing to keep on learning a little more every day"
Hi Derek, thanks for the excellent work you are doing with your tutorials.
I think I spotted three errors though.
1. theFunc.hashFunction2(elementsToAdd2, theFunc.theArray); should be called with first parameter being elementsToAdd3, shouldn't it?
Errors regarding prime number calculation:
"A prime number (or a prime) is a natural number greater than 1 that has no positive divisors other than 1 and itself." - Wiki
So 1 is not a prime number, but 2 is a prime number. Any negative number is not a prime.
2. integer 2 is a prime number, so the function isPrime that currently starts with:
if (number % 2 == 0)
return false;
should be corrected (imho) to something like this:
if (number < 2) return false;
if (number == 2) return true;
if (number % 2 == 0)
return false;
Thank you for pointing that out. I think I fixed the code on my site after I noticed the typo. I'm mobile right now so I'll check later to make sure.
This tutorial should really be called How All those Tools you Use Actually Work :)
Hi Derek I just want to start by saying that I love your videos; though i do have a question for you are you going to ever get into game engine development because I think that would be a great series.
Yes I use arraylists all of the time in my Java tutorials. I also have a tutorial on them in my java video tutorial for part 11
Stick with it and it will make sense. I hope to eventually cover math topics, but I want to do it the right way. I want it to be fun and interesting. If I could make math tutorials that really helped people, that would be awesome!
Hey Derek..Videos for algo are awesome. These are fast and precise.
Just wanted to know if you have uploaded videos on Java Collections too?
+Archit Jain Thank you :) I don't have videos that are specific to the Java collections but I use them in my Java and Android tutorials
Your video is great! It helps me a lot!
Though I have a question here. So 61 is the next prime number after 60. Why the array have a size of 69? I saw this at 11:23 in the video
U helped me complete my assignment about hash table! Thank you so much! Keep going well! :)
+Tomn Nguyen You're very welcome :)
Thank you for a great tutorial! I think you should have increased the value of the step. golden ratio (some step=37 and hash table size =61) might be the best because golden ratio has the worst chain fraction approximation and the lowest likelihood of collision.
for the programming up until 11.05, when I type prime number in increseArraySize(), it will throw arrayOutBound Exception. It works for non prime number because it will increase the size to next prime. But when I use prime number(assume is 67) for the new array size, it will get exception. I tried to fix this, but I failed. Derek, need help to explain why this will happen.
Hi Derek! I find your tutorials very useful. I just want to ask how to implement a quadratic probing method. I noticed that you used linear probing for hashFunction2 method. I appreciate any help or suggestion. Thanks
I believe instead of incrementing by 1 each time, you should increment by the number of rehash attempts squared. I would create variable that keeps track of every collision, and then instead of adding one to the arrayIndex add number of collisions squared. Hope this helps
Android development starts next week. I had a vote a while back on whether people wanted to see web or tablet development. Tablets won, so that is why I've been focusing on that path. I really just want to teach about game development because it requires so many other skills. I'll get to everything else ASAP
In your r moveEmptyspacesInArray(String arrayToClean) the ‘if’ statement should that be an or || not an and && ?
Thank you :) I just used 69 so that there would be an equal number of spaces in the columns that are displayed on the screen.
Hi,
The function you used to generate a step distance
int stepDistance = 7 - (Integer.parseInt(newElementVal) % 7);
Can you use a random function "RAND" to generate random index.
Will that solve the clustering problem.
Please suggest..?
Thanks
it would solve the clustering, but you would no longer be able to find the target using a key.
Ok...thanks John...I got it.
As every time it will generate a new number and same will not be mapped backwards..isn't it
False. Pseudorandom number generators can be seeded and their emulated stochasticity can therefore be accessed in a deterministic fashion. Id est:
rng.setSeed( hash1 ); // where rng = class member Random; ensures that the second line is deterministic
int hash2 = rng.nextInt( arraySize ); // produces a second "random" hash within the range [0, arraySize)
You da real MVP
Soyeon Park That's funny :) Thank you
+Soyeon Park (Shannon) +Derek where P stands for Programmer ;)
Thank you :)
Very helpful! but just do not know what the double hash exactly means... Would you please answer me?
I make everything 100% on my own. It isn't really that hard. The hardest part is to make them understandable. Once I figure out how to do that I draw a sequence diagram and crank out the code
you're wonderful. Thank you so much for this professional videos
Thank you very much :) I'm happy they helped
WHere is the concept of key value pairs in these videos ?, I am feeling confused how the login you implemented is different from HashTable class in Java ?
Hey Derek,
Firstly thanks for all your tutorial videos, they are pretty helpful.
I was thinking of the example you used to explain why we use a prime number for the arraySize.
Since "30", "60", "90", "120", "150", "180" these numbers are intentionally chosen and they are multiples of 30(which is the arraySize), so there will be a lot of collisions while storing.
Then you mentioned if we change the arraySize to 31, the modulus for those numbers will be different, so a lot of collisions will be avoided.
HOWEVER, what if the numbers added into hash table are "31", "62", "93", "124", "154", "185", which are multiples of 31? then I guess the same collisions will happen as well, no matter if 31 is a prime number or not.
Thanks!
Rich
He said that patterns similar to the one you just described are not as common as the one he used in the example. Nothing is perfect, just less bad
When checking if a number is prime or not, a nice way to make things quicker is to check until the square root of the number, instead of until the number itself.
Thank you for pointing that out :)
It should be noted that your displayStack() method isnt the same as it was in Video 1, took a while to figure out why my hashtable kept printing out differently than yours.
For the double hash, why not use the first hash as a parameter to a seeded number generator? Something along the lines of: rng.setSeed( hash1 ); int hash2 = rng.nextInt( arraySize ); // where rng = Random rng
hey derek
thanks for ur reply i wana ask u about if i have a code how i can calculate his time complixty ,, ?
THANKS AGAIN
I have an additional hash table tutorial after this. It should help
I would like to thank you for such a helpful video.
Gaurav Gupta You're very welcome :)
Derek Banas I watched your all videos on Linked List, Binary tree and it helped me to learn concepts completely. In case I have any problem with any other concept, Is there anyway (like email) to contact you?
with array size 31, we get collision again if we array of elements 31,62, 93.....
He clearly stated that patterns in real life data sets don't generally happen in primes. You are more likely to get numbers like 30,60,90 than 31,62,93. Furthermore, you should be looking at your dataset and basing your algorithm on that. In this case a higher prime would be better, but if all your numbers are like under 30, then it would make no sense to use 31.
but still I appreciate your effort on making this fantastic video, Keep it up : )
Very informative and it's good to know how a hashtable works, but I'm going to stick to .Net's generic solutions + overriding hashCode as opposed to making my own. This was complicated enough, after adding on thread safety it would be a monster (er, well, at least in comparison to the objects I've been making lately; since I watched your refactoring series and started making smaller more specific objects). I really can't go back to large classes now that I've tasted the freedom of granularity.
i am making a project on auto summarization tool.
so i am using stammer and lemma, to reduce the no and length of words in a given sentence .
i only need to place them in a hash table according to there frequency (frequency= how many times a word is repeating in a whole input)
so ,i am taking frequency of word as a key value
and thts what i am not able to do it
i need help in this
Hey Derek, Awesome tutorial. Couple of things though, any reason why you decided to use an ArrayList instead of doubling the size of the array? And you could use System.arraycopy method to do a lot of the work for you. Awesome tutorial anyways.
How about 2, 2 is prime number. if U number %2 ==0 then U exclude prime numbe 2.
are you a troll? anyway if not, this is because the prime number check is being done to find the next possible arraysize that is prime number. now if you were to get 2 as your next possible arraysize that means the size of the prvevious array was 1 which is highly unlikely. even if the size of previous array was 1 then the arraysize being used would be 3. so you only skip 2 which should not make that much of a difference.
Hey, I am not sure if your isPrime function actually works ? ?
Since I watched it at 11:14 that your hash table actually has 69 boxes and that is not a prime.
Sie sind herzlich willkommen
does windows defragmenter use this algorithm?
@Derek , you might have already made this video but I could not find it. A video about Hashmaps or Hashmaps vs Hashtables
hey derek..
i have a project that i want to accses files using hashing then find the exactly id of someone on that file how i can make this ,, :)
Με τη διδασκαλία γι 'αυτούς ήμουν σε θέση να καλύψει ένα σωρό άλλα πράγματα. Έχει ένα ενδιαφέρον θέμα. Χαίρομαι που σας αρέσει. Θα δω αν μπορώ να δημοσιεύσετε στο 10. Βοηθός μου έχει φύγει τώρα, ώστε να μπορεί να είναι πιο δύσκολο να δημοσιεύσετε βίντεο γρήγορα
How does the line in arrayIndex %= arraySize not cause an infinite loop?
well done fella ! !
can i use a hashtable to store the data that i get from an XML file?
Abi Oni Yes you can
Nice video. thanks
Excellent as always. Thanks for sharing. :)
can you explain why do you multiply i by 2 in the for loop in isPrime method?
+Verdy Rizaldi Its math stuff. number % 2 == 0 eliminates all even numbers. Then we only have to go up to the square root of number because when you list out all of the factors of the number the square root will always be in the middle.
I actually figured it out a few minutes ago, but thx for ur response :D
+Verdy Rizaldi No problem :)
But, 2 is also a prime number, isn't it?
You are really good!!
Ariel Snir Thank you :)
Here in 2021 ; thanks bro :-)
It is my pleasure to help :)
Another little bug found in isPrime() method. I did a unit testing which resulted in:
Next prime to -1 is 2
Next prime to -2 is 2
Next prime to -3 is 2
Next prime to -4 is 2
Next prime to 0 is 2
Next prime to 1 is 2
Process finished with exit code -1
Next prime to 2 is 2
junit.framework.AssertionFailedError: Next prime expected for 2 is 3 expected: but was:
at numbers.PrimaryNumbersTest.testGetNextPrime(PrimaryNumbersTest.java:77)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at com.intellij.junit3.JUnit3IdeaTestRunner.doRun(JUnit3IdeaTestRunner.java:141)
at com.intellij.junit3.JUnit3IdeaTestRunner.startRunnerWithArgs(JUnit3IdeaTestRunner.java:52)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:211)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:67)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:134)
One way to fix it is to insert:
if (isPrime(minNumberToCheck)){
minNumberToCheck++;
}
at the beginning of the method. Then for my unit test data:
Next prime to -1 is 2
Next prime to -2 is 2
Next prime to -3 is 2
Next prime to -4 is 2
Next prime to 0 is 2
Next prime to 1 is 2
Next prime to 2 is 3
Next prime to 3 is 5
Next prime to 4 is 5
Next prime to 5 is 7
Next prime to 6 is 7
Next prime to 7 is 11
Next prime to 8 is 11
Next prime to 9 is 11
Next prime to 10 is 11
Next prime to 11 is 13
Next prime to 12 is 13
Next prime to 13 is 17
Next prime to 14 is 17
Next prime to 15 is 17
Next prime to 16 is 17
Next prime to 17 is 19
Next prime to 18 is 19
Next prime to 19 is 23
Next prime to 20 is 23
Next prime to 21 is 23
Next prime to 22 is 23
Next prime to 23 is 29
Next prime to 24 is 29
Next prime to 25 is 29
Next prime to 26 is 29
Next prime to 27 is 29
Next prime to 28 is 29
Next prime to 29 is 31
Next prime to 30 is 31
Wait why does the Double Hashing method doesn't work?
can someone explain the isPrime method and why i*i was put in the for loop please. 5:30
+spacepod100 You do not need to check for numbers that are greater than half the value of your target.
+spacepod100 Furthermore, you do not need to check for numbers larger than sqrt(n) where n is the target value. Solving for i in the equation, sqrt(n) = i, we find that i^2 should be less than n.
Everything you did is very helpful to me but could you please try to talk a little slowier :)
Sorry about the speed. I'm working on that
Hey, Derek! You play Minecraft???? Nice. (I saw that in the bottom of your screen)
BTW Thanks a lot. I am a fan of yours. :)
Hi, Yes I used to make mods for Minecraft. It is very fun to play with. I'm very happy that you enjoyed the video.
Why not make an clean array of size itemsInArray. instead of wasting time with a arrayList which you have to convert back to an array? And again, this search function won't work if the table is full.
Yo dude love your course you should be on lynda or something but quick q is there a hash table class in the java API
sameer pabreja Thank you for the compliment :) I think this is what you need docs.oracle.com/javase/7/docs/api/java/util/Hashtable.html
Awesome
Oh i have used this before
When you say "clustering is not good", you need to explain why. We shouldn't be told to avoid something in programming just because someone tells us to. The reason may not be that apparent to some. Whenever developers write code, they should know exactly why something is being written. One thing I hate when reviewing someone else's code is seeing a comment like "This could be bad, so to avoid this, the following line of code fixes it" without writing why something was bad.
I thought about the same "why clustring bad" and a quick google search to contribute to Derek's great work, it seems like a performance concern:
en.wikipedia.org/wiki/Primary_clustering
"These long chains degrade the hash-table performance closer to O(n) performance instead of closer to O(1)."
GOOD!
Your videos are really very helpful :)
But PLEASE PLEASE try and go a little slower.
Piyush Ramnani Thank you :) Sorry about the speed.
Lol... I was watching it at 1.25x, hahaha
+Piyush Ramnani RUclips has a pause button lol.
Here's a tip the works for me: YMMV... get the code and explore it in the debugger before you watch the video
Danke
I love you
hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh
I enjoy your videos but it would be better if you did not name fields and variables with the word new in them
josh widman Thank you :) Sorry about that. I tend to write these out of my head so they aren't optimized.
I'm so baffled rn. You have made 3 tutorials named "Hash Table" but NOT ONCE do you ever declare a Hashtable in java and use the predefined package provided by java. Yes I understand that a hash table is a bunch of arrays but you are still confusing the heck outta me bro. Is there a reason you don't actually DECLARE a table? Because for my school project, we have to define a hastable and its size, then add a dictionary and spell checker to it. Then a GUI. good luck to me
Sorry for the confusion. I'm making hash tables from scratch.
+Derek Banas No problem, thanks for replying quickly. Do you have any recommendations for setting up a dictionary using a text document and using the hash table as a spell checker? Would you want to utilize two hash tables? Or just one and compare each word using hash functions. Our teacher isn't letting us use the "hash code" function, we have to do the math
+ThatBoyDunn If you are allowed to use the Java Collection Framework, try adding each word from your dictionary file to a HashSet. Then the text file that you want to spellcheck should be stored in another Set depending on your needs. I had a similar assignment where we didn't need a GUI, and we were to display each misspelled word in alphabetical order, so I stored the words in a TreeSet, that way they were in order. I also kept another Set to keep track of misspelled words, since we were not to show the same word twice. Again it'll depend on your specific assignment if you need that or not.
There shouldn't be any need for custom hash functions if your supposed predefined packages. Just use the methods available with the collections you choose. But I would definitely use two collections. You're going to need to iterate through both and multiple times. I'm assuming you probably need to list possible corrections too? So you're likely going to be manipulating the incorrect words to find matches in your dictionary. This means you will be constantly searching for each manipulated string in your dictionary.
Hope that kind of makes sense, and it's not too late for you. Good luck.
thanks for your input, we actually had completed the project before your comment, but that's okay, we actually asked one of our lab TA's who was a CSE from India and he gladly helped us with our project, thank the lord lol
where do you go to school? i had the same project
but 2 is a prime number :O
yes, but do you need a hash function for a hash table of size 2? hmmm
Thank you :)