Few other questions I have come across which everyone should prepare beforehand: 1. What is bucketing in hashmap ? 2. What is loadfactor ? 3. Why hashmap is not recommended in a multi threaded environment ? 4. Implement a hashmap using custom class as key 5. is it mandatary to override equals and hashcode method ? What will happen if not overridden ? 6. What is the difference between hashmap and concurrent hashmap also explain the working of concurrent hashmap .
@mohammadfaizanhashmi42133 жыл бұрын
thanx a lot bro, bohot bohot shukriya bhaijan,,,maine noten kr lia hai
@frankfernandes7183 жыл бұрын
woh jo table tha red me 9:57 woh bucket hai
@pankajchaudhari24132 жыл бұрын
Bucketing is nothing but index of that node Array Hashmap doesn't contain synchronized method or variable , that's y it is not thread safe, overcome to resolve this problem we are having HashTable (as it contains all synchronized method)
@Basukinathkr2 жыл бұрын
Great Amit. For people who are looking here for the answers - Buckets are basically the area that contains values. Loadfactor is the threshold for the percentage of the bucket when it is decided that now bucket is going to be full and then the capacity is doubled. By default, loadfactor is 75% and capacity is 16. Totally configurable via constructor. The reason a hashmap isn't recommended in a MT env because when multiple threads start to access the data while some thread is updating it, there can be issues. Whenever overriding equals, it is mandatory to override hashCode so that every time when equals is called, the values generated by hashCode remain consistent. Rest 4 and 6 are explanatory. Can be looked on internet. Easy stuff.
@AI_for_funn Жыл бұрын
Bucketing in HashMap is the process of storing multiple values in a single location (bucket) of the internal array of the HashMap, which is indexed using a hash function. The hash function calculates the hash code of the key and uses it as an index in the array. If multiple keys have the same hash code, they are stored in the same bucket as linked nodes. Load factor is a measure of how full a HashMap is allowed to get before its capacity is automatically increased. It is a float value that ranges from 0.0 to 1.0. When the number of entries in the HashMap exceeds the load factor multiplied by the current capacity, the capacity is increased, and the entries are rehashed. HashMap is not recommended in a multi-threaded environment because it is not thread-safe. If multiple threads access a HashMap concurrently, it may result in an inconsistent state of the HashMap, leading to data loss or unexpected results. ConcurrentHashMap is recommended for use in a multi-threaded environment. Here's an example implementation of a HashMap using a custom class as a key: class Person { private String name; private int age; public Person(String name, int age) { this.name = name; this.age = age; } // getters and setters @Override public int hashCode() { return Objects.hash(name, age); } @Override public boolean equals(Object o) { if (this == o) return true; if (!(o instanceof Person)) return false; Person person = (Person) o; return age == person.age && Objects.equals(name, person.name); } } class CustomHashMap { private List[] buckets; private int capacity; private int size; private static class Entry { K key; V value; public Entry(K key, V value) { this.key = key; this.value = value; } // getters and setters } public CustomHashMap(int capacity) { this.buckets = new List[capacity]; this.capacity = capacity; this.size = 0; } public void put(K key, V value) { int index = key.hashCode() % capacity; if (buckets[index] == null) { buckets[index] = new LinkedList(); } for (Entry entry : buckets[index]) { if (entry.key.equals(key)) { entry.value = value; return; } } buckets[index].add(new Entry(key, value)); size++; } public V get(K key) { int index = key.hashCode() % capacity; if (buckets[index] == null) { return null; } for (Entry entry : buckets[index]) { if (entry.key.equals(key)) { return entry.value; } } return null; } public int size() { return size; } // other methods } It is highly recommended to override the equals() and hashCode() methods when using custom objects as keys in a HashMap. If these methods are not overridden, the default implementations in the Object class are used, which compares object references rather than object contents. This can lead to unexpected behavior, where two objects that are considered equal by their contents are not considered equal by the HashMap. As a result, the HashMap may not be able to retrieve the values correctly.
@AI_for_funn Жыл бұрын
Bucketing in HashMap is the process of storing multiple values in a single location (bucket) of the internal array of the HashMap, which is indexed using a hash function. The hash function calculates the hash code of the key and uses it as an index in the array. If multiple keys have the same hash code, they are stored in the same bucket as linked nodes. Load factor is a measure of how full a HashMap is allowed to get before its capacity is automatically increased. It is a float value that ranges from 0.0 to 1.0. When the number of entries in the HashMap exceeds the load factor multiplied by the current capacity, the capacity is increased, and the entries are rehashed. HashMap is not recommended in a multi-threaded environment because it is not thread-safe. If multiple threads access a HashMap concurrently, it may result in an inconsistent state of the HashMap, leading to data loss or unexpected results. ConcurrentHashMap is recommended for use in a multi-threaded environment. Here's an example implementation of a HashMap using a custom class as a key: class Person { private String name; private int age; public Person(String name, int age) { this.name = name; this.age = age; } // getters and setters @Override public int hashCode() { return Objects.hash(name, age); } @Override public boolean equals(Object o) { if (this == o) return true; if (!(o instanceof Person)) return false; Person person = (Person) o; return age == person.age && Objects.equals(name, person.name); } } class CustomHashMap { private List[] buckets; private int capacity; private int size; private static class Entry { K key; V value; public Entry(K key, V value) { this.key = key; this.value = value; } // getters and setters } public CustomHashMap(int capacity) { this.buckets = new List[capacity]; this.capacity = capacity; this.size = 0; } public void put(K key, V value) { int index = key.hashCode() % capacity; if (buckets[index] == null) { buckets[index] = new LinkedList(); } for (Entry entry : buckets[index]) { if (entry.key.equals(key)) { entry.value = value; return; } } buckets[index].add(new Entry(key, value)); size++; } public V get(K key) { int index = key.hashCode() % capacity; if (buckets[index] == null) { return null; } for (Entry entry : buckets[index]) { if (entry.key.equals(key)) { return entry.value; } } return null; } public int size() { return size; } // other methods } It is highly recommended to override the equals() and hashCode() methods when using custom objects as keys in a HashMap. If these methods are not overridden, the default implementations in the Object class are used, which compares object references rather than object contents. This can lead to unexpected behavior, where two objects that are considered equal by their contents are not considered equal by the HashMap. As a result, the HashMap may not be able to retrieve the values correctly.
@tech_wizard93153 жыл бұрын
Please add questions for every video of DSA course which would be enough to crack tech giant's for beginners
@DensonGeorge183 жыл бұрын
I am not a beginner. I still find the DSA 1 series very helpful to revise the concepts and learn new things for interviews.
@GuruPrasadShukla2 жыл бұрын
best video on hashmaps in whole coder community!
@nandabawane91173 жыл бұрын
No wondor.... Your Videos are always be useful...
@anujpotdar35292 жыл бұрын
I was asked this yesterday, could not answer. I started searching for solutions, most of them were too long and difficult to understand. This one taught the concept very well, keep such awesome videos, and more power to you Anuj!
@AnujBhaiya2 жыл бұрын
Thanks Anuj ♥️
@tanmoydutta58462 жыл бұрын
I was also asked the internal implementation of this in JPMC interview (technical round).
@chetantailor36203 жыл бұрын
Another worth 16 minutes 👌💫
@awwush3 жыл бұрын
are Abhi aapka hi videos dekhra tha ARRAYS superb!!
@Vishal-2423 жыл бұрын
Most clear explanation I have seen
@itsShashwat3 жыл бұрын
Great video @Anuj Bhaiya
@surajdhotre28893 жыл бұрын
U really gr8 bhaiya.Your video hleping me a lots....god bless u 😇
@factsEcho--3 жыл бұрын
Yes video was helpful 🙂🙂
@vivekshokeen11923 жыл бұрын
YES, IT WAS HELPFUL! bhaiya
@ShankarKumar-ko8lt2 жыл бұрын
This video is very Helpful for me Thank you Anuj Bhaiya.
@tsp573 ай бұрын
Beautifully exlpained!
@shivisharma42673 жыл бұрын
Bhaiya please make a video on roadmap to cloud computing🙏🙏🙏
@rameezkhan22202 жыл бұрын
The way of explanation is excellent👌👌👌
@gmanikantasai36558 ай бұрын
Awesome explanation brother💯💯
@AjayKumar-tl1qy2 жыл бұрын
Calculating hash and index number are two different things while putting value in the hash map. for index calculation hash map uses (n-1) & hash where n is bucket length. its never uses hash as index number.
@sachingl42662 жыл бұрын
Thanks
@unboxingsillystuffs49202 жыл бұрын
Thank you Anuj..you explained very well.
@sonam35312 жыл бұрын
Thanks , it was good information.
@sumeet115 Жыл бұрын
Great explanation. Thanks 👍 ..
@ashwithchandra26222 жыл бұрын
thanks bhayya nice explanation😘
@agyaani80603 жыл бұрын
Thankuu so much bhaiya❤❤
@aishapi632010 ай бұрын
Awesome content and presentation
@shubhammahawar62062 жыл бұрын
Thanks for explaining.
@antorsaha60653 жыл бұрын
Thank you bhaiya for this series. This is most useful dsa series.😍
@AnujBhaiya3 жыл бұрын
You're welcome ☺️
@venkatasaikrishnamarri11582 жыл бұрын
perfect tutorial
@sathishrajasekar11553 жыл бұрын
Thank you Anuj, The Video was helpful.
@richasharma63613 жыл бұрын
Hello bhaiya, bhaiya bug bounting ke uper video bhi banye with practical knowledge
@chaitanyaasati3 жыл бұрын
Yeah, It helped to understand the concept.
@AbhayKumar-lb6fl3 жыл бұрын
Yes, it was helpful.
@kalpeshsaubhri Жыл бұрын
Bhai end me jo BST wala concept btaya usse maja aa gya.
@acoustic_ng87063 жыл бұрын
Very helpful ! Thank you Anuj bhai !
@gauravkhare18364 ай бұрын
Yes, it is very helpful
@87507956552 жыл бұрын
Great, very well and easily explained
@mousumi7213 жыл бұрын
Thank you bhaiya for this series🌸.i'm really grateful.
@rajanwalia4tech3 жыл бұрын
I didn't knew about that java8 implement hashmap using self balancing BST. Yes video was helpful.
@devendersinghrathore88372 жыл бұрын
Yes. It is really helpful.
@ashutoshpandey41713 жыл бұрын
Thanks for the effort, anuj bhaiya
@kashisharora10182 жыл бұрын
Very nice explanation
@raghavendraraviteja10552 жыл бұрын
Thanks, it is helpful
@ZSHADOW183 жыл бұрын
16:24 the video was not helpful but DAMM HELPFUL !
@er.skelafahmed3 жыл бұрын
Yes bhaiya its really helpful thank you 😀
@pareeks2 жыл бұрын
Great video. Two things TBC: 1. New values are pre-appended, not appended at end. 2. In case of collision in get(Key), value is not checked for equals() but key is checked.
@nishantaggarwal8303 жыл бұрын
It was very interesting and helpful
@dharmeshkhasiya67372 жыл бұрын
Thanks for explaining
@mruduladdipalli54172 жыл бұрын
EK Number Bhai
@jiteshjs994 ай бұрын
Great explanation :)
@learntocode80003 жыл бұрын
Yes, It was Helpful
@rahulsrivastava10403 жыл бұрын
Anuj bhaiya op❣️❣️
@shriduttpatel13502 жыл бұрын
Thank you @Anuj bhaia. It was really help full. Please do not stop making videos like this😀.
@AnujBhaiya2 жыл бұрын
If it was really helpful, I will never stop making videos like this 🤗
@YashvardhanBaid Жыл бұрын
Amazing explanation, thanks man!
@ritikarai12323 жыл бұрын
Yes it was helpful😁
@stith_pragya Жыл бұрын
Thank You So Much bhaiya,............🙏🙏🙏
@jainikprajapati16322 жыл бұрын
Yes it is useful 👍 thanks 😀
@madhusmitamishra78013 жыл бұрын
Watched this before 15mins of my interview and interviewer asked the same question. Thank you ☺️.
@mrityunjoybarman90983 жыл бұрын
You always make helpful videos vaiya...
@RupeshYadav-kt5dv Жыл бұрын
Good job 👏 👍 👌
@TheCultureCraze233 жыл бұрын
great bhaiya
@keshav19_203 жыл бұрын
Nice bhaiya Bhaiya linked list kb se chalu ho gi??
@meetsoni19382 жыл бұрын
Yes it is helpful 😃
@swati09093 ай бұрын
Awesome 👍
@surajchavan10002 жыл бұрын
Yes, very helpful
@PAWANKUMAR-el2zk3 жыл бұрын
Bhaiya make more such kind of videos on all collection's or tree👍🏻
@shashwatmishra7056 Жыл бұрын
A guy from Amazon Seattle, Washington, interviewed me today asked me the same concept
@Naveenkumar-qs1qd3 ай бұрын
sandar jabardast jinda baad
@abilashappat96403 жыл бұрын
Very helpful indeed
@surajwaghmare4653 Жыл бұрын
Very Helpful
@AhamedKabeer-wn1jb3 жыл бұрын
Thank you Bhaiya..
@anupamdubey57363 жыл бұрын
😯😯Where's that CAP/BEANIE! Loved the explanation!!❤❤
@ranjeet58062 жыл бұрын
Great explanation, really helpful.
@nitin58653 жыл бұрын
Perfectly explained 👍
@anuj59272 жыл бұрын
Yes it was helpful :)
@shashwatsharma99043 жыл бұрын
next video pls make on working of hashset
@nileshmutthe54572 жыл бұрын
This was helpful
@nandiniverma52732 жыл бұрын
It was helpful , Thankyou for deep Knowledge
@itz_me_imraan023 жыл бұрын
The videos are too gud... Plz try to maintain consistency in DSA course🙏🙏...
@codehustler85822 жыл бұрын
YES IT HELPS
@thebugger7269 Жыл бұрын
Sir please make a video on hash mam and concurrent hash map how perform different internally
@arre_amay3 жыл бұрын
maza aa gaya bhai
@harshitsrivastava99033 жыл бұрын
Thanks a lot !!
@deev10322 жыл бұрын
very helpful
@av9810 ай бұрын
Helpful
@sumitrana26283 жыл бұрын
Very helpful 🙂👍🏻
@vaibhavsomani51613 жыл бұрын
Hash Code is basically the Memory Reference of that object so what is need for doing the hashing by Modulo and all.
@AdityaKumar-ic8wz3 жыл бұрын
Make a video for beginners On how to become a free lancer
@CHALLENGESTORY Жыл бұрын
2:05 ye sare k sare operation aapke "Big O of 1" bola kya?
@ankitdubey68133 жыл бұрын
This series is the most useful ❤
@himanshusinghparmar58162 жыл бұрын
yes it was helpful
@samridhisinha82253 жыл бұрын
too good bhaiya :)
@parthparmar97982 жыл бұрын
thanks for the extremely good content and hardwork.
@superbudy83383 жыл бұрын
very helpful thanku for making these kind of videos :)
@debasispaul44102 жыл бұрын
it was helpful
@tejasbavkar28112 жыл бұрын
thank you..
@piyushkesharwani19873 жыл бұрын
Great one, Please make a video on the Internal working of "HEAP" also.