<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Data with Abhishek on Medium]]></title>
        <description><![CDATA[Stories by Data with Abhishek on Medium]]></description>
        <link>https://medium.com/@data_with_abhishek?source=rss-5a1acc3ce7b5------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*WOzPeh87B9RR19F4MYCvMg.png</url>
            <title>Stories by Data with Abhishek on Medium</title>
            <link>https://medium.com/@data_with_abhishek?source=rss-5a1acc3ce7b5------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 01 Dec 2026 15:43:03 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@data_with_abhishek/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[B+ Tree in DBMS]]></title>
            <link>https://medium.com/@data_with_abhishek/b-tree-in-dbms-2d304ecf892b?source=rss-5a1acc3ce7b5------2</link>
            <guid isPermaLink="false">https://medium.com/p/2d304ecf892b</guid>
            <dc:creator><![CDATA[Data with Abhishek]]></dc:creator>
            <pubDate>Sun, 15 Nov 2026 19:10:00 GMT</pubDate>
            <atom:updated>2026-11-15T19:10:00.579Z</atom:updated>
            <content:encoded><![CDATA[<p>Let’s build the concept from scratch. By the end, you should understand:</p><ul><li>What a B-Tree and B+ Tree are.</li><li>Why B+ Trees are used in databases.</li><li>What internal nodes and leaf nodes do.</li><li>What the parameter m (order) means.</li><li>How searching works.</li><li>How insertion and splitting work.</li><li>Why B+ Trees are balanced and how their height is calculated.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/743/1*17aacEuL5dTZTLDN90Rz7g.png" /></figure><h3>1. First, why do we need a B+ Tree?</h3><p>Imagine a database table containing 1 million students.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/572/1*oqrlpnKFuAVOKUr8rGA-ew.png" /></figure><p>Suppose you want to find Student ID 500500.</p><p>One approach is to start from the first row and check each row until you find it.</p><p>This is called a linear search.</p><p>In the worst case, you might check 1 million records!</p><p>We need something faster.</p><p>One solution is to sort the IDs and use binary search.</p><p>But databases usually store data on disk in pages (blocks). Accessing disk pages is relatively expensive.</p><p>This is where B+ Trees become useful.</p><p>They organize index entries into a tree, where each node can contain many keys and pointers.</p><p>Instead of visiting thousands of pages, you may only need a few.</p><h3>2. Understand a B-Tree first</h3><p>A B-Tree is a balanced search tree.</p><p>Let’s break that sentence down.</p><h3>A. What is a search tree?</h3><p>Imagine you have these numbers:</p><p>10, 20, 30, 40, 50, 60, 70</p><p>You want to organize them so you can search efficiently.</p><p>A simple binary search tree might look like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/262/1*B7lMuqd8FPGI-omvE709xQ.png" /></figure><p>Each node has at most two children.</p><p>But imagine a database with millions of records.</p><p>A binary tree can become very tall, requiring many levels and potentially many disk accesses.</p><h3>B. What makes a B-Tree different?</h3><p>A B-Tree allows multiple keys inside one node and multiple children. For example:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/757/1*66_LhfnFGxEWvptbr_awxQ.png" /></figure><p>One node can hold multiple values.</p><p>This means one node can point to many children.</p><p>Why is this useful?</p><p>Because each page can contain many keys, we can therefore search a huge amount of data with fewer tree levels.</p><h3>C. What does balanced mean?</h3><p>A balanced tree means all leaf nodes are at the same depth.</p><p>For example:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/763/1*9n4f_WfncsRxAmVCyATI0Q.png" /></figure><p>If one leaf were much deeper than another, the tree would be unbalanced.</p><p>A B-Tree maintains balance automatically during insertion and deletion.</p><h3>D. Why is it called B-Tree?</h3><p>The B in B-Tree does not mean Binary.</p><p>It is commonly associated with its inventor, Rudolf Bayer; other interpretations have also been suggested.</p><h3>3. What is the difference between B-Tree and B+ Tree?</h3><p>This is extremely important.</p><p>A B+ Tree is a variation of a B-Tree.</p><p>The key difference is how they store data.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/779/1*2mF1rlw71106ofLEoI6M0w.png" /></figure><p>Data entries can be stored in internal nodes and leaf nodes.</p><h4>B+ Tree</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/769/1*dU-2nsPsWlICetLljObJ6w.png" /></figure><ul><li>Internal nodes contain only search keys and child pointers.</li><li>Actual data-record pointers are stored in leaf nodes.</li><li>Leaf nodes are connected to one another.</li></ul><p>Think of internal nodes as signboards and leaf nodes as the actual destinations.</p><p>Internal node: “For IDs between 20 and 40, go to this page.”</p><p>Leaf node: “Student ID 30 is here. This is where you find the actual record.”</p><p>This separation makes internal nodes smaller, allowing them to hold more keys and point to more children.</p><p>That is one reason B+ Trees are very efficient for database indexes.</p><h3>4. Understand the structure of a B+ Tree</h3><p>A B+ Tree has two types of nodes:</p><p>Non-leaf nodes (internal nodes).</p><p>Leaf nodes.</p><p>Let’s use one example throughout.</p><p>Suppose we have the following student IDs:</p><p>10, 12, 17, 22, 25, 28, 29, 32, 34, 37, 38</p><p>A simplified B+ Tree could look like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/755/1*kyEJmTVBoivi254LswkluQ.png" /></figure><h3>A. Non-leaf nodes (internal nodes)</h3><p>These are the nodes at the top of the tree.</p><p>They contain:</p><ul><li>Search keys.</li><li>Pointers to other nodes.</li></ul><p>They do NOT contain pointers to the actual student records in a B+ Tree.</p><p>For example, look at the root:</p><p>20 | 30</p><p>What does it mean?</p><p>It divides the search space into three ranges:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/679/1*BcrunpcBc133fjOMOYN-Dw.png" /></figure><p>Very important concept:</p><p>If a node has n keys, it has n + 1 child pointers.</p><p>For example:</p><ul><li>1 key → 2 pointers.</li><li>2 keys → 3 pointers.</li><li>3 keys → 4 pointers.</li><li>4 keys → 5 pointers.</li></ul><p>Why?</p><p>Because every key creates a boundary, dividing the values into one more range than the number of keys.</p><h3>B. Leaf nodes</h3><p>Leaf nodes are at the bottom of the tree.</p><p>They contain:</p><ul><li>Search keys in sorted order.</li><li>Pointers to actual data records (or, depending on the database, the data itself).</li><li>A pointer to the next leaf node.</li><li>Often, a pointer to the previous leaf node as well.</li></ul><p>For example:</p><p>Why are leaf nodes connected?</p><p>Imagine you want all student IDs between 12 and 32.</p><p>The database:</p><ol><li>Finds 12 using the tree.</li><li>Reaches the leaf containing 12.</li><li>Moves to the next leaf.</li><li>Continues until it reaches 32.</li></ol><p>It doesn’t need to go back to the root for every value.</p><p>This makes range searches very efficient.</p><h3>5. What is parameter m (order)?</h3><p>Parameter m = the order.</p><ul><li>A normal internal node has between m and 2m keys.</li><li>A leaf node has between m and 2m entries.</li><li>The root is an exception and can have fewer entries.</li></ul><p>This means a node cannot be completely empty or arbitrarily full.</p><h3>Example: Suppose m = 2</h3><p>Then:</p><p>Minimum keys=2<br>Maximum keys=2m=4<br>So each non-root node should contain between 2 and 4 keys.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/767/1*1iR3BaNfGP1dnldkxEUX4Q.png" /></figure><h3>What about the root?</h3><p>The root is a special case.</p><p>It can contain fewer keys than other nodes.</p><p>For example, if the tree has only one key, the root might look like:</p><p>[20]</p><p>This is perfectly valid.</p><p>If the root is also a leaf, it can contain fewer than m entries.</p><h3>6. How does searching work in a B+ Tree?</h3><p>Let’s take this tree:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/782/1*bBIXXA3rN7-TddXEFXgntw.png" /></figure><p>Search path</p><ol><li>Root: 80</li><li>30 is smaller than 80 → Go left.</li><li>Internal node: 20 | 60</li><li>30 belongs to the range [20, 60) → Go middle</li><li>Leaf: 20 | 30 | 40 | 50</li><li>Found 30 → Follow its data pointer.</li></ol><h3>How much time does searching take?</h3><p>→ O(log⁡n)</p><p>This is the time complexity for equality search.</p><p>Why?</p><p>Because the tree is balanced, and every step takes us closer to a leaf.</p><p>The height grows logarithmically with the number of records.</p><p>There is also a useful observation in your slides:</p><ul><li>If we use binary search inside each node, the total key-comparison complexity is approximately O(log⁡n).</li><li>If we use linear search inside each node, the number of comparisons within a node is higher.</li></ul><p>In practice, database performance is often measured in page accesses (I/O), which is one of the main reasons B+ Trees are useful.</p><h3>7. How is the height of a B+ Tree calculated?</h3><p>This is another important exam topic.</p><p>First, what is height?</p><p>Height = Number of edges on the longest path from the root to a leaf.</p><p>For example:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/213/1*1xPOYQE9zdyQ8dURyrbi_w.png" /></figure><h3>Why does the height stay small?</h3><p>Remember our example:</p><ul><li>Minimum number of keys in a non-root node = m.</li><li>Maximum number of keys = 2m.</li></ul><p>That means a node can have many children.</p><p>As a result, the tree grows wider rather than becoming very tall.</p><p>Best-case height≈log2<em>m</em>​(<em>n</em>)</p><p>Maximum height≤log⁡m(n)</p><p>Here, n represents the number of indexed entries, with simplified assumptions about node occupancy.</p><p>The intuition is more important than memorizing the formula:</p><p>More keys per node = More children per node = Shorter tree = Fewer page accesses.</p><p>For a database with millions of records, the tree may still only need a handful of levels.</p><h3>8. B+ Tree insertion — The most important operation</h3><p>Now let’s understand what happens when we insert a new value.</p><p>This is where the concept of splitting becomes important.</p><p>Imagine a node can hold a maximum of 4 keys.</p><p>We want to insert a new key into that node.</p><p>There are two situations:</p><ul><li>Situation 1: The node has free space.</li><li>Situation 2: The node is already full.</li></ul><p>Let’s see both.</p><h3>Situation A: Insertion when there is free space</h3><p>Suppose a leaf contains:</p><p>[10, 20, 30]</p><p>Maximum capacity = 4 keys.</p><p>Now insert 25.</p><p>The new leaf becomes:</p><p>[10, 20, 25, 30]</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/765/1*-5RvHEItwQoyvhhVB_ICiA.png" /></figure><h3>Situation B: Insertion when the node is full</h3><p>Now suppose the leaf contains:</p><p>[10, 20, 30, 40]</p><p>Maximum capacity = 4 keys.</p><p>Now insert 25.</p><p>What happens?</p><p>First, imagine we temporarily insert 25:</p><p>[10, 20, 25, 30, 40]</p><p>Oops!</p><p>We now have 5 keys, but the maximum is 4.</p><p>This is called overflow.</p><p>We must split the node.</p><h3>Step 1: Split the node</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/770/1*Ces-683JguD2Mk3YRlr8mw.png" /></figure><p>Divide the five entries into two groups, keeping them as balanced as possible.</p><p>We now have two leaf nodes.</p><h3>Step 2: Copy the first key of the right leaf to the parent</h3><p>The right leaf starts with 25.</p><p>We copy 25 into the parent node as a separator.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/775/1*ROj0zROVRTMbYyyOdGUhcA.png" /></figure><p>Why do we copy 25 instead of removing it from the leaf?</p><p>Because in a B+ Tree, the actual data entries remain in the leaf nodes.</p><p>The parent only needs the key to guide searches.</p><p>Important difference:</p><ul><li>When splitting a leaf: Copy the first key of the new right leaf into the parent. The key stays in the leaf.</li><li>When splitting an internal node: Move the middle separator key up to the parent. It is removed from the child.</li></ul><h3>9. What happens if the parent is also full?</h3><p>This is called recursive splitting.</p><p>Let’s understand it using your lecture’s example.</p><p>The original tree has:</p><ul><li>A leaf containing [2, 3, 5, 7].</li><li>A parent containing [13, 17, 24, 30].</li></ul><p>Maximum capacity = 4 keys per node.</p><p>Now insert 8.</p><h3>Step 1: Find the correct leaf</h3><p>We follow the tree and reach:</p><p>[2, 3, 5, 7]</p><h3>Step 2: Insert 8</h3><p>Temporarily:</p><p>[2, 3, 5, 7, 8]</p><p>There are 5 keys.</p><p>Overflow!</p><h3>Step 3: Split the leaf</h3><p>Divide it into:</p><ul><li>Left leaf: [2, 3]</li><li>Right leaf: [5, 7, 8]</li></ul><p>Now copy the first key of the right leaf (5) into the parent.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/791/1*yAfRw-VGkkuzIif2vobslg.png" /></figure><h3>Step 4: Insert 5 into the parent</h3><p>The original parent was:</p><p>[13, 17, 24, 30]</p><p>After inserting 5:</p><p>[5, 13, 17, 24, 30]</p><p>Again, there are 5 keys.</p><p>But maximum capacity is 4.</p><p>So the parent also overflows!</p><p>We must split the parent too.</p><h3>Step 5: Split the internal node</h3><p>Split:</p><p>[5, 13, 17, 24, 30]</p><p>The middle key is 17.</p><p>Divide the remaining keys:</p><ul><li>Left internal node: [5, 13]</li><li>Right internal node: [24, 30]</li></ul><p>Move 17 up to the next parent.</p><p>Notice: Unlike the leaf split, 17 is removed from the internal child nodes.</p><h3>Step 6: Create a new root</h3><p>In this example, the parent was the root.</p><p>There is no parent above it.</p><p>Therefore, we create a new root containing 17.</p><p>The resulting structure is:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/767/1*z_cfnqoKVNIksThQJe6ayg.png" /></figure><p>The tree has now grown one level taller!</p><p>This is how a B+ Tree grows.</p><p>Remember the insertion algorithm:</p><ol><li>Find the correct leaf.</li><li>Insert the key in sorted order.</li><li>If there is enough space, stop.</li><li>If the leaf overflows, split it.</li><li>Copy the first key of the new right leaf into its parent.</li><li>If the parent overflows, split it too.</li><li>Continue upwards if necessary.</li><li>If the root splits, create a new root.</li></ol><h3>10. What does the B+ Tree page format mean?</h3><p>Your slides show something like this:</p><h3>A. Internal page format</h3><p>P1 | K1 | P2 | K2 | P3 | K3 | P4</p><p>Here:</p><ul><li>P = Pointer to another page.</li><li>K = Search key.</li></ul><p>For example:</p><p>P1 | 10 | P2 | 20 | P3</p><p>This means:</p><ul><li>P1 points to a page containing values less than 10.</li><li>P2 points to a page containing values from 10 up to (but not including) 20.</li><li>P3 points to a page containing values greater than or equal to 20.</li></ul><p>Remember: 2 keys mean 3 pointers.</p><h3>B. Leaf page format</h3><p>A leaf page looks conceptually like this:</p><p>Previous | Key1, RecordPointer1 | Key2, RecordPointer2 | Next</p><p>For example:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/780/1*qskctT07mB32aOcJWZnbvQ.png" /></figure><h3>11. What are the different B+ Tree operations?</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/703/1*wuNbGyBg3SF1wzY3DsX79Q.png" /></figure><p>One additional note: Optimized bulk loading, especially when the input is already sorted, can be approximately O(n). The <em>O</em>(<em>n </em>log<em> n</em>) is a more general bound.</p><h3>12. Insert and Split vs Split as You Search</h3><p>Your final slide mentions something called:</p><p>Split as you search.</p><p>Let’s understand why it exists.</p><p>There are two ways to handle insertion.</p><h3>Method 1: Insert first, split later</h3><p>This is what we learned above.</p><ol><li>Search for the correct leaf.</li><li>Insert the new value.</li><li>If the node overflows, split it.</li><li>If the parent overflows, split the parent.</li><li>Continue upwards if necessary.</li></ol><p>The problem?</p><p>You may need to go back up the tree and split several nodes.</p><h3>Method 2: Split proactively while searching</h3><p>Instead of waiting until you reach the leaf, the database checks nodes while travelling down the tree.</p><p>If it sees that a node is full (or is about to become full), it splits the node before continuing.</p><p>This way, when it reaches the leaf, it has already handled potential overflow on the path.</p><p>Why is this useful?</p><p>Imagine multiple database transactions are inserting records simultaneously.</p><p>These transactions are called concurrent transactions.</p><p>If several transactions try to modify the same pages, they may need to wait for locks.</p><p>Splitting nodes proactively can help manage these operations and reduce some complications caused by having to revisit ancestors.</p><p>The exact strategy depends on the database implementation and concurrency-control mechanism.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2d304ecf892b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[What Happens Inside Your Computer When You Open Google Chrome?]]></title>
            <link>https://medium.com/@data_with_abhishek/what-happens-inside-your-computer-when-you-open-google-chrome-84d775c3dbae?source=rss-5a1acc3ce7b5------2</link>
            <guid isPermaLink="false">https://medium.com/p/84d775c3dbae</guid>
            <dc:creator><![CDATA[Data with Abhishek]]></dc:creator>
            <pubDate>Wed, 04 Nov 2026 18:56:48 GMT</pubDate>
            <atom:updated>2026-11-04T18:56:48.368Z</atom:updated>
            <content:encoded><![CDATA[<p>Have you ever wondered what happens inside your computer when you double-click Google Chrome?</p><p>You click an icon, wait a few seconds, and suddenly the browser appears on your screen. But behind this simple action, several hardware and software components work together.</p><p>The operating system creates a process, memory is allocated, program instructions are loaded, the CPU executes those instructions, and the Memory Management Unit (MMU) translates virtual addresses into physical RAM addresses.</p><p>In this article, we will follow the complete journey of opening Google Chrome, from clicking its icon to accessing data in RAM.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/682/1*ljnE_DW2SPZ2_rVArkPgbw.png" /></figure><p>We will cover:</p><ul><li>CPU and process creation</li><li>Virtual memory and logical addresses</li><li>Pages and physical memory frames</li><li>Page tables</li><li>Memory Management Unit (MMU)</li><li>Translation Lookaside Buffer (TLB)</li><li>Page faults and demand paging</li></ul><h3>Step 1: You Click the Google Chrome Icon</h3><p>Imagine you double-click the Google Chrome icon on your desktop.</p><p>What happens?</p><ol><li>The operating system receives your request.</li><li>It identifies the Chrome application.</li><li>It locates the necessary program files on your SSD or HDD.</li><li>It begins launching the application.</li></ol><p><strong>Important concept:</strong> Chrome’s executable files and libraries are stored on secondary storage (SSD/HDD) before they are loaded and used.</p><h3>Step 2: The Operating System Creates a Process</h3><p>The operating system creates a new process for Chrome.</p><p>A process is simply a program that is currently executing.</p><p>During process creation, the operating system establishes several things:</p><ul><li>Process ID (PID): A unique identifier for the process.</li><li>Process information: Information required to manage its execution.</li><li>Virtual address space: A separate address space for Chrome.</li><li>Memory management information: Information used to manage the process’s memory.</li></ul><p><strong>Why is this important?</strong></p><p>Each application gets its own virtual address space. This helps applications operate independently and prevents them from directly interfering with one another’s private memory.</p><p>For example, Chrome and a game can both use the same virtual address without necessarily accessing the same physical RAM location.</p><h3>Step 3: Virtual Memory Is Allocated</h3><p>The operating system provides Chrome with its own virtual address space.</p><p>Think of virtual memory as a private memory space that an application can use. This address space is divided into fixed-size blocks called <strong>pages</strong>.</p><p>For example:<br>Page 0: First block of virtual memory<br>Page 1: Second block of virtual memory<br>Page 2: Third block of virtual memory<br>Page 3: Fourth block of virtual memory</p><p>An important feature of virtual memory is that reserving virtual address space does not necessarily require immediately allocating physical RAM.</p><p>Physical memory can be allocated when the application actually accesses the relevant memory.</p><p>This is called <strong>demand allocation</strong>.</p><p>Virtual memory provides:</p><ul><li>Easier programming.</li><li>Independent address spaces.</li><li>Better memory protection.</li><li>Flexibility in physical memory management.</li></ul><h3>Step 4: Chrome’s Program Code and Required Data Are Loaded</h3><p>Chrome’s program files are stored on the SSD/HDD.</p><p>However, the CPU needs instructions and data to be available through the memory system when it executes the application.</p><p>The operating system loads the necessary parts of Chrome’s executable files and libraries into memory as needed.</p><p>Examples include:</p><ul><li>Program instructions.</li><li>Required libraries.</li><li>Initial application data.</li></ul><p>Not every part of Chrome needs to be loaded into RAM immediately.</p><p>Some parts can be loaded only when they are accessed.</p><p>This is called <strong>demand paging</strong>.</p><h3>Step 5: Virtual Pages Are Mapped to Physical RAM Frames</h3><p>Now we need to understand the relationship between virtual memory and physical memory.</p><p>Virtual memory is divided into pages.</p><p>Physical RAM is divided into fixed-size blocks called frames.</p><p>A page and a frame have the same size.</p><p>For example:</p><ul><li>Page size = 4 KB.</li><li>Frame size = 4 KB.</li></ul><p>The operating system assigns available physical frames to virtual pages as needed.</p><p>Consider this example:<br>Page 0: Frame 3<br>Page 1: Frame 6<br>Page 2: Frame 1<br>Page 3: Not currently in RAM</p><p>Notice that the pages do not need to be stored in the same numerical order as their virtual page numbers.</p><p>For example, Page 2 is stored in Frame 1.</p><p>The operating system maintains these mappings using a data structure called the <strong>page table</strong>.</p><p>Remember:</p><ul><li>Page = Block of virtual memory.</li><li>Frame = Block of physical RAM.</li><li>Page table = Maps virtual pages to physical frames.</li></ul><h3>Step 6: The CPU Starts Executing Chrome Instructions</h3><p>Now Chrome has been initialized sufficiently for the CPU to begin executing its instructions.</p><p>The CPU executes instructions such as:</p><ul><li>Loading data.</li><li>Performing calculations.</li><li>Comparing values.</li><li>Moving information between registers and memory.</li></ul><p>Suppose Chrome needs to access a variable stored at logical address 2500.</p><p>The CPU generates this address as a virtual address.</p><p>But there is an important distinction:</p><p><strong>A logical (virtual) address is not necessarily the actual physical RAM address.</strong></p><p>The computer must translate it before accessing the corresponding physical memory location.</p><h3>Step 7: The MMU Translates the Logical Address</h3><p>The <strong>Memory Management Unit (MMU)</strong> is hardware responsible for translating virtual addresses into physical addresses.</p><p>Let’s understand this using a numerical example.</p><p>Suppose:</p><ul><li>Page size = 1000 bytes.</li><li>Logical address = 2500.</li></ul><p>The MMU separates the logical address into two parts:</p><h4>A. Page Number</h4><p>Formula:</p><p>Page number = Logical address ÷ Page size (take the whole-number quotient).</p><p>2500 ÷ 1000 = 2</p><p>Therefore:</p><p><strong>Page number = 2</strong></p><p>This tells us that the requested address belongs to Virtual Page 2.</p><h4>B. Offset</h4><p>Formula:</p><p>Offset = Logical address MOD Page size.</p><p>2500 MOD 1000 = 500</p><p>Therefore:</p><p><strong>Offset = 500</strong></p><p>This tells us that the requested byte is 500 bytes from the beginning of Page 2.</p><p>We now have:</p><ul><li>Page number = 2.</li><li>Offset = 500.</li></ul><h3>Step 8: The MMU Checks the TLB</h3><p>Before consulting the page table in main memory, the MMU checks something called the <strong>Translation Lookaside Buffer (TLB)</strong>.</p><p>The TLB is a small, very fast cache that stores recently used virtual-page-to-physical-frame mappings.</p><p>Think of it as a small notebook containing frequently used address translations.</p><p>For example, it might contain:</p><p>Virtual page: Physical frame<br>Page 0: Frame 3<br>Page 2: Frame 7</p><p>The MMU searches for the mapping of Page 2.</p><p>There are two possible outcomes.</p><h3>TLB Hit</h3><p>A TLB hit occurs when the required mapping is already available in the TLB.</p><p>For example:</p><p>Page 2 → Frame 7.</p><p>The MMU can obtain the frame number quickly.</p><h3>TLB Miss</h3><p>A TLB miss occurs when the required mapping is not found in the TLB.</p><p>In this case, the MMU consults the page table to find the mapping.</p><p>The mapping can then be cached in the TLB for future accesses.</p><p><strong>Important:</strong> A TLB miss does not necessarily mean a page fault. It simply means the required address translation was not found in the TLB.</p><h3>Step 9: The Page Table Provides the Frame Number</h3><p>Suppose the TLB has a miss.</p><p>The MMU consults the page table.</p><p>Consider this example:</p><p>Virtual page Physical frame<br>Page 0 Frame 3<br>Page 1 Frame 6<br>Page 2 Frame 7<br>Page 3 Frame 1</p><p>The MMU searches for Page 2.</p><p>It discovers:</p><p><strong>Page 2 → Frame 7</strong></p><p>Now the MMU knows that the requested virtual page is stored in Physical Frame 7.</p><p>An important point: The page table stores mapping information, not the actual program data. The page table itself is also stored in memory, although frequently used translations may be cached in the TLB.</p><h3>Step 10: The Physical Address Is Calculated</h3><p>Now we have all the information required to calculate the physical address.</p><p>Given:</p><ul><li>Frame number = 7.</li><li>Frame size = 1000 bytes.</li><li>Offset = 500.</li></ul><p>Formula:</p><p>Physical address = (Frame number × Frame size) + Offset</p><p>Substitute the values:</p><p>Physical address = (7 × 1000) + 500</p><p>Physical address = 7000 + 500</p><p><strong>Physical address = 7500</strong></p><p>This is the actual RAM address corresponding to the requested virtual address.</p><p>The CPU’s memory access can now proceed using this translated physical address.</p><h3>Step 11: What Happens If the Required Page Is Not in RAM?</h3><p>Suppose Chrome requests a virtual page that is not currently present in physical RAM.</p><p>A <strong>page fault</strong> occurs.</p><p>A page fault is an event that tells the operating system that the requested virtual memory page cannot currently be accessed through a valid resident RAM mapping.</p><p>The operating system then handles the situation.</p><p>Typically, it:</p><ol><li>Checks whether the requested memory access is valid.</li><li>Locates the required page in its backing storage, if applicable.</li><li>Finds an available RAM frame or frees one if necessary.</li><li>Loads the required page into RAM.</li><li>Updates the page table.</li><li>Restarts the interrupted instruction.</li></ol><p>A page fault is not necessarily an error. It can be a normal part of virtual memory management.</p><h3>Step 12: Chrome Becomes Ready to Use</h3><p>After the necessary initialization and memory operations, Chrome continues executing its instructions.</p><p>Its user interface is initialized, its browser window appears, and you can begin browsing.</p><p>You can now type a website address, open tabs, and interact with the browser.</p><p>Behind the scenes, the CPU and MMU continue handling memory accesses as Chrome runs.</p><h3>Complete End-to-End Flow</h3><p>Let’s summarize the entire process in one sequence.</p><p>What happens?<br>1. User clicks the Chrome icon.<br>2. The operating system creates a Chrome process.<br>3. A virtual address space is established.<br>4. Required program code and data are loaded from secondary storage as needed.<br>5. Virtual pages are mapped to physical RAM frames.<br>6. The CPU starts executing Chrome instructions.<br>7. The CPU generates virtual addresses for memory accesses.<br>8. The MMU checks the TLB for a cached translation.<br>9. On a TLB miss, the page table is consulted.<br>10 MMU obtains the physical frame number and calculates the physical address.<br>11 RAM supplies the requested data.<br>12 Chrome continues running and displaying its interface.</p><h3>Final Takeaway</h3><p>The most important sequence to remember is:</p><p><strong>Click Chrome → OS creates process → Virtual memory is established → Required pages are loaded into RAM → CPU executes instructions → MMU translates virtual addresses using the TLB and page table → Physical RAM is accessed → Chrome continues running.</strong></p><p>One final clarification: This is a simplified conceptual sequence. In a real computer, loading, allocation, execution and address translation overlap. The MMU performs address translation repeatedly throughout the application’s execution, not just once when Chrome opens.</p><p>Understanding this flow gives you a foundation for understanding operating systems, memory management, paging and computer architecture.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=84d775c3dbae" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Stack vs Heap]]></title>
            <link>https://medium.com/@data_with_abhishek/stack-vs-heap-f628c4372480?source=rss-5a1acc3ce7b5------2</link>
            <guid isPermaLink="false">https://medium.com/p/f628c4372480</guid>
            <category><![CDATA[data-structure-algorithm]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[full-stack]]></category>
            <dc:creator><![CDATA[Data with Abhishek]]></dc:creator>
            <pubDate>Tue, 27 Oct 2026 20:30:06 GMT</pubDate>
            <atom:updated>2026-10-27T20:30:06.391Z</atom:updated>
            <content:encoded><![CDATA[<p>Every program needs memory to store data, execute functions, and manage objects. But not all memory is managed in the same way. Two important concepts behind memory management are the <strong>stack</strong> and the <strong>heap</strong>.</p><p>Understanding these concepts helps explain how variables work, why some data disappears when a function returns, and how programming languages manage memory.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/391/1*sW69j_VKNQVnsZNZWnO-Hg.png" /></figure><p>Let’s explore them using simple analogies and examples.</p><h3>What Are the Stack and Heap?</h3><p>Imagine you are working in an office.</p><ul><li><strong>The stack is like your desk.</strong> You place the documents you are currently working on on top. When you finish a task, you put those documents away.</li><li><strong>The heap is like a storage room.</strong> You store items there that may need to be used later, shared with others, or kept for an unpredictable amount of time.</li></ul><p>A program uses memory in a similar way.</p><p>The stack is commonly used to manage<strong><em> function calls and their local data.</em></strong> The heap is commonly used for <strong><em>dynamically allocated data, such as collections, strings, and objects</em></strong> that may need to outlive a particular function call.</p><h3>Understanding the Stack</h3><p>The stack follows a principle called <strong>LIFO (Last In, First Out)</strong>.</p><p>Think of a stack of plates: the last plate you put on top is the first one you remove.</p><p>When a function is called, the program typically creates a <em>stack frame</em> containing the information needed for that call. When the function returns, its frame is removed.</p><pre>def greet():<br>    message = &quot;Hello, World!&quot;<br>    print(message)<br><br>greet()</pre><p>When greet() executes:</p><ol><li>A function call becomes active.</li><li>The variable message refers to the string &quot;Hello, World!&quot;.</li><li>The string is printed.</li><li>The function returns, and its local variable is no longer accessible by that name.</li></ol><p>Conceptually, the call stack looks like this:</p><pre>During the function call:<br><br>┌─────────────────────┐<br>│ greet()             │<br>│ message             │<br>│ &quot;Hello, World!&quot;     │<br>├─────────────────────┤<br>│ Calling function    │<br>└─────────────────────┘<br><br>After greet() returns:<br><br>┌─────────────────────┐<br>│ Calling function    │<br>└─────────────────────┘</pre><p>The diagram illustrates the lifetime of a function call, not the exact physical memory layout.</p><p>Let’s understand this with another in-depth example:</p><pre>def second():<br>    y = 20<br>    print(y)<br><br>def first():<br>    x = 10<br>    second()<br>    print(x)<br><br>first()<br></pre><h4>1. first() starts</h4><p>The variable x = 10 is created inside first().</p><pre>       STACK<br>   ┌─────────────┐<br>   │ first()     │<br>   │ x = 10      │<br>   └─────────────┘</pre><h4>2. first() calls second()</h4><p>Now second() starts, and y = 20 is created. Its frame goes on top of first().</p><pre>       STACK<br>   ┌─────────────┐<br>   │ second()    │  ← Top<br>   │ y = 20      │<br>   ├─────────────┤<br>   │ first()     │<br>   │ x = 10      │<br>   └─────────────┘</pre><h4>3. second() finishes</h4><p>It prints 20, then its frame is removed. Execution returns to first().</p><pre>       STACK<br>   ┌─────────────┐<br>   │ first()     │  ← Top<br>   │ x = 10      │<br>   └─────────────┘</pre><h4>4. first() finishes</h4><p>It prints 10, then its frame is removed.</p><pre>       STACK<br>   ┌─────────────┐<br>   │   Empty     │<br>   └─────────────┘</pre><pre>OUTPUT: <br>20<br>10</pre><p>Remember: first() waits while second() runs. Once second() finishes, Python returns to first() and continues from where it stopped.</p><h3>When is the stack useful?</h3><p>The stack is particularly useful for:</p><ul><li>Managing function calls and return information.</li><li>Storing many local values with predictable lifetimes.</li><li>Handling nested function calls efficiently.</li><li>Automatically managing temporary call-related storage.</li></ul><p>However, the stack has limited capacity. Excessively deep recursion or very large stack allocations can cause a stack overflow.</p><p>A stack frame is the information needed to manage one active function call.</p><p>A <strong>stack overflow</strong> happens when a program exceeds its available call-stack capacity or reaches a runtime’s call-depth limit. <br>A common cause is infinite or excessively deep recursion.</p><pre>def call_forever():<br>    call_forever()<br><br>call_forever()</pre><pre>call_forever() — Call 1<br><br>call_forever() — Call 2<br><br>call_forever() — Call 3<br><br>call_forever() — Call 4<br><br>Call-depth or stack limit exceeded</pre><p>To avoid this problem, use a proper stopping condition for recursive functions or consider an iterative solution when appropriate.</p><pre>def countdown(n):<br>    while n &gt; 0:<br>        print(n)<br>        n -= 1<br><br>    print(&quot;Done!&quot;)<br><br>countdown(5)</pre><h3>Understanding the Heap</h3><p>Now that we understand the stack, let’s look at the heap.</p><p>The <strong>heap</strong> is a region of memory commonly used for dynamically allocated data. Unlike the call stack, which follows the structure of active function calls, heap allocations can remain available after the function that created them has returned.</p><p>The heap is useful when data needs a lifetime that does not match a single function call.</p><p>For example, consider a program that creates a list of user records, a collection of products, or a large data structure. These objects may need to be accessed by multiple parts of the program.</p><p>The heap provides a way to store such dynamically allocated objects.</p><h3>Example: Creating an Object</h3><p>Consider this Python code:</p><pre>def create_numbers():<br>    numbers = [10, 20, 30]<br>    return numbers<br><br>result = create_numbers()<br><br>print(result)</pre><pre>[10, 20, 30] # output</pre><p>What happens here?</p><ol><li>The function create_numbers() is called.</li><li>A list object containing 10, 20, and 30 is created.</li><li>The local variable numbers refers to that list.</li><li>The function returns a reference to the list.</li><li>The variable result receives that reference.</li><li>The list remains accessible after the function returns.</li></ol><p>Conceptually, we can represent the situation like this:</p><p><strong>While the function is running:</strong></p><pre>          CALL STACK                 HEAP<br>       ┌──────────────┐        ┌─────────────────┐<br>       │ create_      │        │                 │<br>       │ numbers()    │        │                 │<br>       │              │        │                 │<br>       │ numbers ─────┼───────→│ [10, 20, 30]    │<br>       └──────────────┘        └─────────────────┘</pre><p><strong>After the function returns:</strong></p><pre>          CALL STACK                 HEAP<br>       ┌──────────────┐        ┌─────────────────┐<br>       │ Main code    │        │                 │<br>       │              │        │                 │<br>       │ result ──────┼───────→│ [10, 20, 30]    │<br>       └──────────────┘        └─────────────────┘</pre><p>The function’s local name numbers no longer exists after the function returns, but the list remains accessible through result.</p><p><strong>Important:</strong> These diagrams illustrate the conceptual relationship between references and objects. Python does not guarantee that every variable lives on the physical call stack or that every object is allocated in a particular physical heap region.</p><h3>Why Doesn’t the List Disappear?</h3><p>The key idea is that a variable and the object it refers to are not necessarily the same thing.</p><p>In the example above:</p><ul><li>numbers is a local name inside create_numbers().</li><li>The list is an object.</li><li>result receives a reference to that same object.</li></ul><p>When the function returns, its local name disappears. However, the list is still reachable through result.</p><p>This is why data can outlive the function that created it.</p><h3>When Is the Heap Useful?</h3><p>The heap is particularly useful for:</p><ul><li>Creating objects and collections whose lifetimes are not tied to one function call.</li><li>Storing dynamically sized data structures.</li><li>Sharing objects between different parts of a program.</li><li>Building linked lists, trees, graphs, and other dynamic structures.</li><li>Managing data that needs to remain accessible after a function returns.</li></ul><h3>If the stack has a fixed size, how can functions have different sizes?</h3><p>Here’s the important distinction:</p><ul><li>Stack capacity: The total amount of stack memory available to a thread is limited.</li><li>Stack frame size: The amount of memory needed for one active function call can vary.</li><li>Total stack usage: The combined memory used by all active calls and their frames.</li></ul><p>Think of the stack as a suitcase with a fixed capacity. You can put small or large items into it, but the suitcase itself does not grow indefinitely.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f628c4372480" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Understanding SSH Keys as a Beginner]]></title>
            <link>https://medium.com/@data_with_abhishek/understanding-ssh-keys-as-a-beginner-67b1b89a0468?source=rss-5a1acc3ce7b5------2</link>
            <guid isPermaLink="false">https://medium.com/p/67b1b89a0468</guid>
            <category><![CDATA[ssh-keys]]></category>
            <category><![CDATA[ssh]]></category>
            <category><![CDATA[computer-networking]]></category>
            <category><![CDATA[windows]]></category>
            <dc:creator><![CDATA[Data with Abhishek]]></dc:creator>
            <pubDate>Tue, 27 Oct 2026 07:35:21 GMT</pubDate>
            <atom:updated>2026-10-27T07:36:00.427Z</atom:updated>
            <content:encoded><![CDATA[<p><em>My journey from generating my first SSH key to understanding how secure remote access actually works.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/763/1*pR_o6E16vvJQvEkdjgVdbg.png" /></figure><h3>1. The Beginning: Why Did My University Ask for an SSH Public Key?</h3><p>Today, I learned something new — something I probably should have learned much earlier. But hey, better late than never!</p><p>Sometimes, the best way to learn something is to stop and ask a simple question:</p><p><strong>“Why am I doing this, and what is actually happening behind the scenes?”</strong></p><p>That is exactly what I did today, and now SSH makes a lot more sense.</p><p>I was asked to provide my <strong>SSH public key</strong> to my university so I could access a development virtual machine (VM) and submit my lab reports. At first, I wondered:</p><ul><li>What exactly is SSH?</li><li>Why does my university need my public key?</li><li>What are public and private keys?</li><li>How will I use these keys in the future?</li></ul><p>Instead of blindly following instructions, I decided to understand what was happening behind the scenes. Here is what I learned.</p><h3>What Were We Actually Trying to Do?</h3><p>My university wants me to access a development VM for my lab work.</p><p>A <strong>virtual machine (VM)</strong> is essentially a computer created using software that runs on a physical computer or server. In this case, the university provides a remote environment where I can work on my code, run programs, and complete laboratory assignments.</p><p>I can access this remote computer from my Windows machine without physically being in front of it.</p><p>But how do I connect securely?</p><p>That is where SSH and SSH keys come in.</p><p>The basic idea is:</p><ul><li><strong>My Windows computer:</strong> Stores my private key.</li><li><strong>University server:</strong> Has my public key registered for authentication.</li><li><strong>SSH:</strong> Establishes a secure connection and verifies that I possess the corresponding private key.</li></ul><p>Here is a simplified illustration of the process:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/325/1*eqHuT6xp3IOl-VWHIMeRKw.png" /></figure><p>The important thing to understand is that <strong>my private key never needs to be sent to the university server</strong>. Instead, SSH uses cryptographic techniques to verify that my computer possesses the private key corresponding to the registered public key.</p><p>Now, let’s understand each part.</p><h3>What Is SSH?</h3><p>SSH stands for <strong>Secure Shell</strong>. It is a network protocol that allows us to securely connect to and interact with another computer over a network.</p><p>For example, SSH allows me to:</p><ul><li>Log in to my university’s development VM.</li><li>Execute commands on a remote computer.</li><li>Compile, run, and test my code.</li><li>Manage files and development environments.</li><li>Transfer files securely using tools such as scp and sftp.</li></ul><p>Imagine that I am sitting at home with my Windows laptop, but my code needs to run on a Linux machine maintained by my university.</p><p>Instead of sitting in front of that machine, I can connect to it using SSH and work with it remotely.</p><p>Once connected, I can use commands just as I would in a terminal on the remote computer.</p><h3>What Exactly Did I Do in PowerShell?</h3><p>To generate my SSH keys, I opened PowerShell on Windows and ran the following command:</p><pre>ssh-keygen -t ed25519 -C &quot;my-university-vm&quot;</pre><p>Let’s break this command down.</p><h3>ssh-keygen</h3><p>This is the utility used to generate SSH key pairs.</p><p>It creates two related keys:</p><ul><li>A public key that I can share.</li><li>A private key that I must protect.</li></ul><h3>-t ed25519</h3><p>The -t option specifies the type of key to generate.</p><p>Here, ed25519 refers to a modern public-key cryptographic algorithm commonly used for SSH authentication.</p><h3>-C &quot;my-university-vm&quot;</h3><p>The -C option adds a comment to the public key.</p><p>I used my-university-vm as a label to help identify what the key is for.</p><h3>Where were the keys saved?</h3><p>PowerShell then asked where I wanted to save the generated key pair.</p><p>I pressed Enter to accept the default location.</p><p>On Windows, the files are typically stored in:</p><pre>C:\Users\&lt;YourWindowsUsername&gt;\.ssh\</pre><p>The generated files are:</p><p>.ssh/<br>├── id_ed25519<br>└── id_ed25519.pub</p><h3>What Are Public and Private Keys?</h3><p>This is probably the most important concept to understand.</p><p>SSH key authentication uses <strong>public-key cryptography</strong>, which relies on two mathematically related keys.</p><h4>The public key</h4><p>The public key is the part I can share with my university.</p><p>The university registers it with my account or in the appropriate authorization configuration on the server. When I attempt to connect, the server can use that registered key to verify my authentication.</p><p>I can safely submit my public key through the university’s designated form.</p><h4>The private key</h4><p>The private key stays on my computer.</p><p>My SSH client uses it to prove that I possess the key corresponding to the registered public key.</p><h3>How Can I Access My SSH Keys in the Future?</h3><p>The good news is that I do not need to generate a new key pair every time I want to connect.</p><p>Once generated, my keys remain saved on my computer until I move or delete them.</p><h3>Display my public key</h3><p>Open PowerShell and run:</p><pre>Get-Content ~/.ssh/id_ed25519.pub</pre><p>This displays the public key in the terminal.</p><p>If I need to submit it again, I can copy the complete output.</p><h3>How Do I Actually Connect to the University VM?</h3><p>Generating my SSH keys is only the first step. It does not automatically give me access to the university’s VM.</p><p>Usually, I need to complete the following steps.</p><h4>Step 1: Register my public key</h4><p>I submit the contents of id_ed25519.pub through the university&#39;s designated form or registration system.</p><h4>Step 2: Wait for access to be configured</h4><p>The university must associate my public key with my account or configure it in the appropriate place on the server.</p><p>Submitting a key does not necessarily mean access is available immediately.</p><h4>Step 3: Obtain the connection details</h4><p>I need the information provided by my university, such as:</p><ul><li>My assigned username.</li><li>The VM’s hostname or IP address.</li><li>The SSH port, if it differs from the default.</li><li>Any required VPN or university-network access.</li><li>Any additional connection instructions.</li></ul><h4>Step 4: Connect using SSH</h4><p>Once I have the necessary details, I can open PowerShell and run:</p><p>powershell</p><pre>ssh YOUR_USERNAME@YOUR_VM_HOSTNAME</pre><p>For example, suppose the university provides the following fictional details:</p><ul><li>Username: student123</li><li>Hostname: devvm.example.edu</li></ul><p>Then I would run:</p><p>powershell</p><pre>ssh student123@devvm.example.edu</pre><p>These are example details, not the actual connection information for any particular university.</p><p>If my private key is stored under the default filename and location, SSH will usually find it automatically. If I have several keys or the university specifies a different key, I may need to specify it explicitly:</p><p>powershell</p><pre>ssh -i ~/.ssh/id_ed25519 YOUR_USERNAME@YOUR_VM_HOSTNAME</pre><p>If the university uses a custom SSH port, I can specify it with -p:</p><p>powershell</p><pre>ssh -p 2222 YOUR_USERNAME@YOUR_VM_HOSTNAME</pre><p>Here, 2222 is only an example port. I must use the port provided by my university.</p><h4>Step 5: Verify the server’s identity</h4><p>The first time I connect to a server, SSH may display a message asking whether I trust its host key.</p><p>This is different from my own SSH key pair.</p><ul><li><strong>My SSH key pair</strong> identifies me to the server.</li><li><strong>The server’s host key</strong> helps my computer verify the identity of the server.</li></ul><p>Before accepting an unfamiliar host key, I should compare its fingerprint with a trusted fingerprint provided by the university. This helps protect against connecting to an impostor server.</p><p>After the connection is established successfully, I can use the remote terminal to work on my lab assignments.</p><h3>What If Something Goes Wrong?</h3><p>Here are a few common situations and what they mean.</p><p><strong>Problem: </strong><strong>Permission denied (publickey)</strong></p><p>The server did not accept the offered key for authentication. Possible reasons include an unregistered public key, an incorrect username, the wrong private key being used, or an account that has not yet been authorized.</p><p>I should verify my username, confirm that the correct public key was registered, and follow the university’s access instructions.</p><p><strong>Problem: </strong><strong>Could not resolve hostname</strong></p><p>My computer could not resolve the hostname. I should check that the hostname was typed correctly and that any required university VPN or network connection is active.</p><p><strong>Problem: </strong><strong>Connection timed out</strong></p><p>My computer could not establish the connection within the expected time. The VM might be unavailable, the network or VPN might be incorrect, or a firewall might be blocking the connection.</p><p>Hope this helps if you have similar confusion. Thank you.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=67b1b89a0468" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Solid-State Drives (SSDs): How They Work and How They Differ from HDDs]]></title>
            <link>https://medium.com/@data_with_abhishek/solid-state-drives-ssds-how-they-work-and-how-they-differ-from-hdds-13d4e008cd85?source=rss-5a1acc3ce7b5------2</link>
            <guid isPermaLink="false">https://medium.com/p/13d4e008cd85</guid>
            <category><![CDATA[data]]></category>
            <category><![CDATA[ssd]]></category>
            <category><![CDATA[computer-engineering]]></category>
            <category><![CDATA[computer-science]]></category>
            <dc:creator><![CDATA[Data with Abhishek]]></dc:creator>
            <pubDate>Mon, 26 Oct 2026 21:46:01 GMT</pubDate>
            <atom:updated>2026-10-26T21:46:01.441Z</atom:updated>
            <content:encoded><![CDATA[<p>In this post, we are going to learn in-depth about the intuition and working of SSDs and compare them with the internal working of Hard Disk Drives. If you want to know more about HDDs first, you can click the link below and read the post first.</p><p>Link to the blog about <a href="https://medium.com/@data_with_abhishek/how-do-hard-disks-work-dc186ac9551b"><strong><em>Hard Disk Drives.</em></strong></a></p><p>Imagine that an HDD is a traditional library where a mechanical arm must move to the correct shelf and wait for a rotating disk to bring the required data into position.</p><p>Now imagine an SSD as a modern library with electronic storage cells, several access routes, and a controller that can coordinate many operations at once. There are no spinning platters and no mechanical arm that must move between tracks.</p><p>That is the fundamental difference between a Hard Disk Drive (HDD) and a Solid-State Drive (SSD).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/549/1*k-6_NJTATwsV68KdfwZ6Gg.png" /></figure><p><strong>An SSD stores data in flash memory chips</strong>. This allows it to access scattered data much more efficiently than an HDD, although SSDs have their own challenges, particularly when writing, erasing, and managing flash memory.</p><p>Let’s explore how SSDs work, using simple definitions, analogies, and examples.</p><p>A Solid-State Drive (SSD) is a storage device that saves data in electronic memory cells, usually NAND flash memory.</p><p>It’s a storage device that saves your operating system, games, pictures, videos, and other files.</p><p>Unlike an HDD, an SSD has no spinning platters or moving heads. It uses electronic memory chips to store information, and your data remains saved when the power is switched off.</p><p>Think of an SSD as a giant electronic notebook made of millions or billions of tiny storage cells.</p><p>Each cell can store information using electrical charge.</p><p>Think of it like this:</p><ul><li>NAND chips are the warehouses containing your stored information.</li><li>The controller is the manager who knows where everything is and coordinates reading, writing, and erasing.</li><li>The SSD is the whole storage system.</li></ul><h3>2. How can electricity store data?</h3><p>This is the most important part to understand.</p><p>Inside an SSD are special memory chips containing tiny components called flash memory cells.</p><p>A simplified way to imagine one cell is as a tiny box that can trap electrical charge.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/842/1*A3HungY930KKIv0rBNeeVw.png" /></figure><p>The SSD’s electronics measure how the cell behaves electrically and use that information to determine which value it represents.</p><p>For a simple beginner example, imagine that one electrical state means 0 and another means 1.</p><p>Real SSDs are a little more complicated: some cells store more than one bit by representing several different charge levels.</p><p>Here’s the amazing part: the cell can retain its stored charge even when the computer is switched off. That’s why the data doesn’t disappear when you unplug your computer.</p><p>The computer can later read the cells and reconstruct the original information.</p><h4>ANALOGY</h4><p>Imagine an HDD as one worker who must walk around a warehouse to find each requested item.</p><p>An SSD is more like a warehouse with many electronic storage sections and a central manager who can coordinate several workers simultaneously.</p><p>The manager is the controller, the storage sections are flash chips, and the communication routes are the channels.</p><p>This design helps explain why SSDs offer both lower access latency and higher potential bandwidth.</p><h3>How does an SSD access data?</h3><p>Suppose your computer requests a file.</p><ol><li>The operating system sends a read request to the SSD.</li><li>The controller translates the requested logical address into the location of the data in flash memory.</li><li>The controller accesses the appropriate flash chips.</li><li>The data travels back through the interface to the computer.</li></ol><p>The operating system generally sees a familiar block-storage device. It does not need to know the physical location of every flash cell. The controller handles much of that complexity internally.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/754/1*pRpFijOM_MWOymLD5bVgwg.png" /></figure><ul><li>A memory cell stores bits.</li><li>A memory die contains enormous numbers of cells.</li><li>A NAND package can contain one or more dies.</li><li>An SSD contains NAND packages plus a controller and other components.</li></ul><h3>Why is an SSD so much faster than an HDD?</h3><p>There are three main reasons.</p><h4><strong>A. No mechanical movement</strong></h4><p>An HDD must move its arm and wait for the platter to rotate to the required location. An SSD has no such mechanical delay.</p><p><strong>Analogy:</strong></p><p>HDD: Walk to a shelf and wait for a carousel to bring the item to you.</p><p>SSD: Retrieve an item electronically from a storage system.</p><p>This is particularly important for random access, where a program requests many small pieces of data from different locations.</p><h4>B. Efficient random access</h4><p>An SSD can access scattered data without mechanically seeking between tracks.</p><p>For example, suppose your operating system needs 100 small files stored in different locations.</p><ul><li>HDD: Repeated mechanical positioning can take considerable time.</li><li>SSD: The controller can access flash locations electronically, without moving a head between tracks.</li></ul><p>SSDs still have access delays, and random reads and writes do not all take the same amount of time. However, they generally handle small, scattered requests much better than HDDs.</p><h4>C. Internal parallelism</h4><p>This is another crucial concept.</p><p>Internal parallelism means that an SSD can perform multiple operations across different flash resources at the same time.</p><p>Imagine a warehouse with four loading docks.</p><ul><li>With one dock, only one truck can be loaded at a time.</li><li>With four docks, several trucks can be loaded simultaneously.</li><li>With more coordinated docks and workers, the warehouse can process more goods per second.</li></ul><p>Similarly, an SSD may have several channels connected to multiple flash chips. Its controller can distribute requests across available resources to increase throughput.</p><p>But there is an important catch: the resources must be available, and there must be enough work to keep them busy.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/757/1*4K5zpzPtlc1I1soTqcMIAw.png" /></figure><p>Imagine an SSD is like a huge library, and the SSD controller is the librarian who knows exactly where every piece of information is stored.</p><h3>The surprising part: Why can’t an SSD simply overwrite any data?</h3><p>We have seen that SSDs are fast. But flash memory has a limitation that makes managing writes more complicated than reading.</p><p>NAND flash generally must erase a larger unit before that unit can be programmed again.</p><p>To understand this, we need two terms.</p><p><strong>Page: </strong>A relatively small unit that flash memory can program or read.</p><p><strong>Erase block</strong>: A larger group of pages that must be erased together.</p><p>In simpler terms,</p><ul><li>A page is like one small sheet of paper in the notebook</li><li>A block is like a group of sheets bundled together.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/311/1*odgGuTDmgsNdvG6lgaw1FQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/628/1*9EPrMNftFo72-qdf1qDHew.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/518/1*_zWjN8qyLjjM1gKegg5iEw.png" /></figure><p>The exact page and erase-block sizes vary by flash technology.</p><p>Imagine a notebook.</p><ul><li>A page is one page of the notebook.</li><li>An erase block is the entire section of the notebook containing many pages.</li></ul><p>Suppose you want to replace a few words on one page. With ordinary paper, you could cross them out and write again. But imagine that the notebook only allowed you to erase an entire section before reusing any of its pages.</p><p>That is roughly the difficulty an SSD controller must handle.</p><p>It cannot simply overwrite arbitrary existing flash data in place as if it were ordinary RAM. Flash programming and erasing follow different rules.</p><h4>Example: Updating a file</h4><p>Suppose a page contains the old value A, and you want to replace it with B.</p><ul><li>The SSD writes the new value to an available flash page.</li><li>The controller updates its mapping so the logical address points to the new value.</li><li>The old page becomes invalid because it no longer contains the current version.</li><li>The old page can be reclaimed later when the surrounding erase block is erased.</li></ul><p>The computer sees a normal update to the file, but the SSD may have written the new data somewhere else physically.</p><p>This process is one reason the SSD controller is so important.</p><p>Let&#39;s understand the above example with a simple and clear example:</p><p>Imagine you have a notebook on your computer<br>- Your file notes.txt contains:</p><p><em>My favorite color is blue.</em></p><p>You change the word blue to green and press <strong>Save.</strong></p><p>You might think the SSD simply erases blue and writes green in the same place. But NAND flash memory doesn&#39;t usually work that way!</p><p>Let’s see what really happens.</p><h4>Step 1: The computer asks the SSD to save the change</h4><p>You press <strong>Save</strong> on your computer. The computer tells the SSD, “Please update this piece of information!” The computer uses a number called a logical address to identify where that data belongs. Think of it like telling a librarian, “Please update the book on shelf number 100.”</p><h4>Step 2: The SSD controller finds the information</h4><p>Inside the SSD, a tiny manager called the controller acts like the librarian. It uses a special list called the FTL (Flash Translation Layer) to find where the data is physically stored.</p><p>For example, the controller’s list says:</p><p>- Logical address 100 → Block 7, Page 3.</p><p>The computer knows the logical address, but the controller knows the actual physical location.</p><h4>Step 3: The SSD writes the new data somewhere else</h4><p>Here’s the interesting part!</p><p>The SSD usually cannot simply erase the old page and write the new data into that exact same page.</p><p>So the controller finds an empty page and writes the updated data there.</p><p><strong><em>OLD LOCATION</em></strong></p><p><strong><em>Block 7, Page 3</em></strong></p><p><strong><em>My favorite color is blue.</em></strong></p><p>Now, the new location becomes:</p><p><strong><em>NEW LOCATION</em></strong></p><p><strong><em>Block 12, Page 5</em></strong></p><p><strong><em>My favorite color is green.</em></strong><br>The new data is now stored in a different physical location!</p><h4>Step 4: The controller updates its list</h4><p>Now the controller updates its special list to remember where the latest data is stored.</p><p>Before the update:</p><p>Address 100 → Block 7, Page 3</p><p>After the update:</p><p>Address 100 → Block 12, Page 5</p><p>Why is this important?</p><p>Because next time the computer asks for the information, the controller must find the new version, not the old one.</p><h4>Step 5: The old page becomes invalid</h4><p>The old page still contains the word blue, but that is no longer the latest version. The controller marks that page as invalid. Important: invalid does not mean the old data disappears immediately. It means the SSD no longer treats that page as the current version.</p><p>It’s like an old book that has outdated information. The book is still sitting on the shelf, but the librarian knows not to use it as the latest reference.</p><h4><strong>Step 6: The SSD cleans up the old storage</strong></h4><p>Eventually, the SSD needs more space.</p><p>It cleans up blocks containing old, invalid pages. But there is a catch: NAND flash erases a whole block at once, not just one page.</p><p>Imagine a block is a bookshelf with four pages stored on it:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/764/1*ht2UszvIPjarL6z0fisIvg.png" /></figure><p>The SSD first moves the needed data to another location. Then it erases the entire block, making all its pages available for reuse.</p><p>This cleaning process is called garbage collection.</p><h3>Why can garbage collection slow an SSD down?</h3><p>The controller has extra work to do:</p><ul><li>Identify blocks that contain invalid pages.</li><li>Copy any valid pages that must be retained.</li><li>Erase the selected blocks.</li><li>Make the newly available space ready for future writes.</li></ul><p>This work consumes time and flash bandwidth. If an incoming write arrives when free space is scarce, the SSD may need to perform garbage collection before it can complete the request.</p><p>That can create an unexpected delay, even when the SSD is normally very fast. Many SSDs try to perform some of this work in the background, but background maintenance can still compete with user requests for resources.</p><h3>What is write amplification?</h3><p>Write amplification measures how much data the SSD physically writes compared with how much data the computer logically asks it to write. The formula is:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/411/1*LBoD106hzraBXEug-1BlXg.png" /></figure><p>Consider this example:</p><p>Your computer asks the SSD to write 100 MB of new data.</p><p>To make room and organize its flash blocks, the SSD ends up physically writing 150 MB, including data relocated during garbage collection.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/344/1*Ep3Nsfik5lK0lKmo4Att2A.png" /></figure><p>This means the SSD physically wrote 1.5 times the amount of data requested by the computer.</p><p>High write amplification has two important consequences:</p><p><strong>Performance:</strong> Extra internal writing consumes time and bandwidth.</p><p><strong>Endurance</strong>: Extra writes contribute to flash memory wear.</p><h3>What is wear leveling?</h3><p>Flash memory cells have limited program/erase endurance. Repeatedly programming and erasing the same physical blocks gradually wears them out.</p><p>Wear leveling is the SSD controller’s method of distributing writes across flash blocks so that some blocks do not wear out much sooner than others.</p><p>Imagine a school with 100 classrooms. If every lesson takes place in the same classroom, that room gets much more use than the others.</p><p>A sensible school rotates classroom use. Similarly, an SSD controller tries to distribute wear across the available flash blocks.</p><h3>Why can SSD latency sometimes be unpredictable?</h3><p>You might expect an SSD to return every request in roughly the same amount of time because it has no moving parts. But this is not always true.</p><p>Suppose the SSD receives a write request.</p><ul><li>If enough free pages are available, the write may finish quickly.</li><li>If free space is limited, garbage collection may be required.</li><li>If valid pages must be relocated before a block can be erased, extra work is necessary.</li><li>If many requests compete for the same flash channels, the controller must schedule them.</li><li>If a write triggers substantial background maintenance, a request can take much longer than an ordinary request.</li></ul><p>Imagine a supermarket checkout. Normally, a customer is served quickly. But if the cashier must restock shelves and reorganize the shop before completing a transaction, the waiting time increases.</p><p>This is why SSD performance is often evaluated not only by average latency but also by tail latency.</p><p>Tail latency means the waiting time experienced by the slowest portion of requests, such as the slowest 1% of requests.</p><p>For databases and other latency-sensitive applications, those occasional long delays can be important even when average SSD latency is low.</p><h3>Logical addresses versus physical addresses</h3><p>The operating system typically sends requests using logical block addresses (LBAs).</p><p>An LBA identifies a logical location on the storage device. It does not directly tell the operating system which physical flash cell stores that data.</p><p>The SSD controller maintains the mapping between logical addresses and physical locations. This mapping is part of the Flash Translation Layer (FTL).</p><p>Analogy: You know a book’s library catalogue number, but the librarian knows which shelf and position currently hold the book.</p><p>When data is rewritten, the SSD may store it at a different physical location. The controller updates the mapping so the computer can still access the data using the same logical address.</p><h3>SSD vs. HDD: The complete comparison</h3><h4>HDD — Hard Disk Drive</h4><ul><li>Stores data magnetically on spinning platters.</li><li>Uses a mechanical arm and read/write heads.</li><li>Has relatively high random-access latency.</li><li>Offers good sequential throughput for its price.</li><li>Traditionally costs less per terabyte.</li><li>Mechanical movement and shock sensitivity are concerns.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/486/1*KlBb20uv4XobnOZRKM5q3g.png" /></figure><h4>SSD — Solid-State Drive</h4><ul><li>Stores data in flash memory cells.</li><li>Has no spinning platters or mechanical arm.</li><li>Offers much lower random-access latency.</li><li>Can deliver very high sequential bandwidth, especially over PCIe/NVMe.</li><li>Traditionally costs more per terabyte.</li><li>Has limited flash endurance and requires internal data management.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*h5yUJyKLSor091yWv32Q4w.png" /></figure><h3>The final analogy: Two different warehouses</h3><p>Imagine two warehouses that both store 1 million products.</p><h4>Warehouse A — HDD</h4><p>One mechanical crane moves to the correct aisle. The shelves rotate or move the item into position. Once the crane reaches the correct location, it can retrieve many nearby items efficiently.</p><h4>Warehouse B — SSD</h4><p>An electronic manager coordinates many storage sections. It can retrieve scattered items quickly and operate across multiple sections in parallel. However, the warehouse must also reorganize storage areas, clear outdated items, and spread usage to avoid excessive wear.</p><p>The HDD’s major limitation is mechanical positioning. The SSD’s main complications come from the way flash memory must be programmed, erased, and managed.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=13d4e008cd85" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How do hard disks work?]]></title>
            <link>https://medium.com/@data_with_abhishek/how-do-hard-disks-work-dc186ac9551b?source=rss-5a1acc3ce7b5------2</link>
            <guid isPermaLink="false">https://medium.com/p/dc186ac9551b</guid>
            <category><![CDATA[hard-disk]]></category>
            <category><![CDATA[memories]]></category>
            <category><![CDATA[computer-science]]></category>
            <category><![CDATA[software-engineering]]></category>
            <dc:creator><![CDATA[Data with Abhishek]]></dc:creator>
            <pubDate>Sun, 25 Oct 2026 13:05:09 GMT</pubDate>
            <atom:updated>2026-10-25T13:05:09.711Z</atom:updated>
            <content:encoded><![CDATA[<p>Imagine you are in a huge library. Thousands of books are stored on shelves, and you need to find a particular page in a particular book.</p><p>Sometimes, the book is right in front of you. Sometimes, you must walk to another shelf, find the book, open it, and locate the page. The time spent finding the book may be much longer than the time spent reading the page.</p><p>In this post, we will learn the fundamentals of a hard disk drive in the simplest possible way with necessary analogies.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/389/1*aXqhbJoqmWC7NVRkO7rjhQ.png" /></figure><p>A hard disk drive (HDD) works in a similar way. It stores data on spinning magnetic disks, and the time needed to locate that data can be more important than the time needed to read it.</p><p>Let’s understand each technical term using simple definitions and everyday analogies.</p><h3>1. What is a hard disk?</h3><p>A hard disk drive (HDD) is a storage device that saves information, such as operating systems, photos, videos, documents, and applications.</p><p>Unlike RAM, which stores data electronically while the computer is running, an HDD stores data magnetically on rotating disks. The data remains stored even when the power is switched off.</p><p>It stores information using tiny magnetic areas on the surface of the platter.</p><p>Think of it this way:</p><ul><li>Imagine a huge sheet covered with billions of incredibly tiny dots.</li><li>Each dot can be magnetized in one of two different ways.</li><li>The computer uses these magnetic patterns to represent information.</li></ul><p>These patterns represent the numbers 0 and 1which are called bits.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/767/1*bn206z8Q9d84d7NMuO9zMw.png" /></figure><h3>The main parts of a hard disk</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/596/1*SixXam5tVX1_Dj4QBwbUFw.png" /></figure><h4>1. Platters</h4><p>Simple meaning: The circular disks that store data.</p><p>Analogy: Like the circular records on a record player. Magnetic patterns on their surfaces represent data.</p><h4>2. Disk head (read/write head)</h4><p>Simple meaning: The part that reads data from or writes data to the platter.</p><p>Analogy: Like the reading tip of a record player. It accesses the data at the selected position without touching the spinning platter in a modern HDD.</p><h4>3. Actuator arm</h4><p>Simple meaning: The arm that moves the head to the required track.</p><p>Analogy: Like moving your hand across a bookshelf to reach a particular shelf.</p><h4>4. Spindle</h4><p>Simple meaning: The central shaft that holds and rotates the platters.</p><p>Analogy: Like the central axle of a rotating carousel.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/523/1*3u-9_ftE7xduf46J-3W33w.png" /></figure><p>Till now, we have learned what a hard disk drive looks like. Now, the terms described below explain how information is organized on a hard disk.</p><p>Imagine that each platter is a circular city map.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/548/1*jITDOZBaEV_IGmWU6MGn1A.png" /></figure><h3>A. Tracks — circular paths on the platter</h3><p>A track is a circular path on the platter where data is recorded.</p><p>Imagine a dartboard with many circular rings. Each ring represents a track.</p><ul><li>Tracks are arranged in concentric circles.</li><li>A track closer to the outer edge has a larger circumference than a track near the center.</li><li>The head must be positioned over the correct track to access the desired data.</li></ul><p>Analogy: Tracks are like the circular lanes on a running track.</p><h3>B. Sectors — small divisions of a track</h3><p>A sector is a small, addressable physical region of a track. Traditionally, HDD sectors have commonly been 512 bytes or 4,096 bytes (4 KiB), although formats vary.</p><p>Imagine dividing a circular pizza into slices. Each slice represents a sector-like portion of the circle.</p><ul><li>A track contains many sectors.</li><li>Sectors provide physical locations in which data can be recorded.</li></ul><p>Analogy: A track is a circular road, and sectors are the numbered parking spaces arranged along it</p><h3>C. Blocks — units of data handled by the computer</h3><p>A block is a unit of storage that the operating system or storage system reads or writes.</p><p>In simple examples, a block might be 4 KiB (4,096 bytes). Depending on the system, a block may correspond to one sector or several sectors.</p><p>Imagine ordering a box of books from a warehouse. You request a whole box rather than asking the warehouse to hand over individual letters from the books.</p><p>Analogy: A block is like a package of data collected from the disk in one operation.</p><p>Important distinction:</p><ul><li>Sector: A physical storage unit on the disk.</li><li>Block: A logical or operational unit used by the computer’s storage system.</li></ul><p>The terms are sometimes used interchangeably in introductory explanations, but they are not always identical.</p><h3>D. Cylinder — tracks at the same radius across platters</h3><p>A cylinder is the collection of tracks at the same radial position on different platter surfaces.</p><p>Imagine stacking several circular dartboards one above another. Draw an imaginary vertical line through the same circular position on each board. The tracks intersected at that position form a cylinder.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/544/1*B6Jil7O-KKwzkATfbjqY9A.png" /></figure><p><strong>Why is this useful?</strong></p><p>Because the heads are attached to the same actuator assembly, moving the arm positions the heads over corresponding tracks on the different surfaces. Switching between those heads may allow access to another track in the same cylinder without moving the arm to a different radius.</p><h3>How does an HDD find and read data?</h3><p>Suppose you want to open a photo stored on your hard disk.</p><p>The computer knows the address of the required data. The drive must position its head and wait until the relevant data passes beneath it.</p><p><strong>Step 1: Seek</strong></p><p>The actuator arm moves the head to the correct track.</p><p>Analogy: Walking to the correct bookshelf.</p><p><strong>Step 2: Wait for rotation</strong></p><p>The platter continues spinning until the desired sector or block reaches the head.</p><p>Analogy: Waiting for the page you need to rotate into view.</p><p><strong>Step 3: Transfer</strong></p><p>The head reads the data as the platter spins, and the drive transfers it to the computer.</p><p>Analogy: Reading or copying the required page.</p><p>These three steps explain the three important parts of HDD access latency.</p><h3>What is access latency?</h3><p>Access latency is the time spent waiting to access the requested data.</p><p>For an HDD, the basic model is:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/325/1*mxmnaRt39GITDs-yvbsHQg.png" /></figure><h4>A. Seek time</h4><p>Seek time is the time taken to move the actuator arm and head to the required track.</p><p>Imagine you are in a library on the ground floor, but the book you need is on a different floor. You must travel to the correct location before reading it.</p><ul><li>Moving to a nearby track may be relatively quick.</li><li>Moving to a distant track can take longer.</li><li>The arm must settle into the correct position before reading reliably.</li></ul><h4>B. Rotational delay (rotational latency)</h4><p>Rotational delay is the time spent waiting for the required sector to rotate under the head after the head reaches the correct track.</p><p>Imagine you are standing beside a carousel. You can see the carousel, but you must wait for your particular suitcase to come around to you.</p><p>For a drive spinning at a constant speed, the average rotational delay is approximately half a rotation.</p><p>That is why the disk’s rotation speed matters: a faster-spinning disk generally has a shorter average rotational delay.</p><h4>C. Transfer time</h4><p>Transfer time is the time required to read or write the requested data once it is available beneath the head.</p><p>Imagine the book is open at the correct page. The time required to copy the paragraph is the transfer time.</p><p>Transfer time depends on:</p><ul><li>How much data must be read or written.</li><li>How quickly the disk can transfer that data.</li><li>The location and physical characteristics of the disk.</li></ul><p>For a small request such as 4 KiB, transfer time can be much less than the time spent moving the arm and waiting for rotation.</p><p><strong>The big lesson</strong>: An HDD can spend more time finding data than actually reading it.</p><h3>Latency vs. bandwidth: What is the difference?</h3><p>These two terms sound similar, but they measure different things.</p><ul><li>Latency: How long you wait before an operation completes or data starts arriving.</li><li>Bandwidth: How much data can be transferred per second.</li></ul><p>Imagine a delivery truck.</p><ul><li>Latency is the time it takes the truck to reach your house.</li><li>Bandwidth is how many boxes the truck can deliver per minute once delivery is underway.</li></ul><h3>Random access vs. sequential access</h3><p>Suppose you need 100 pages from a library, but every page is in a different book on a different shelf.</p><p>For each page, you may need to:</p><ol><li>Find the correct shelf.</li><li>Wait until you locate the correct page.</li><li>Copy the page.</li></ol><p>You repeat this process for every request.</p><p>That is similar to random disk access, where successive data requests are at different physical locations on the disk.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/550/1*B3jhuqS2xzAxf233GWoReg.png" /></figure><p>The drive repeatedly pays the cost of finding the next location.</p><h3>Sequential access: Data is next to each other</h3><p>Now imagine the 100 pages are all consecutive pages in the same book.</p><p>You find the book and the first page once. Then you continue reading the next pages without going back to the library shelves every time.</p><p>That is similar to sequential disk access, where the requested blocks are stored consecutively or close together.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/621/1*JekO0PuZdLR8lTBNQ4MdFQ.png" /></figure><p>The important difference is that the model does not charge a new seek and rotational delay for every block.</p><h3>Let’s calculate the difference with an example</h3><p>Suppose the following values are used for illustration:</p><ul><li>Seek time = 5 ms.</li><li>Average rotational delay = 4 ms.</li><li>Transfer time per block = 0.1 ms.</li><li>Number of blocks = 100.</li></ul><p>The positioning overhead is:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/217/1*xZQDqsfR5S63JQhPOH9Fdg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/784/1*B7a8euHRjPb3xQJFzIlanA.png" /></figure><p>The one-sentence takeaway: Sequential access is much faster than random access on a hard disk because it avoids repeatedly moving the arm and waiting for the platter to rotate to a new location.</p><p>I hope this post helps you to know how the hard disk internally functions. See you in the next post with a different topic!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=dc186ac9551b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Single-Core, Multi-Core, and Multi-Socket Multi-Core Systems]]></title>
            <link>https://medium.com/@data_with_abhishek/single-core-multi-core-and-multi-socket-multi-core-systems-b85240ac612e?source=rss-5a1acc3ce7b5------2</link>
            <guid isPermaLink="false">https://medium.com/p/b85240ac612e</guid>
            <category><![CDATA[cpu]]></category>
            <category><![CDATA[cloud-computing]]></category>
            <category><![CDATA[networking]]></category>
            <category><![CDATA[computer-science]]></category>
            <dc:creator><![CDATA[Data with Abhishek]]></dc:creator>
            <pubDate>Sun, 25 Oct 2026 09:35:02 GMT</pubDate>
            <atom:updated>2026-10-25T09:35:02.777Z</atom:updated>
            <content:encoded><![CDATA[<p>We will understand these concepts in computer architecture with a proper analogy. At the end, you will be able to relate these topics to the analogy.</p><h4>Imagine a restaurant.</h4><p>The chefs represent CPU cores, the kitchen represents a processor, the pantry represents RAM, and the ingredients kept close to each chef represent cache memory.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WTPWqJg2vMvVjAIAhi0jCg.png" /></figure><h3>1. Single-Core System</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/380/1*hgVmNkJ-kzsHAEzmieKiOA.png" /></figure><p>A single-core system has one processing core executing instructions. It can switch between tasks, but on a conventional single-core CPU, it cannot execute multiple instruction streams simultaneously on that core.</p><h4>RESTAURANT ANALOGY</h4><p>One chef, one kitchen station</p><p>The chef prepares one dish at a time, switching between orders when needed. There is no second chef to prepare another dish simultaneously.</p><ul><li>CPU core: One chef.</li><li>Registers: Ingredients or tools in the chef’s hands.</li><li>L1 cache: A small tray beside the chef.</li><li>L2 cache: A nearby shelf.</li><li>RAM: The kitchen pantry.</li><li>SSD/HDD: The restaurant’s external warehouse</li></ul><h3>2. Multi-Core System</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/643/1*7D-wNqSUE0lXwSzQaVdBYw.png" /></figure><p>A multi-core system has two or more processing cores within a single processor package. Multiple cores can execute separate instruction streams simultaneously, provided the software and workload allow it.</p><h4>RESTAURANT ANALOGY</h4><p>Four chefs, one kitchen</p><p>Each chef can prepare a different dish at the same time. Each has nearby tools and may share the same pantry.</p><p>For a four-core processor:</p><ul><li>4 cores: Four chefs.</li><li>Private L1 caches: Each chef has a personal tray.</li><li>Private L2 caches: Each chef may have a personal shelf, depending on the CPU design.</li><li>Shared L3 cache: A common preparation counter or shared shelf.</li><li>RAM: The shared pantry.</li><li>SSD/HDD: The external warehouse.</li></ul><p>The exact cache arrangement depends on the processor. Some processors share certain cache levels, while others keep them private.</p><h3>3. Multi-Socket Multi-Core System</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/658/1*HOlt0WN1VrG_lZSOnhdnDg.png" /></figure><p>A multi-socket system has two or more physical processor packages installed in one computer. Each processor package can contain multiple cores.</p><p>For example, a server with two sockets and 16 cores per processor has:</p><p>2 sockets×16 cores=32 cores2 sockets×16 cores=32 cores</p><h4>RESTAURANT ANALOGY</h4><p>Two kitchens, multiple chefs in each</p><p>Each kitchen has its own chefs, local shelves, and pantry. The kitchens can coordinate and exchange ingredients, but transferring ingredients between them may take longer than using a kitchen’s own pantry.</p><ul><li>Two sockets: Two physical kitchens or processor packages.</li><li>Multiple cores per socket: Multiple chefs in each kitchen.</li><li>Private L1/L2 caches: Personal trays and shelves.</li><li>Last-level cache (often L3): A shared shelf within a processor, depending on the design.</li><li>Local RAM: Each processor’s nearby pantry.</li><li>Remote RAM: The other processor’s pantry, accessed through the interconnect.</li></ul><p>This arrangement commonly uses NUMA (Non-Uniform Memory Access). A core can generally access memory attached to its own socket with lower latency than memory attached to another socket.</p><p>This is the most important part:<strong> more cores do not automatically mean faster memory access. </strong>Every core still needs data, and the time spent fetching that data can limit performance.</p><h3>How does the hierarchy work?</h3><p>Suppose a core needs a variable called x.</p><ol><li>The CPU checks its registers.</li><li>If the value is not available there, it checks the relevant cache levels.</li><li>If the cache misses, it fetches the required data from RAM.</li><li>If the required data must first be read from an SSD, the operating system typically loads it into RAM before the CPU uses it.</li></ol><p>The CPU does not ordinarily read every variable directly from an SSD. Registers and caches hold data needed for active computation, while RAM holds the programs and data currently in use.</p><p>Let’s revise the concepts we learned above.</p><p>Imagine processing 1,000 customer orders.</p><ul><li>Single-core: One chef processes all 1,000 orders.</li><li>Four-core: Four chefs divide the orders, processing approximately 250 each.</li><li>Two sockets × 16 cores: Two kitchens have 16 chefs each, so 32 chefs can process orders in parallel.</li></ul><p>Now suppose every chef needs the same ingredient.</p><ul><li>If the ingredient is already on a chef’s tray, it is like a cache hit.</li><li>If the chef needs the shared pantry, it is like accessing RAM.</li><li>If a chef must fetch ingredients from the other kitchen, it is like a remote NUMA memory access.</li></ul><p>Even with 32 chefs, the restaurant may not be 32 times faster if everyone is waiting for the same pantry or sharing limited resources.</p><h3>The key takeaway</h3><h4>Single-core</h4><p>One processing worker; a single core uses its cache hierarchy to access data efficiently.</p><h4>Multi-core</h4><p>Many processing workers inside one processor package, with private and/or shared caches.</p><h4>Multi-socket, multi-core</h4><p>Multiple processor packages, each with multiple cores, connected through an interconnect and potentially having local memory.</p><p>I hope from now on, you can clearly differentiate between these architectures with the analogy of restaurant.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b85240ac612e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[ 20 System Design Concepts Every Developer Should Know]]></title>
            <link>https://medium.com/@data_with_abhishek/20-system-design-concepts-every-developer-should-know-b776ecc2bb07?source=rss-5a1acc3ce7b5------2</link>
            <guid isPermaLink="false">https://medium.com/p/b776ecc2bb07</guid>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[system-design-interview]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[design]]></category>
            <dc:creator><![CDATA[Data with Abhishek]]></dc:creator>
            <pubDate>Sat, 04 Apr 2026 15:11:03 GMT</pubDate>
            <atom:updated>2026-04-04T15:11:03.786Z</atom:updated>
            <content:encoded><![CDATA[<p>System design can feel overwhelming at first — so many moving parts, trade-offs, and buzzwords. But at its core, it’s about building systems that are scalable, reliable, and efficient.</p><p>Here’s a clear and concise breakdown of 20 essential system design concepts that form the backbone of modern applications.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/656/1*5W8AP4qN4muzXW9k5nj-Yg.png" /></figure><h3>1. Vertical Scaling (Scale Up)</h3><p>Vertical scaling means increasing the power of a single server — adding more CPU, RAM, or storage.<br>It’s simple to implement but has physical limits and can become expensive.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/546/1*W6WRxPEli2lC34E02F1Grw.png" /></figure><h3>2. Horizontal Scaling (Scale Out)</h3><p>Instead of upgrading one machine, you add more servers to distribute the load.<br>This improves fault tolerance and allows systems to handle massive traffic.</p><h3>3. Load Balancers</h3><p>A load balancer sits in front of your servers and distributes incoming requests evenly.<br>It prevents any single server from being overwhelmed and improves reliability. It is also called “Reverse Proxy”.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/668/1*XA8hxmvWTOVKmwxAYPaEAQ.png" /></figure><h3>4. Content Delivery Networks (CDN)</h3><p>CDNs cache static content (like images, videos, and scripts) on servers worldwide.</p><p>By serving data from the nearest “edge server” rather than a distant central origin server, CDNs significantly reduce latency, speed up website loading, lower bandwidth costs, and improve site reliability.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/665/1*WxA9T1Y5zKUn-TgoV0wHxA.png" /></figure><h3>5. Caching</h3><p>Caching stores frequently accessed data in memory or fast storage.<br>It reduces expensive database or network calls, significantly improving performance.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/628/1*O2oU7Zl998GZWwr4yVtr1Q.png" /></figure><h3>6. IP Address</h3><p>An IP address is a unique identifier assigned to each device on a network.<br>It enables devices to locate and communicate with each other over the internet.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/807/1*uB05xg9zdIjPaMcx2qTWYw.png" /></figure><h3>7. TCP/IP</h3><p>TCP/IP is the fundamental protocol suite of the Internet.<br>It is the fundamental set of standardized rules that enable computers to communicate and share data over the internet or private networks. It breaks data into packets, ensures reliable delivery, and routes information efficiently across varied systems. It is the bedrock protocol suite that allows the modern internet to function.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/510/1*VxdjIg5qK-G5O_oJz1wzgg.png" /></figure><h3>8. Domain Name System (DNS)</h3><p>DNS translates human-friendly domain names (like google.com) into IP addresses.<br>Think of it as the internet’s phonebook.</p><p><strong>How They Work:</strong> When you enter a URL, your computer sends a request to a recursive DNS resolver, which navigates a hierarchy of servers (root, TLD, authoritative) to find the correct IP address.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/645/1*Teq0lZVVoKYQvqYCqyDCWw.png" /></figure><h3>9. HTTP</h3><p>HTTP is the protocol used for communication between clients and servers.<br>It defines how requests and responses are structured and transmitted.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/652/1*vsffDurIDyABobZmdUkYRA.png" /></figure><h3>10. REST</h3><p>REST is an API design style that uses standard HTTP methods (GET, POST, etc.).<br>It is stateless, scalable, and widely adopted for web services.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/650/1*5cxxKIYMYwsjtfV2QIlP6A.png" /></figure><h3>11. GraphQL</h3><p>GraphQL allows clients to request exactly the data they need in a single query.<br>This avoids over-fetching or under-fetching data.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/704/1*_tMu6a4-FbjsB68TDC5glg.png" /></figure><h3>12. gRPC</h3><p>gRPC is a high-performance communication framework using binary protocols. gRPC is a high-performance alternative designed for internal microservices, prioritizing speed and efficiency through binary serialization.<br>It’s ideal for fast, efficient communication between backend services. It is often <strong>3–10x faster</strong> than REST because of its binary format and efficient transport.</p><p>Google Remote Procedure Call is a way for one computer program to call a function in another program — on a different machine — as if it were a local function on its own computer.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/671/1*LRIIc4dRrsIWLasgKajdmA.png" /></figure><h3>13. WebSockets</h3><p>WebSockets enable persistent, real-time communication between client and server.<br>Perfect for chat apps, live notifications, and multiplayer games.</p><p>WebSockets are a communications protocol that provides full-duplex (two-way), real-time communication between a client (like a web browser) and a server over a single, long-lived TCP connection.</p><p>WebSockets allow either party to send data at any time without waiting for a request.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/636/1*l4nGJPEqcbgvtLUfENnmCA.png" /></figure><h3>14. SQL Databases</h3><p>SQL databases use structured tables with predefined schemas.<br>They are reliable and ideal for applications requiring complex queries.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/525/1*vZWwRdmD3O0ooy3ZRYdNNg.png" /></figure><h3>15. ACID Properties</h3><p>ACID ensures reliable database transactions:</p><ul><li><strong>Atomicity</strong>: All or nothing</li><li><strong>Consistency</strong>: Data remains valid</li><li><strong>Isolation</strong>: Transactions don’t interfere</li><li><strong>Durability</strong>: Data persists after completion</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/689/1*8yKdrlETi5BMH_nWU8t99w.png" /></figure><h3>16. NoSQL Databases</h3><p>NoSQL databases are flexible and schema-less.<br>They are designed for scalability and handle large, unstructured datasets.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/508/1*1hyIJGCwVUzjEzkNrN0YcQ.png" /></figure><h3>17. Sharding</h3><p>Sharding splits a database into smaller pieces across multiple machines.<br>Each shard holds a subset of data, improving scalability.</p><p>Shard Key: A specific column (e.g., user_id, region) used to determine which shard a particular row belongs to.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/819/1*PjvrGuv9IGI4rfpG_bBNxQ.png" /></figure><h3>18. Replication</h3><p>Replication creates copies of data across multiple servers.<br>It increases read performance and ensures data availability during failures.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/568/1*p3MBaXr9IIWIV3wWoEEcGw.png" /></figure><ul><li><strong>Single-Leader (Primary/Replica):</strong> All write operations occur on a single primary node, which then replicates data to secondary nodes that primarily handle read operations.</li><li><strong>Multi-Leader (Multi-Master):</strong> Writes can be submitted to any of multiple leader nodes, which then sync with each other. This is complex but useful for multi-data center setups.</li><li><strong>Leaderless (Masterless):</strong> All nodes handle reads and writes, providing high availability.</li></ul><h3>19. CAP Theorem</h3><p>CAP theorem states that in distributed systems, you can only guarantee two of the following three:</p><ul><li>Consistency</li><li>Availability</li><li>Partition Tolerance</li></ul><p>The distributed databases can only provide two of three guarantees: Consistency (all nodes see the same data), Availability (every request gets a response), and Partition Tolerance (the system works despite network failures)</p><p>Trade-offs are unavoidable.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/710/1*flPtP92d-W6zWnSN-qr-Yg.png" /></figure><p><strong>The Trade-offs (When P occurs):</strong></p><ol><li><strong>CP (Consistency + Partition Tolerance):</strong> If nodes cannot communicate, the system shuts down or returns an error to ensure data remains consistent, sacrificing availability. (e.g., MongoDB, Redis, HBase).</li><li><strong>AP (Availability + Partition Tolerance):</strong> The system remains operational, allowing nodes to return potentially outdated data to ensure it is available, sacrificing consistency. (e.g., Cassandra, DynamoDB, CouchDB).</li><li><strong>CA (Consistency + Availability):</strong> This combination is only possible if there are no network partitions (no P), which is unrealistic for distributed systems.</li></ol><h3>20. Message Queues</h3><p>Message queues allow asynchronous communication between services.<br>They decouple components and help manage spikes in traffic by buffering tasks.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*U8Xto46rO7LAflMzpx5RPA.png" /></figure><h3>🎯 Final Thoughts</h3><p>Understanding these concepts is crucial for designing systems that scale and perform well under pressure. You don’t need to master everything at once — but building intuition around these fundamentals will take you a long way in backend engineering and system architecture.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b776ecc2bb07" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[NeetCode Journey — Question 2: Valid Anagram]]></title>
            <link>https://medium.com/@data_with_abhishek/neetcode-journey-question-2-valid-anagram-2cbfec6359a0?source=rss-5a1acc3ce7b5------2</link>
            <guid isPermaLink="false">https://medium.com/p/2cbfec6359a0</guid>
            <category><![CDATA[data-structures]]></category>
            <dc:creator><![CDATA[Data with Abhishek]]></dc:creator>
            <pubDate>Fri, 27 Mar 2026 13:56:57 GMT</pubDate>
            <atom:updated>2026-03-27T13:56:57.516Z</atom:updated>
            <content:encoded><![CDATA[<p>Continuing my journey of solving <strong>one problem per session</strong> from the NeetCode 150 list:<br><a href="https://neetcode.io/practice/practice/neetcode150">https://neetcode.io/practice/practice/neetcode150</a></p><p>Today’s problem was <strong>“Valid Anagram”</strong> — and honestly, this one felt a bit challenging at first.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/373/1*6fxUZkzkaZeZdhyNiQ2iUg.png" /></figure><h3>Problem</h3><p>Given two strings s and t, return <strong>true</strong> if they are anagrams of each other.</p><p>An anagram means:</p><ul><li>Same characters</li><li>Same frequency</li><li>Order doesn’t matter</li></ul><p><strong>Example:</strong></p><p>s = &quot;racecar&quot;, t = &quot;carrace&quot; → True<br>s = &quot;jar&quot;, t = &quot;jam&quot; → False</p><h3>My Initial Approach (Using HashMaps)</h3><p>The hint about <strong>frequency counting</strong> helped me come up with this:</p><pre>class Solution:<br>    def isAnagram(self, s: str, t: str) -&gt; bool:<br>        f_of_s = {}<br>        f_of_t = {}<br>        <br>        for char in s:<br>            if char in f_of_s:<br>                f_of_s[char] += 1<br>            else:<br>                f_of_s[char] = 1<br>                <br>        for char in t:<br>            if char in f_of_t:<br>                f_of_t[char] += 1<br>            else:<br>                f_of_t[char] = 1<br>                <br>        if f_of_s == f_of_t:<br>            return True<br>        else:<br>            return False</pre><h3>Complexity:</h3><ul><li><strong>Time:</strong> O(n + m) ✅</li><li><strong>Space:</strong> O(n) ❌</li></ul><p>The time complexity was good, but space complexity didn’t meet the <strong>recommended O(1)</strong>. Also, I was using 2 dictionaries which was not a good approach.</p><h3>Optimized Approach (Fixed Size Array)</h3><p>This is where things got interesting.</p><p>Since the problem says:</p><blockquote><em>only lowercase English letters</em></blockquote><p>That means we only have <strong>26 possible characters</strong>.</p><p>So instead of using dictionaries, we can use a <strong>fixed-size array of 26</strong>.</p><pre>class Solution:<br>    def isAnagram(self, s: str, t: str) -&gt; bool:<br>        if len(s) != len(t):<br>            return False<br>    arr = [0] * 26<br>        for char in s:<br>            index = ord(char) - ord(&quot;a&quot;)<br>            arr[index] += 1<br>        for char in t:<br>            index = ord(char) - ord(&quot;a&quot;)<br>            arr[index] -= 1<br>        for num in arr:<br>            if num != 0:<br>                return False<br>        return True</pre><h3>Key Idea</h3><ul><li>Use one array</li><li>Increment for string s</li><li>Decrement for string t</li><li>If everything cancels out → anagram ✅</li></ul><h3>Complexity</h3><ul><li><strong>Time:</strong> O(n + m) ✅</li><li><strong>Space:</strong> O(1) ✅ (because array size is always 26)</li></ul><h3>What I Learned</h3><ul><li>My first instinct (hashmap) was correct but not optimal.</li><li>Constraints matter A LOT — they help you optimize.</li><li>Fixed-size arrays can replace hashmaps when the input domain is small.</li><li>This problem really improved my thinking around <strong>space optimization</strong>.</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2cbfec6359a0" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[NeetCode Journey — Question 1: Contains Duplicate]]></title>
            <link>https://medium.com/@data_with_abhishek/neetcode-journey-question-1-contains-duplicate-ccdbf5dc68c6?source=rss-5a1acc3ce7b5------2</link>
            <guid isPermaLink="false">https://medium.com/p/ccdbf5dc68c6</guid>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[data]]></category>
            <category><![CDATA[data-structures]]></category>
            <category><![CDATA[problem-solving]]></category>
            <dc:creator><![CDATA[Data with Abhishek]]></dc:creator>
            <pubDate>Wed, 25 Mar 2026 16:04:09 GMT</pubDate>
            <atom:updated>2026-03-25T16:04:09.224Z</atom:updated>
            <content:encoded><![CDATA[<p>I recently started solving <strong>one problem each session</strong> from the NeetCode 150 list to improve my problem-solving skills and deepen my understanding of data structures.<br>Here is the link to the list I’m following:<br><a href="https://neetcode.io/practice/practice/neetcode150">https://neetcode.io/practice/practice/neetcode150</a></p><p>Today’s problem was <strong>“Contains Duplicate.”</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/381/1*1cQCOea5LciLporGmZcpfQ.png" /></figure><h3>Problem</h3><p>Given an integer arraynums, return <strong>true</strong> if any value appears more than once in the array, otherwise return <strong>false</strong>.</p><p><strong>Example:</strong></p><p>Input:<br>nums = [1,2,3,3]</p><p>Output:<br>True</p><p>Input:<br>nums = [1,2,3,4]</p><p>Output:<br>False</p><h3>My First Approach (Brute Force Thinking)</h3><p>My initial solution used a <strong>list</strong> to store elements I had already seen.</p><pre>class Solution:<br>    def hasDuplicate(self, nums: List[int]) -&gt; bool:<br>        arr = []<br>        for num in nums:<br>            if num in arr:<br>                return True<br>            else:<br>                arr.append(num)<br>        return False</pre><p>At first, this looked fine to me. But then I realized something important.</p><p>Checking num in arr takes <strong>O(n)</strong> time because Python has to scan the list.</p><p>Since this check runs <strong>inside a loop</strong>, the total time complexity becomes:</p><p><strong>O(n²)</strong></p><p>That means if the input size becomes large, the program will slow down a lot.</p><h3>The Better Approach — Using a Set</h3><p>I remembered that <strong>sets use hashing</strong>, which makes lookup operations very fast.</p><p>So I rewrote the solution using a set.</p><pre>class Solution:<br>    def hasDuplicate(self, nums: List[int]) -&gt; bool:<br>        set1 = set()<br>        for i in nums:<br>            if i in set1:<br>                return True<br>            else:<br>                set1.add(i)<br>        return False</pre><p>Now the <strong>membership check (</strong><strong>in) in a set is O(1)</strong> on average.</p><p>So the overall time complexity becomes:</p><p><strong>O(n)</strong></p><p>Much better.</p><h3>What Happens Inside a Python Set (Under the Hood)</h3><p>While solving this question, I decided to finally understand <strong>how sets actually work internally</strong>.</p><h3>1. Hashing</h3><p>When an element is added to a set, Python calls its __hash__() method to generate an integer hash value.</p><h3>2. Indexing</h3><p>The hash value determines the position in the underlying table.</p><p>Example idea:</p><pre>index = hash(element) % table_size</pre><h3>3. Collision Handling</h3><p>Sometimes two different elements produce the same index.<br>This is called a <strong>collision</strong>.</p><p>Python solves this using <strong>open addressing with probing</strong>, meaning it searches for the next available slot.</p><h3>4. Ensuring Uniqueness</h3><p>Before inserting an element, Python checks if it already exists using the hash and equality (==).<br>If it finds the same element, it simply <strong>does not insert it again</strong>.</p><p>This is why <strong>sets only store unique values</strong>.</p><h3>Simple Example</h3><p>If we create a set:</p><pre>fruits = {&quot;apple&quot;, &quot;banana&quot;}</pre><p>Python internally stores them in slots.</p><pre>[None, None, None, &quot;banana&quot;, None, None, None, &quot;apple&quot;]</pre><p>If we try to add &quot;apple&quot; again:</p><ul><li>Python hashes &quot;apple&quot;</li><li>Finds the slot</li><li>Sees &quot;apple&quot; already exists</li><li>Ignores the insertion</li></ul><p>Very efficient.</p><h3>Final Takeaways</h3><ul><li>Lists take <strong>O(n)</strong> time for membership checks.</li><li>Sets use <strong>hashing</strong>, so lookup is <strong>O(1) on average</strong>.</li><li>Using the correct data structure can drastically improve performance.</li><li>This simple problem pushed me to finally understand <strong>hashing and sets under the hood</strong>.</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ccdbf5dc68c6" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>