Java Hash Tables 3

Поділитися
Вставка
  • Опубліковано 19 вер 2024

КОМЕНТАРІ • 96

  • @cguimaraenz
    @cguimaraenz 6 років тому

    I like it when they don't hide their mistakes, but show they are human and humble at the same time. It's good also for people learning to see that even experienced ones can make mistakes. Thank you Derek, really good work, very clear and entertaining too!

  • @AnhNguyen-qp8bi
    @AnhNguyen-qp8bi 3 роки тому +1

    I have watched all your 3 videos about hash tables. They are all amazing and the best on UA-cam. Thank you

  • @derekbanas
    @derekbanas  11 років тому

    They are very crazy. I spent many years creating sales training programs. I got to experiment on unsuspecting people all over the country to see what actually works. Basically I got to program people. After my contract was up I uploaded everything on UA-cam :) the crazy stuff is in my advanced sales techniques tutorial. Not many people have seen it

  • @derekbanas
    @derekbanas  11 років тому

    You would create a custom data structure when what is out there doesn't fit the requirements of a class you need. If you just need a basic list, hash table, etc. you should always use those provided by java. In those situations though this tutorial shows which is best to use depending on what you specifically want to optimize

  • @piyush_ramnani
    @piyush_ramnani 7 років тому +2

    Hi Derek, correct me if I'm wrong :)
    The Word class doesn't need to have the key variable.
    The key(hashKey) is only used to find an appropriate index in the wordList[] to insert the word.
    The word gets inserted in the linkedList (at the key index of wordList[]) in no particular order, so we don't need to use the key in the "insert" and "find" methods of the WordList class.
    Thanks for the video.

  • @derekbanas
    @derekbanas  11 років тому

    I'm sorry, but I'm a bit confused by the questions. You have to have a unique piece of data that differentiates each item you are storing. The fact that all items are sorted in the word list speeds up the search. Some times this increases speed, but some times staggering the indexes works better. This is something that needs to be experimented with. Normally it doesn't matter if the array size is optimized for the number of items. I hope that helps

  • @derekbanas
    @derekbanas  11 років тому +1

    I'm happy that you're enjoying the videos :)

  • @derekbanas
    @derekbanas  11 років тому

    Thank you :) I'll get back to web stuff soon enough. I'm glad you liked them

  • @inspired7606
    @inspired7606 7 років тому

    You make me wonder why I am in college that can't teach a fraction of what you thought me. superb tutor. thank you, Derek.

    • @derekbanas
      @derekbanas  7 років тому

      Thank you very much :) A free education for all is the dream!

  • @eliasarias7004
    @eliasarias7004 8 років тому

    Very well done! I was waiting and waiting for you to cover Java's API's, but this approach actually makes understanding and using their API far more understandable. Thank you and cheers!

    • @derekbanas
      @derekbanas  8 років тому

      Thank you :) I'm happy you found it useful

  • @reydez84
    @reydez84 9 років тому

    only youtuber that I found that did an amazing job with hash.. thx a lot!!

  • @derekbanas
    @derekbanas  11 років тому

    That is coming. I just think it helps to print out what's going on with the code for now

  • @topturv528
    @topturv528 8 років тому

    You're on fire, dude. This was an awesome tutorial. Especially the use of the link-list

    • @derekbanas
      @derekbanas  8 років тому

      +Julia A. (Rubunyjea) Thank you :)

  • @derekbanas
    @derekbanas  11 років тому

    Thank you :) I do my best to make them interesting and useful

  • @ngInverse
    @ngInverse 11 років тому

    Thanks, I'll look into it!
    I just realized you had videos pertaining to things other than programming. Psychology, being the main one. I cannot wait to dive into those!

  • @derekbanas
    @derekbanas  11 років тому

    With hash tables you can't have duplicates. That is the one big negative. Surprisingly enough I haven't really found it to be a problem though. I made the mistake because I was trying to do too many things out of my head. Either way, I think it is good to see how I solved the mistake. Believe me I make many mistakes in life :)

  • @derekbanas
    @derekbanas  11 років тому

    That's funny. I'm amazed by how many languages you guys know!

  • @NoobsDeSroobs
    @NoobsDeSroobs 11 років тому

    And it did indeed help a lot. Thank you for always making excellent tutorials.

  • @derekbanas
    @derekbanas  11 років тому +1

    That is actually the error I made in this video at the very end. You have to go in and check for a distinct name, value, etc. that each item in the hash table has. (Everything must have something distinct )
    The key just points you to the right neighborhood. It is like telling somebody you live on Main Street. That gets them almost there. Then your house number gets them right to your doorstep. Does that help?

  • @derekbanas
    @derekbanas  11 років тому

    I really like Google's WindowBuilder tool eclipse. org/windowbuilder/
    It works for what I do.
    Android will start at the very beginning of next month. I'll do as much on algorithms as possible until then. If I miss anything that I want to cover on algorithms I'll slip those videos in randomly until I'm satisfied

  • @derekbanas
    @derekbanas  11 років тому

    Ill double check it tomorrow thanks

  • @derekbanas
    @derekbanas  11 років тому

    Yes I agree

  • @atlrafa
    @atlrafa 8 років тому +1

    Great work +Derek Banas

    • @derekbanas
      @derekbanas  8 років тому +1

      +atl rafa Thank you :)

  • @derekbanas
    @derekbanas  11 років тому

    Sorry, but I currently don't have time to do tutorials on specific classes created at universities. It is a topic that wouldn't apply to many people. I hope that makes sense

  • @NoobsDeSroobs
    @NoobsDeSroobs 11 років тому

    I must beg your pardon then, I noticed that mistake, but I stopped when you were about to test it as I presumed you were correct. I watch your videos because you explain the inner working of concepts in programming. I have one question though. What if you tried to add the word "snake" twice with a different definition, how would you handle that? Assume we don't have a list to store the definitions in, how would I avoid an overwrite? Is there a better way than a list?

  • @derekbanas
    @derekbanas  11 років тому

    Yes this is a game we play :) I figured we were both using translators and I know they don't work very well

  • @skazis87
    @skazis87 11 років тому

    Hi, thanks for ALL the great tutorials. I have 2 questions.
    1st:
    If I put parameters as type Objects in my HashTable- what kind of hash function can i use?
    2nd:
    if I don't allow more than one object in my bucket and next object is sent to next bucket and so on until it can be stored(solved hash collision) how it is better than storing in the same bucket in the sense of efficiency of retrieving this object if in both cases I have to iterate trough a single bucket's values or values of buckets?

  • @NoobsDeSroobs
    @NoobsDeSroobs 11 років тому

    Lets assume you enter a key that gives you the value of 1, and you put an object in the slot marked #1. Then you give a different key that also give the value of 1, how does the program know to not return the element stored? Same with these lists, how does the program know what element in the list to return when key a is entered in comparison to key b?

  • @genesisbejarano9671
    @genesisbejarano9671 11 років тому

    just thank T.T i have struggle so much with coding chaining keep it up :)

  • @BashkimUkshini
    @BashkimUkshini 9 років тому +1

    You are helping a lot mate, very good!
    THANK YOU!

    • @derekbanas
      @derekbanas  9 років тому

      Bashkim Ukshini You're very welcome :)

  • @dasten123
    @dasten123 11 років тому

    Interesting stuff, but In Wordlist's insert() the
    while(...&& newWord.key > current.key)
    never evaluates to true. When insert() is called more than one time on one Wordlist, it means that their indexes in theArray[] are the same - and this is the hash key you are comparing right now
    In your case it works because your elementsToAdd[][] is ordered alphabetically
    According to your explanation I think you meant:
    while(...&& newWord.theWord.compareTo(current.theWord) > 0)
    And below in find() the same

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

    Why is "arraySize" displayed as 10 instead of 11 in the output?

  • @MegaVuhung
    @MegaVuhung 11 років тому

    u put the main method in the WordList class,but the public class is HashFunction3 so obviously it can't be executed,so how can i fix that?

  • @georgikoyrushki7825
    @georgikoyrushki7825 9 років тому +2

    Thank you
    Derek Banas
    , a really good implementation of a Dictionary.There is only one thing that I do not understand. I may get it wrong, but I would be really glad if someone helps me. So, theArray is an array that holds objects of type WordList. Each of these objects is a LinkedLists in which key values with the same hashKeys are kept. Here is what bothers me:
    In the insert method, in the WordList class, when we try to find the place of the newWord in the linked list corresponding to its hashkey, we are comparing the hashKey of that word with the hashKeys of all other words. Isn't this going to be the same value? Or I am getting it wrong. Because if theArray[someHashKey] returns list with words having the same hashkey, what is the point of making the comparison?
    Thank you very much for your response :)

    • @ARJUNCEC
      @ARJUNCEC 9 років тому

      The same questions comes in my mind too... We are inserting the objects with the same hashKey in the linked list, then what is the point in comparing the key again?

    • @riazuddin6862
      @riazuddin6862 9 років тому +1

      +georgi koyrushki , +Derek Banas, Exactly i have the same question in my mind.. I think there is no need of While and if else condition, as while loop is never executed so previous value is always null, hence no need of them. Please correct me if i am missing something, my understanding is based on the following explanation i found on the internet about hashtable.
      "Hashtable stores elements in buckets. In separate chaining, every bucket will store a reference to a linked list. Now assume that you have stored an element in bucket 1. That means, in bucket 1 you will have a reference to a linked list and in that linked list you will have two cells. In those two cells you will have key and its corresponding value. Why do you want to store the key? Because when there is a collision i.e., when two keys results in same hashcode and directs to the same bucket (assume bucket 1) you want to store the second element also in the same bucket. You add this second element to the already created linked list as the adjacent element.Now when you retrieve a value it will compute the hash code and direct you to a bucket which has two elements. You scan those two elements alone sequentially and compare the keys using their equals() method. When the key matches you get the respective value."source: javapapers.com/core-java/java-hashtable/

    • @jeffreytrenton
      @jeffreytrenton 8 років тому +1

      +Riaz Ud Din From my understanding, the issue with the while statement on line 69 is that it only needs one test. The "&& newWord.key > current.key" is not necessary and makes me think Derek is confused.
      We first use the key values to determine in which position in the theArray to place a string. Once we have that key value or position, then we need to look and see if that position is already filled or if its empty.
      This is where you need to test if "current != null." If it is not null, that indicates a string is ALREADY in that position and tells us that we need to traverse the list until we arrive at the end of the list where we attach our new node. So, as far as I can tell, removing the "&& newWord.key > current.key" should take care of everything.

  • @crotis1000
    @crotis1000 8 років тому

    what would you change in the StringHashFunction method if your words that started with any letter?

  • @24georgeh
    @24georgeh 9 років тому

    thanks!! you really helped me with my English to pirate translator

    • @derekbanas
      @derekbanas  9 років тому

      george hargis That's funny :)

  • @ngInverse
    @ngInverse 11 років тому

    You've really helped a lot!
    I was wondering if you knew of a nice GUI builder for Java that can either run with Eclipse or standalone? I've been trying to manual code but it never looks nice enough for my needs.
    Can't wait for the game programming series either. Keep it up!

  • @ikefalco
    @ikefalco 9 років тому

    dude your amazing im having troubles on finding out how to implement a hash table in disk... you know were can i find an example or imformation about it ?

  • @MrSanwong15
    @MrSanwong15 8 років тому

    Hi, Thanks for the video. I have some questions. Can you define what is current and previous? Is the latest word that is added to the list stay on the top of the list or it is at the bottom of the list. aka. is the next of the oldest word added to the list pointing to NULL? Thanks

  • @stevegalka1720
    @stevegalka1720 10 років тому +1

    Hi Derek, Love the videos, Question though, In the find method you don't actually need to pass in the hash key correct? "&& current.key

  • @Nnoohhaa
    @Nnoohhaa 11 років тому

    hi thank you for ur amazing videos,, Could you please do a video about creating FSM( finite state machines) Codes in JAVA ? like how to create nodes, edges and travel from state to another? Thank you

  • @monome3038
    @monome3038 8 років тому

    hello sir! I really love programming and want to acheive some summer projects just for fun, however, it seems like i mostly don't know where to start nor how much time i should take per day for programming, i saw your website and loved it (specially the psycology part= communication) i was hoping you'd make an article or perhaps just answer me here because i struggle with it loads?! thanks for all the videos, keep going!

    • @derekbanas
      @derekbanas  8 років тому +1

      Here is my detailed Java tutorial ua-cam.com/video/TBWX97e1E9g/v-deo.html Spend 1.5 hours every day learning (no more / no less) and you should be a pretty good programmer in 2 months. I'm also going to start a Python for beginners tutorial very soon that will be very detailed. Don't try to memorize. Write lots of code using the cheat sheets I provide in the descriptions. Feel free to ask questions.

    • @monome3038
      @monome3038 8 років тому

      Thank you so so much sir! very helpful; i'll follow your advices for sur! cannot wait for the new videos :)

  • @faranasiri3978
    @faranasiri3978 10 років тому +1

    i almost watched all your java tutorial videos and i learned a lot, thank you so much sir, just 1 question, do you have a video about hashMap as well? i searched into your website but i didn't find anything, it was all about hash table.

    • @derekbanas
      @derekbanas  10 років тому +2

      You are very welcome :) No I didn't cover HashMaps. I plan on going back and covering everything algorithm and data structure wise that I missed soon.

    • @faranasiri3978
      @faranasiri3978 10 років тому +3

      Derek Banas
      thank you i'm waiting for your new videos impatiently

    • @thales2008
      @thales2008 7 років тому

      i am waiting :P

  • @venicebeachsurfer
    @venicebeachsurfer 10 років тому

    hey, I like your vids... but quick question on hash tables. Why the need to convert the char to a byte before you put into the array. I am amazed that you can't just create a has like so in java... somevar = {'a':'whatever', 'cc':'more'}... like in other languages. seems a LOT of manuevering to get this to just have a collection of name/value pairs. Isn't there an easier way?

  • @0xVantwoutMaarten
    @0xVantwoutMaarten 5 років тому

    Java Hash table 1 & 2 were really Easy and this one is really quite difficult.

  • @sydethsam
    @sydethsam 11 років тому

    This is an awesome tutorial.

  • @Truthiness231
    @Truthiness231 11 років тому

    The ending of this reminds me: this channel could use some debugging and unit testing videos =P

  • @mjbgworld5594
    @mjbgworld5594 10 років тому

    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

  • @topturv528
    @topturv528 8 років тому

    Do you think you could show a tutorial using Java's built-in LinkedList class for creating a hash table?

    • @derekbanas
      @derekbanas  8 років тому +1

      +Julia A. (Rubunyjea) I'll see what I can do. I hope to get back to data structures soon.

  • @RichStoneIO
    @RichStoneIO 8 років тому

    Great third part as well! But why do you want to use your own list for WordList instead of using Java's ArrayList or something?

    • @derekbanas
      @derekbanas  8 років тому

      Thank you :) The idea here is to get better at programming and to learn how to make custom algorithms when a tool isn't already available

    • @RichStoneIO
      @RichStoneIO 8 років тому

      sure! I mean it's cool and very interesting but because we are in the process of learning it may be confusing for some of us if you don't explain it or make analogies to the linked list while coding. Then for someone like me questions arouse like does it really have to be this way? Does it have a special reason? But besides of that it was all perfect!

  • @laurentiulazar1301
    @laurentiulazar1301 10 років тому

    Hello Derek,
    Your tutorials helped me alot. Thanks!
    Still I have a question. Try to put a sysout int the insert method from class WordList, all the words are the first elements. Am I doing something wrong or it's the implementation?

    • @derekbanas
      @derekbanas  10 років тому

      Sorry, but can you show me the code you used?

    • @GabbeSWE0
      @GabbeSWE0 10 років тому

      I get the same problem, in the insert method the (previous == null) will always be true, aswell as the current always being set to null.
      if (previous == null) // is always true
      firstWord = newWord;
      newWord.next = current; // becomes null = null

  • @Back2basics_
    @Back2basics_ 8 років тому +3

    In the WordList.insert method, how are you maintaining an ordering within the List using Word.key?
    Won't Word.key be the same for all elements within a list?

    • @sodatta11
      @sodatta11 8 років тому

      Yes, that part confused me as well.

    • @domd511
      @domd511 8 років тому +2

      StringHashFunction receives a string as input and returns a key based on the characters in that string. The way the algorithm works, things should be ordered alphabetically. 'aa' results in (1 * 27 + 1) % arraysize where as 'ab' results in (1 * 27 + 2) % arraysize. If you examine the function for larger examples you should be able to see that it orders them alphabetically. The hashkey is just the index where the word is stored.

    • @ChumpyZhang
      @ChumpyZhang 7 років тому

      This part confuses me as well!

    • @_avenger9709
      @_avenger9709 7 років тому

      Yeah I do not see how the insert() and find() methods work? The hash table here is essentially an array of linked lists and when you compute a hash key collisions will be appened to the end of the linked list. A collision implies that two or more values at that spot in the array have the same hash key. Thus, there is no need to check the key in the while loops.

  • @xianleiqiu6793
    @xianleiqiu6793 11 років тому

    Eh, I guess there is meaningless to sort by hashkey when inserting a new word to word list, because all the words inserted to the same wordlist have the same hashkey...It's better to sort by string order....Is that right...?

  • @derekbanas
    @derekbanas  11 років тому

    আমি ভিডিও অনুষ্ঠিত বন্ধ যতদিন সম্ভব. আমি ভেবেছিলাম যে যদি আমি এটা করা 9 আপ জিততে পারে. দেখার জন্য ধন্যবাদ. আমি এখন হ্যাশ টেবিল সহ সম্পন্ন am :)

  • @samtux762
    @samtux762 7 років тому

    Awesome debugging!

  • @pizzadispenser1389
    @pizzadispenser1389 7 років тому

    I find your videos to be very helpful, although it feels waaaay to fast for me.

    • @derekbanas
      @derekbanas  7 років тому

      Thank you :) Sorry about the speed. I basically make videos that some times require the pause button

    • @pizzadispenser1389
      @pizzadispenser1389 7 років тому

      You're videos are amazing! I guess you can't make the video too long haha

  • @ahmedsaber1992
    @ahmedsaber1992 6 років тому

    Perfect, really helpful

  • @thatmathbro5732
    @thatmathbro5732 7 років тому

    you are briliant

    • @derekbanas
      @derekbanas  7 років тому

      Thank you for the compliment, but I promise I'm not that smart :)

  • @Nnoohhaa
    @Nnoohhaa 11 років тому

    no worries Thank you

  • @herp_derpingson
    @herp_derpingson 11 років тому

    I dont mean to alarm you but... this language IS my mother tongue and I can actually READ it. LOL
    Apparently even the other guy used google translate and is just messing with you.
    Yeah, google translate isnt particularly reliable when translating Asian languages be it bengali,chinese,japanese etc.

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

    You have a robotic voice😅. And thanx for the amazing video.

  • @yevgeniyv.87
    @yevgeniyv.87 6 років тому

    Nice on-the-spot implementation but its lacking explanation. Unfortunately results in a video of you just telling what code you're typing up. But thank you for the video it was still helpful.

  • @herp_derpingson
    @herp_derpingson 11 років тому

    For me it was hilarious to read the mistranslation XD

  • @derekbanas
    @derekbanas  11 років тому

    Door :)

  • @123japanuser
    @123japanuser 11 років тому

    হ্যালো প্রিয় কোচ,
    আশা করি আপনি ভাল করছেন.
    সবে মঁচ একটি ব্রোঞ্জ :) সাথে পেতে পরিচালিত
    ধন্যবাদ আপনার সাহায্য আমি সহজে হ্যাশ টেবিল করতে পারবে.
    তলা সব কি ভাল ফলাফল.

  • @MegaVuhung
    @MegaVuhung 11 років тому

    never mind! i fixed it

  • @aggelikisampsaki
    @aggelikisampsaki 5 років тому

    hashKey...ASCII :o

  • @derekbanas
    @derekbanas  11 років тому

    You may like my tutorial on the state design pattern newthinktank. com/2012/10/state-design-pattern-tutorial/
    Ill be doing another tutorial on algorithms soon