Skip to main content

Posts

Showing posts with the label HashMap Time Complexity

Kubernetes & Amazon EKS Explained: A Beginner's Guide

Backend Deep-Dive · Beginner Friendly ~16 min read · Updated for 2026 · No prior experience required If the words Kubernetes and EKS have always felt like a wall of jargon, this is the guide that finally makes them click. We start from absolute zero — what a container even is — and build up, one idea at a time, until you can follow a single user request all the way through a real Amazon EKS cluster and back. Plain English, simple analogies, and a clear mental model instead of a pile of commands. Prefer to read? Everything in the video is written out below. Skim the table of contents and jump to whatever you need. TL;DR — the whole idea in six lines Containers pack your app and its environment together so it runs the same everywhere. Kubernetes is a manager that runs, heals, scales, and connects hundreds of containers for you. Every cluster has a Control Plane (the brain) and Worke...

Java HashMap Internals Explained in Simple Terms

Java  HashMap  is one of the most frequently asked topics in Java interviews. Many developers use it daily, but very few understand  how it actually works internally . In this article, we will explain: What HashMap is How HashMap stores data internally Role of  hashCode()  and  equals() What collisions are and how they are handled Improvements made in newer Java versions Time complexity of all major operations How to reduce frequent collisions All explanations are in  simple terms , with  examples . 1. What Is a HashMap? A  HashMap  stores data in  key–value pairs . Example: Map<String, Integer> map = new HashMap<>(); map.put("A", 10); map.put("B", 20); Key characteristics: Keys must be  unique Values can be duplicated Order is  not guaranteed One  null key  is allowed Multiple null values are allowed Why HashMap is popular: HashMap provides very fast access to data. 2. How HashMap Stores Data Interna...

Why HashMap Uses (n - 1) & hash and Why Capacity Is Always Power of 2

If you are learning  Java HashMap internals , one line that often confuses beginners is: index = (n - 1) & hash; Many people ask: Where is the  power of 2  here? Why not use  %  (modulo)? Why does HashMap care so much about powers of 2? In this article, we’ll explain everything in  very simple terms . What Is  n  in  (n - 1) & hash ? In this formula: index = (n - 1) & hash; n  is the  capacity of the HashMap , meaning the  number of buckets . Important rule: HashMap capacity is ALWAYS a power of 2 Examples: 16 → 2⁴ 32 → 2⁵ 64 → 2⁶ 128 → 2⁷ So the  power of 2 is hidden inside  n . Why HashMap Capacity Must Be Power of 2 HashMap calculates bucket index using  bitwise AND ( & ) , not modulo ( % ). This works correctly  only when  n  is a power of 2 . Let’s understand this with an example. Example: Capacity = 16 (Power of 2) Binary values: n = 16 → 10000 n - 1 = 15 → 01111 Now sup...