top of page


Tutorials, Errors and Exceptions
Its a journey to understand things better. It will have tutorials, any error/exceptions encountered, its resolutions and lots of learning.

Search


Spring Data JPA with MongoDB
In this post we will create a simple Spring JPA project which will connect to MongoDB and create a document, where we will save records...
Ankit Agrahari
Dec 3, 20213 min read


Testing in Microservices
In this post we will go through the integration testing of the controller of any Spring Boot project. We will be using an existing Spring...
Ankit Agrahari
Dec 1, 20213 min read


#LC1481 - Find Least Number of Unique Integers After K Removals
In this post, we will look into one of the Leetcode problem #1481, where we have to find the least number of unique integers after...
Ankit Agrahari
Nov 30, 20212 min read


#LC983 - Find The Minimum Cost For Tickets (DP)
In this post we will go through the Leetcode #983 to find the minimum cost for Tickets, which could be one of the starting practice...
Ankit Agrahari
Nov 29, 20212 min read


Read/Write Excel Using Apache POI & Java
This post will explore Apache POI library which is used to read any excel document and can also edit the excel sheets. Apache POI (Poor...
Ankit Agrahari
Nov 28, 20213 min read


#LC226 - Inversion Of Binary Tree Using Recursion
Following the last post on the binary tree traversals, in this post we will try to invert a given binary tree. Binary tree is a data...
Ankit Agrahari
Nov 27, 20212 min read


#LC105 - Binary Tree from In-Order and Pre-Order Traversal
In this post we will create a binary tree from the given in-order and pre-order traversal. You can find the details on the question here...
Ankit Agrahari
Nov 26, 20214 min read
Contact
bottom of page
















![You think HashMap is always O(1).
It isn't. Here's what actually happens. 🧵
HashMap stores pairs using `index = hash(key) % capacity` — direct slot access, no scanning. Pure O(1). Until two keys land on the same slot. That's a collision — not a bug, a math inevitability.
Two ways to fix it 👇
🔗 Chaining — each bucket holds a linked list. Collisions append to the list. Simple, handles high load, easy deletion. Downside: pointer overhead, poor cache performance, chains degrade to O(n) at high load. Java's fix? At 8 nodes, the list auto-converts to a Red-Black Tree → O(log n) worst case.
📦 Open Addressing — no linked lists. Collision at slot X? Probe X+1, X+2 until empty. Cache-friendly, zero memory overhead. Downside: deletion needs tombstone markers, and keys cluster together making future collisions worse. Used by C++, Go, Redis.
⚖️ Load Factor = entries ÷ capacity
🟢 Below 0.5 → rare collisions, wasted memory
🟠 0.75 → Java's sweet spot, triggers resize + rehash
🔴 Above 0.9 → collision cascade, O(n) territory
Double hashing kills clustering by varying the probe step per key:
`probe(i) = (h1 + i × h2) % m`
Elements scatter evenly. No bunching. O(1) preserved.
The truth: HashMap is O(1) until a bad hash function, wrong load factor, or wrong strategy turns it into O(n).
Three things protect you:
→ Well-distributed hash function
→ Load factor under 0.75
→ Right collision strategy for your use case
💬 Java interview question: what happens when a chain hits 8 nodes?
Drop your answer below 👇
🔖 Save this before your next interview.
#java #hashmap #datastructures #dsa #algorithms
[codinginterview programming 100daysofcode]](https://scontent-lga3-3.cdninstagram.com/v/t51.71878-15/641188820_1859196944673752_5535080284006983284_n.jpg?stp=dst-jpg_e35_tt6&_nc_cat=102&ccb=7-5&_nc_sid=18de74&efg=eyJlZmdfdGFnIjoiQ0xJUFMuYmVzdF9pbWFnZV91cmxnZW4uQzMifQ%3D%3D&_nc_ohc=bw__s4rY2dUQ7kNvwF1tlA9&_nc_oc=AdqKrA8ieIbduAKQIa82sCtYF_e_fGcGI2M3pP6cUX1fiTbqq6fmCLqJTBrzAX7RU2Q&_nc_zt=23&_nc_ht=scontent-lga3-3.cdninstagram.com&edm=ANo9K5cEAAAA&_nc_gid=Rx-978Ezm_SDU-zOvYspvg&_nc_tpa=Q5bMBQFCsbAWAMJy87g27xX2EShxk5hoeletHON-TZu4wm_-5FKU39lM1SzgoN6bHJ8ezBHoJWdZYetV&oh=00_Af7Dvls8dxveFt7h-SXNbCFQNhJTfzOg1UzXU3GzV2I23Q&oe=6A0A7DFE)


![A Bloom filter is a space-efficient probabilistic data structure used to test whether an element is a member of a set. The key trade-off: it can tell you
- with certainty that an element is not in the set,
- but it can only say an element might be in the set — never with 100% certainty.
How it works ?
- A bit array of size m, initialized to all zeros
- k independent hash functions, each mapping an element to a position in [0, m-1]
- To insert element x:
- Run x through all k hash functions → get k positions
- Set the bit at each of those positions to 1
- To check if element x exists:
- Run x through all k hash functions → get k positions
- If all bits at those positions are 1 → probably in set
- If any bit is 0 → definitely not in set
This is visually shown in the post how the bits are set during insertion or deletion.
If you want the tool for the visual representations, comment on this post, and I'll share it.
#bloomfilter #datastructure #design #softwareengineering #backenddeveloper](https://scontent-lga3-2.cdninstagram.com/v/t51.82787-15/642386646_17867541405570256_7034332257132483480_n.jpg?stp=dst-jpg_e35_tt6&_nc_cat=108&ccb=7-5&_nc_sid=18de74&efg=eyJlZmdfdGFnIjoiQ0xJUFMuYmVzdF9pbWFnZV91cmxnZW4uQzMifQ%3D%3D&_nc_ohc=geOK4Y5Vgc8Q7kNvwHDDp0T&_nc_oc=Adr60VY9gYMEtNwZo2ia_R7buH4qAzTd_IbA4oTFgkIwJbxMcSlbSB7tFvPRzbasXvw&_nc_zt=23&_nc_ht=scontent-lga3-2.cdninstagram.com&edm=ANo9K5cEAAAA&_nc_gid=Rx-978Ezm_SDU-zOvYspvg&_nc_tpa=Q5bMBQE86ZTGmax0nlaz5MQqoCAsyCvlTIwfi7tbJR4pWkRz9ODQKQi-ycIrZ3QsRL4MHB0WT5Z-H0Tg&oh=00_Af4PlEd_UuSae-S52sLANWaSmVTLdY-i0XunbTyWcYC2VA&oe=6A0A74DC)










