How to implement Hashmap in Java | Hashmap and Heap | Data Structure and Algorithms in JAVA

แชร์
ฝัง
  • เผยแพร่เมื่อ 22 ธ.ค. 2024

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

  • @adarshverma5048
    @adarshverma5048 4 ปีที่แล้ว +42

    Man! I have been watching all these playlists lately, I have an amazon interview scheduled soon. And this is the best online content available. Thank You so much for contributing such great explanations and concepts.

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

      Glad it was helpful!

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

      i guess Im quite randomly asking but do anybody know of a good website to stream new series online ?

    • @jamariarian5769
      @jamariarian5769 3 ปีที่แล้ว

      @Wayne Vihaan thanks, signed up and it seems like they got a lot of movies there :D I really appreciate it!!

    • @waynevihaan5742
      @waynevihaan5742 3 ปีที่แล้ว

      @Jamari Arian no problem :)

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

      How was your interview and what are you doing right now?

  • @raghavgarg8024
    @raghavgarg8024 4 ปีที่แล้ว +19

    One of the most under rated channel on youtube

    • @Pepcoding
      @Pepcoding  4 ปีที่แล้ว +13

      With the love and respect and support from you people one day we will reach heights and touch the sky.

  • @lovenagpal.6504
    @lovenagpal.6504 2 หลายเดือนก่อน

    ek number bhai , y bilkul ek line m bta dta hai jha time waste ni krna chaiye

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

    Before watching this video, I was like hashmap is too much scary, but after watching this I'm confident enough.Thank you so much sir🙏

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

      I am glad you liked it. I also hope that you are watching till end and trying to understand the what, how and especially why of the problem.
      If you like our efforts, we request a review
      g.page/Pepcoding/review?rc
      You can subscribe to our channel here
      th-cam.com/users/Pepcodingabout?view_as=subscriber

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

    This is the best explanation I have seen in all the videos so far on HASHMAP Implementations.
    Thank you so much !

    • @Pepcoding
      @Pepcoding  3 ปีที่แล้ว

      If you like the content could you post something on LinkedIn about us? This will help us in reaching out to more people and help a lot of other students as well
      Something like this
      Sumeet Malik from Pepcoding is making all his content freely available to the community
      You can check it out here - www.pepcoding.com/resources
      /
      Also, this is the youtube channel - th-cam.com/users/Pepcodingplaylists?view_as=subscriber

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

    Huge respect for Sumit sir for such a great explanation 🙏🙏🙏🙏🙏🙏.

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

    Thank you so much sir for such a deep analysis of implementation of Hashmap. It took some time to completely understand, analyze and then implement the complete Hashmap but now it feels like an achievement ❤

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

      I am glad. Your kind words are the kind of motivation that truly help me in making more and more content. Especially, these days, not everybody is generous with motivating anybody either. It means a lot.
      If you like our efforts, will you like to write a few words about us here (www.quora.com/How-do-I-start-learning-or-strengthen-my-knowledge-of-data-structures-and-algorithms )

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

      @@Pepcoding Thankyou so much Sir ❤
      Yes Sir, surely I will write what all I have experienced and how confidently I can recommend Pepcoding to everyone. Although I am still not qualified enough to give an answer.

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

    LIKE TRUST ME SUMEET SIR , NO ONE TEACHES DSA LIKE YOU . AMAZING ..

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

    Crystal Clear Explanation.

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

    This is the best explanation that I've ever seen on HashMap implementation. You made it so easy, Sir

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

    This question was asked to me in the Cognizant (GenC next ) technical round.

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

    thank you so much sir...wonderfully explained the concept.
    i have a request to you.. please make a playlist in which all the data structures will be implemented like hashmap...

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

    exactly what I was looking for
    Thanks sir, these lectures are amazing!!!!!

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

    Thanks Sumit sir, It was really helpful

  • @jobanpreetsingh2370
    @jobanpreetsingh2370 3 ปีที่แล้ว

    Bhari swaal.😷😷

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

    Good Going sir...Plese complete next in row sir....
    I'm very thank full for you ,for this effort sir..

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

      I will try my best

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

    Great explanation🤯👌

    • @Pepcoding
      @Pepcoding  3 ปีที่แล้ว

      Glad it was helpful! and If you like our efforts, please upvote the comments written by the students about Pepcoding here (www.quora.com/What-are-the-good-websites-to-learn-data-structures-and-algorithms )

  • @SouravKumar-tc2ql
    @SouravKumar-tc2ql 8 หลายเดือนก่อน +1

    please explain hashcode function internally

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

    Very nice explanation, only one suggestion keySet() method should return set instead of list

  • @DeepakGupta-zz1vf
    @DeepakGupta-zz1vf 4 ปีที่แล้ว +2

    what if hash code returns -2^31 viz INT_MIN value in java if we perform Math.abs on that we will get 2^31 but INT_MAX in java is 2^31-1 due to which we will get integer overflow in this am i right????

    • @Pepcoding
      @Pepcoding  4 ปีที่แล้ว

      Beta, I regret to inform you that, I won't be able to answer/solve the personal doubts of each and every student over here. For clearing your doubts, you can join our community on telegram - t.me/pepcoding.

    • @DeepakGupta-zz1vf
      @DeepakGupta-zz1vf 4 ปีที่แล้ว

      @@Pepcoding yes sir joined👍

  • @sukanyasinha3583
    @sukanyasinha3583 4 ปีที่แล้ว

    Sir load factor ki value generally hm kya rakh sakte hain??? default toh 0.75 hoti na??? nd array ki size default agar 16 hui it seems that ki 2^ power me hi increse hogi it means next hui to 2^5 i.e 32 hogi na????

  • @pranjalsharma499
    @pranjalsharma499 3 ปีที่แล้ว

    Great teaching Style, Thanks Sir!

    • @Pepcoding
      @Pepcoding  3 ปีที่แล้ว

      Glad to know that you liked the content and thank you for appreciating. If you like our efforts, will you like to write a few words about us here (www.quora.com/How-do-I-start-learning-or-strengthen-my-knowledge-of-data-structures-and-algorithms )

  • @user-gq1ij
    @user-gq1ij 2 ปีที่แล้ว +1

    Sir Priority queue/ heap pr bhi ek video aa jati to maza aa jata

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

    I know nados down hai, it would be great if u release ur test cases

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

    Great explaination sir

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

      Sir how do we decide that what should be the best value for lambda?

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

      Java keeps a lambda of 0.5 (I don't know the reason why)
      I think lambda is a constant. As long as we keep a constant as lambda, we are going to get a theoretical average case complexity of a constant.

  • @pranshulkharniwal8146
    @pranshulkharniwal8146 3 ปีที่แล้ว

    bhagwAN ksm pura dimag hill gya but smj aa gya saara✨

  • @NirmalSilwal
    @NirmalSilwal 3 ปีที่แล้ว

    wow, such a great explanation I could ever get on the topic

    • @Pepcoding
      @Pepcoding  3 ปีที่แล้ว

      Thankyou beta!
      I am glad you liked it. I hope that you are watching till the end and trying to understand what, how, and especially why of the problem.
      If you like our efforts, will you like to write a few words about us here (www.quora.com/What-are-the-good-websites-to-learn-data-structures-and-algorithms )

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

    Incredible

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

    Summet sir best

  • @sukanyasinha3583
    @sukanyasinha3583 4 ปีที่แล้ว

    Great explanation sir.

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

    sir..plss complete dynamic programming playlist first..as placements have started nd i fear dp the most...ur videos are helping me..plss complete it first..

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

      hanji wahi karenge abhi.

  • @PankajDas-mw4uq
    @PankajDas-mw4uq 4 ปีที่แล้ว +1

    Sir bucket Ka size or lambda ki value kuch bhi le skte hain na?

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

      ji. Java lambda ko 0.5 rakhti hai aur initial bucket array 16 length ka. Uske peeche ka reason mujhe maloom nahi.

    • @PankajDas-mw4uq
      @PankajDas-mw4uq 4 ปีที่แล้ว

      @@Pepcoding ok sir

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

    sir rehash func me size zero kyu kara h. Agar hm insert krte h or rehash ho jaata h to size bn jaayega. Fir size func size 0 return krega jo ki glt h

  • @sukanyasinha3583
    @sukanyasinha3583 4 ปีที่แล้ว

    Sir rehashing krne se toh performance degrade hoti hai na??

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

    Amazing sir

    • @Pepcoding
      @Pepcoding  4 ปีที่แล้ว

      Thankyou beta!
      I am glad you liked it.
      Will you like to write a few words about us here (www.quora.com/What-are-the-good-websites-to-learn-data-structures-and-algorithms)

  • @SumitKumar-sx1oi
    @SumitKumar-sx1oi 3 ปีที่แล้ว

    mast hai re baba

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

    Great explanation sir!!Do these type of questions in which construction of data structures is involved come in interview or they are for explanation purpose?

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

    Sir, can you also share the design rules of the hashmap, like should not be address based?

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

      Will make a video on that as well beta

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

    bhaiyya wo intro video mein aapne bola tha ki class mein to cpp mein sare revise karwadenge yt mein bh i aap karwaenge?

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

      Hanji. Yahan bhi Oct-Nov-Dec mei sara C++ mei dalega.

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

    Thank you sir!!

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

      Arey, you are checking the videos! Most welcome.

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

      Didi made my life to connect with sumeet sir thanku di

    • @apoorvamittal4112
      @apoorvamittal4112 4 ปีที่แล้ว

      @@anjneykumarsingh4461thank you, all the best ♥️ 😊😊

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

      @@Pepcoding yes sir, was looking for hashmap implemention everywhere, just when this video popped up! 😊

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

      @@apoorvamittal4112 Hello Mam, are you that same girl in who is placed Atllasian?

  • @kushagrashekhawat8227
    @kushagrashekhawat8227 4 ปีที่แล้ว

    Sir size kyo zero kiya yeh toh aap batana hi bhul gye, 37:49

    • @divyanshacharya3796
      @divyanshacharya3796 3 ปีที่แล้ว

      put function increases size as new nodes get added

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

    BEST

  • @shivanichaudhary711
    @shivanichaudhary711 3 ปีที่แล้ว

    Superb!!!!!!!!! Thank you so much..Where can we find the source code sir?

  • @anjneykumarsingh4461
    @anjneykumarsingh4461 4 ปีที่แล้ว

    Bhut hard

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

    Sir your videos are like the vaccine to the corona(Data Structure)

    • @Pepcoding
      @Pepcoding  4 ปีที่แล้ว

      Hahaha, thankyou beta.
      I am glad you liked it. I also hope that you are watching till end and trying to understand the what, how and especially why of the problem.
      If you like our efforts, we request a review - g.page/Pepcoding/review?rc

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

    kadak....

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

    neat!

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

    code share kardo sir ye wala

    • @Pepcoding
      @Pepcoding  4 ปีที่แล้ว

      beta yahan hashmap wale lecture mei hai code.
      www.pepcoding.com/resources/online-java-foundation

  • @faizan346
    @faizan346 3 ปีที่แล้ว

    //thank you sir, here is my c++ implementation, please inform me if found errors i haven't tested it hard.
    template
    class HashMmap {
    private:
    class HMNode {
    public:
    K key;
    V value;
    HMNode(K k, V v) {
    key = k;
    value = v;
    }
    };
    int sizeHM;
    list *buckets;
    void initBuckets(int bucketSize) {
    buckets = new list[bucketSize];
    }
    int hashfn(K key) {
    hash hashFunction;
    size_t hc = hashFunction(key);
    return hc % bucketCount;
    }
    int getIndWithInBucket(K key, int bi) {
    int di = 0;
    for(HMNode node : buckets[bi]) {
    if(node.key == key) {
    return di;
    }
    di++;
    }
    return -1;
    }
    void rehash() {
    int oldBucketCount = bucketCount;
    list *oldBuckets = buckets;
    bucketCount = oldBucketCount*2;
    initBuckets(bucketCount);
    sizeHM = 0;
    for(int i = 0; i < oldBucketCount; i++) {
    for(auto node : oldBuckets[i]) {
    insert(node.key, node.value);
    }
    }
    delete[] oldBuckets;
    }
    public:
    int bucketCount;
    HashMmap() {
    bucketCount = 4;
    initBuckets(bucketCount);
    sizeHM = 0;
    }
    void insert(K key, V value) {
    int bi = hashfn(key);
    int di = getIndWithInBucket(key, bi);
    if(di != -1) {
    auto it = buckets[bi].begin();
    advance(it, di);
    HMNode &node = *it;
    node.value = value;
    } else {
    HMNode node(key, value);
    buckets[bi].push_back(node);
    sizeHM++;
    }
    double lambda = sizeHM * 1.0 / bucketCount;
    if(lambda > 2.0) {
    rehash();
    }
    }
    V at(K key) {
    int bi = hashfn(key);
    int di = getIndWithInBucket(key, bi);
    if(di != -1) {
    auto it = buckets[bi].begin();
    advance(it, di);
    HMNode &node = *it;
    return node.value;
    } else {
    cout

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

    sir apne implementation of hashmap jaldi jaldi mei nipta diya, acchi feel nahi aayi ismei, apko iski 10 vedio ki playlist banani chahiye thi, usmei phle hashing algorithm ka thoda sa part, fir hash code kaise kaam karta hai, load factor kaise optimize kar deta data structure ko, ismei hum basiclly array ki searching property jo ki O(1) mei hoti hai uske basis par isko built kar rahen hain, yeh sab achhi feel de deta topic ki, bhagwaan kasam maza hee aa jata.

  • @Andrew-ez9ft
    @Andrew-ez9ft 3 ปีที่แล้ว

    Please speak English

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

      Hi Andrew, the same content in Also available in English in c++, java or python. On nados web site for free. If you need help let me know