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

  Рет қаралды 42,753

Pepcoding

Pepcoding

Күн бұрын

Please consume this content on nados.pepcoding.com for a richer experience. It is necessary to solve the questions while watching videos, nados.pepcoding.com enables that.
NADOS also enables doubt support, career opportunities and contests besides free of charge content for learning. In this video, we have explained the implementation of Hashmap in Java.
For a better experience and more exercises, VISIT: www.pepcoding....
#pepcoding #java #programming
Have a look at our result: www.pepcoding....
Follow us on our FB page: / pepcoding
Follow us on Instagram: / pepcoding
Follow us on LinkedIn: / pepcoding-education
Join us on Telegram: t.me/joinchat/...

Пікірлер: 87
@adarshverma5048
@adarshverma5048 3 жыл бұрын
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 3 жыл бұрын
Glad it was helpful!
@jamariarian5769
@jamariarian5769 3 жыл бұрын
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 3 жыл бұрын
One of the most under rated channel on youtube
@Pepcoding
@Pepcoding 3 жыл бұрын
With the love and respect and support from you people one day we will reach heights and touch the sky.
@SouravKumar-tc2ql
@SouravKumar-tc2ql 5 ай бұрын
please explain hashcode function internally
@anilgola5879
@anilgola5879 10 ай бұрын
I know nados down hai, it would be great if u release ur test cases
@user-gq1ij
@user-gq1ij Жыл бұрын
Sir Priority queue/ heap pr bhi ek video aa jati to maza aa jata
@prithvirajpatil8150
@prithvirajpatil8150 3 жыл бұрын
This question was asked to me in the Cognizant (GenC next ) technical round.
@kumarinidhi90
@kumarinidhi90 3 жыл бұрын
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...
@rohanjaiswal64
@rohanjaiswal64 3 жыл бұрын
LIKE TRUST ME SUMEET SIR , NO ONE TEACHES DSA LIKE YOU . AMAZING ..
@DeepakGupta-zz1vf
@DeepakGupta-zz1vf 3 жыл бұрын
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 3 жыл бұрын
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 3 жыл бұрын
@@Pepcoding yes sir joined👍
@dakshiaggarwal9627
@dakshiaggarwal9627 4 жыл бұрын
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 жыл бұрын
hanji wahi karenge abhi.
@sudhanshusharma9123
@sudhanshusharma9123 3 жыл бұрын
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 3 жыл бұрын
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 3 жыл бұрын
@@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.
@sauravkumarsonu829
@sauravkumarsonu829 3 жыл бұрын
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 жыл бұрын
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 kzbin.infoabout?view_as=subscriber
@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
@anushakalyanimuttu145
@anushakalyanimuttu145 4 ай бұрын
BEST
@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
@manishshekhar4950
@manishshekhar4950 4 жыл бұрын
Good Going sir...Plese complete next in row sir.... I'm very thank full for you ,for this effort sir..
@Pepcoding
@Pepcoding 4 жыл бұрын
I will try my best
@narendrakothamire2679
@narendrakothamire2679 2 жыл бұрын
Very nice explanation, only one suggestion keySet() method should return set instead of list
@saurabhtrigunayat4071
@saurabhtrigunayat4071 Жыл бұрын
Huge respect for Sumit sir for such a great explanation 🙏🙏🙏🙏🙏🙏.
@gurendersingh8867
@gurendersingh8867 3 жыл бұрын
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 - kzbin.infoplaylists?view_as=subscriber
@shivanichaudhary711
@shivanichaudhary711 3 жыл бұрын
Superb!!!!!!!!! Thank you so much..Where can we find the source code sir?
@azazul_haque
@azazul_haque Жыл бұрын
Thanks Sumit sir, It was really helpful
@sukanyasinha3583
@sukanyasinha3583 3 жыл бұрын
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????
@kaushikrishi01
@kaushikrishi01 4 жыл бұрын
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 жыл бұрын
Hanji. Yahan bhi Oct-Nov-Dec mei sara C++ mei dalega.
@CuriousAnonDev
@CuriousAnonDev 2 жыл бұрын
exactly what I was looking for Thanks sir, these lectures are amazing!!!!!
@kavachtales9252
@kavachtales9252 3 жыл бұрын
Sir your videos are like the vaccine to the corona(Data Structure)
@Pepcoding
@Pepcoding 3 жыл бұрын
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
@dheerajchhatani3580
@dheerajchhatani3580 3 жыл бұрын
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?
@Pepcoding
@Pepcoding 3 жыл бұрын
For both interview and explanation.
@dheerajchhatani3580
@dheerajchhatani3580 3 жыл бұрын
Ok ty sir
@apoorvamittal4112
@apoorvamittal4112 4 жыл бұрын
Sir, can you also share the design rules of the hashmap, like should not be address based?
@Pepcoding
@Pepcoding 4 жыл бұрын
Will make a video on that as well beta
@pranshulkharniwal8146
@pranshulkharniwal8146 3 жыл бұрын
bhagwAN ksm pura dimag hill gya but smj aa gya saara✨
@akshaynilkanth9671
@akshaynilkanth9671 4 жыл бұрын
kadak....
@sukanyasinha3583
@sukanyasinha3583 3 жыл бұрын
Sir rehashing krne se toh performance degrade hoti hai na??
@shoaibakhtar9194
@shoaibakhtar9194 2 жыл бұрын
This is the best explanation that I've ever seen on HashMap implementation. You made it so easy, Sir
@kushagraahire1871
@kushagraahire1871 Жыл бұрын
Crystal Clear Explanation.
@PankajDas-mw4uq
@PankajDas-mw4uq 4 жыл бұрын
Sir bucket Ka size or lambda ki value kuch bhi le skte hain na?
@Pepcoding
@Pepcoding 4 жыл бұрын
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
@akatsuki1363
@akatsuki1363 3 жыл бұрын
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 )
@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 )
@saksham41592
@saksham41592 4 жыл бұрын
code share kardo sir ye wala
@Pepcoding
@Pepcoding 4 жыл бұрын
beta yahan hashmap wale lecture mei hai code. www.pepcoding.com/resources/online-java-foundation
@jobanpreetsingh2370
@jobanpreetsingh2370 3 жыл бұрын
Bhari swaal.😷😷
@LegitGamer2345
@LegitGamer2345 3 жыл бұрын
neat!
@Pepcoding
@Pepcoding 3 жыл бұрын
Thankyou!
@sukanyasinha3583
@sukanyasinha3583 3 жыл бұрын
Great explanation sir.
@rohit8021
@rohit8021 2 жыл бұрын
Incredible
@SumitKumar-sx1oi
@SumitKumar-sx1oi 3 жыл бұрын
mast hai re baba
@harshitkaushik4144
@harshitkaushik4144 3 жыл бұрын
Amazing sir
@Pepcoding
@Pepcoding 3 жыл бұрын
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)
@rahulbhatia3075
@rahulbhatia3075 4 жыл бұрын
Great explaination sir
@rahulbhatia3075
@rahulbhatia3075 4 жыл бұрын
Sir how do we decide that what should be the best value for lambda?
@Pepcoding
@Pepcoding 4 жыл бұрын
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.
@kushagrashekhawat8227
@kushagrashekhawat8227 3 жыл бұрын
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
@anjneykumarsingh4461
@anjneykumarsingh4461 3 жыл бұрын
Bhut hard
@rahuluprety2740
@rahuluprety2740 2 жыл бұрын
Summet sir best
@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 )
@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
@apoorvamittal4112
@apoorvamittal4112 4 жыл бұрын
Thank you sir!!
@Pepcoding
@Pepcoding 4 жыл бұрын
Arey, you are checking the videos! Most welcome.
@anjneykumarsingh4461
@anjneykumarsingh4461 4 жыл бұрын
Didi made my life to connect with sumeet sir thanku di
@apoorvamittal4112
@apoorvamittal4112 4 жыл бұрын
@@anjneykumarsingh4461thank you, all the best ♥️ 😊😊
@apoorvamittal4112
@apoorvamittal4112 4 жыл бұрын
@@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?
@apoorvdixit2856
@apoorvdixit2856 4 жыл бұрын
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.
Остановили аттракцион из-за дочки!
00:42
Victoria Portfolio
Рет қаралды 3,9 МЛН
БЕЛКА СЬЕЛА КОТЕНКА?#cat
00:13
Лайки Like
Рет қаралды 2,8 МЛН
Every parent is like this ❤️💚💚💜💙
00:10
Like Asiya
Рет қаралды 18 МЛН
12. Hashmap Internal Implementation in java  | Hashmap in java | Implementing your HashMap in Java
30:09
Introduction to HashMap & HashTable in Java
1:39:46
Kunal Kushwaha
Рет қаралды 103 М.
01. Internal Working of HashMap & Java-8 Enhancement
19:11
Ankit Wasankar
Рет қаралды 115 М.
Остановили аттракцион из-за дочки!
00:42
Victoria Portfolio
Рет қаралды 3,9 МЛН