<?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 My Algo Journey on Medium]]></title>
        <description><![CDATA[Stories by My Algo Journey on Medium]]></description>
        <link>https://medium.com/@learning4ev?source=rss-ff6d3faf0f55------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*Hoz29WdKJNGs7OV3Tof_GQ.png</url>
            <title>Stories by My Algo Journey on Medium</title>
            <link>https://medium.com/@learning4ev?source=rss-ff6d3faf0f55------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 02 Dec 2026 00:07:48 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@learning4ev/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[Dynamic Arrays — When Arrays Learn to Flex]]></title>
            <link>https://medium.com/@learning4ev/dynamic-arrays-when-arrays-learn-to-flex-1cf7ecefeaa8?source=rss-ff6d3faf0f55------2</link>
            <guid isPermaLink="false">https://medium.com/p/1cf7ecefeaa8</guid>
            <category><![CDATA[data-structure-algorithm]]></category>
            <category><![CDATA[dynamic-array]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[My Algo Journey]]></dc:creator>
            <pubDate>Sun, 14 Sep 2025 06:03:22 GMT</pubDate>
            <atom:updated>2025-09-16T19:29:54.657Z</atom:updated>
            <content:encoded><![CDATA[<h3>Dynamic Arrays — When Arrays Learn to Flex</h3><p>When I was working with <strong>static arrays</strong>, I kept bumping into the same problem:</p><blockquote><em>What if I don’t know how many elements I’ll need?</em></blockquote><p>With static arrays, you’re stuck with the size you declare at the beginning. But in real life, I rarely know if I’ll need 5 slots, 50, or 500. This is where <strong>dynamic arrays</strong> come in — and honestly, the idea feels kind of magical at first.</p><h3>🌱 What Makes Dynamic Arrays Different?</h3><ul><li>You don’t need to specify a size when you initialize.</li><li>They <strong>grow automatically</strong> as you add more elements.</li><li>In Python and JavaScript, dynamic arrays are the <strong>default array type</strong> you use every day.</li></ul><p>Under the hood, though, they’re not magic. They’re still built on top of static arrays — but with a clever resizing trick.</p><h3>➕ Insertion &amp; Resizing</h3><p>When you insert an element into a dynamic array:</p><ol><li>If there’s space, the element goes into the next empty spot.</li><li>If the array is full → the system <strong>resizes</strong> the array.</li></ol><p>Here’s what happens during resize:</p><ul><li>A new static array is created, usually <strong>double the size</strong> of the old one.</li><li>All elements are copied over.</li><li>The old array is deallocated.</li></ul><p>That’s why you can keep pushing elements into a dynamic array “forever.”</p><h3>⏱ Amortized Time Complexity</h3><p>Here’s the part that confused me at first:</p><ul><li>Adding one element usually takes <strong>O(1)</strong>.</li><li>But sometimes, resizing kicks in — and copying all elements over costs <strong>O(n)</strong>.</li></ul><p>So which one is it? The answer: <strong>amortized analysis</strong>.</p><p>👉 If you look at <em>many</em> insertions together, the expensive resizes are rare compared to the cheap insertions. On average, inserting still works out to <strong>O(1)</strong> per operation.</p><p>It’s like spreading the cost of resizing across all the cheap insertions — the “average” is constant.</p><h3>🔍 Why Double the Capacity?</h3><p>At first I wondered: <em>why not just increase the array by 1 each time it’s full?</em></p><p>The problem is efficiency. If you increase one slot at a time, you’ll end up copying everything <strong>every time you insert</strong> — which is painfully slow.</p><p>By doubling capacity each time, you ensure the number of expensive resizes is logarithmic, and the average insertion remains O(1).</p><p>Example:<br> 1 → 2 → 4 → 8 → 16 …<br> By the time you reach size 8, you’ve only done 15 total copies, which is still O(n).</p><h3>⚙️ Other Operations</h3><p>Dynamic arrays behave like static arrays for most operations:</p><ul><li><strong>Access by index</strong> → O(1)</li><li><strong>Insert/Delete in the middle</strong> → O(n) (because of shifting)</li><li><strong>Insert at the end</strong> → O(1)* (amortized, unless a resize happens)</li></ul><h3>🧾 Big-O Summary Table</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/969/1*isS_UeMvJGXCB0j74Dy1iA.png" /></figure><h3>🧩 Why This Matters</h3><p>Static arrays taught me about <strong>predictable memory</strong>. Dynamic arrays are teaching me about <strong>flexibility</strong> and <strong>trade-offs</strong>. They remind me that in computer science, “free” features (like infinite growth) almost always come at a cost — here, it’s the occasional O(n) resize.</p><ul><li><em>Suggest a dynamic array problem (like implementing my own </em><em>push() with resizing) which was tricky or difficult for you.</em></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1cf7ecefeaa8" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Static Arrays — My First Real Data Structure]]></title>
            <link>https://medium.com/@learning4ev/static-arrays-my-first-real-data-structure-f934cff5c641?source=rss-ff6d3faf0f55------2</link>
            <guid isPermaLink="false">https://medium.com/p/f934cff5c641</guid>
            <category><![CDATA[data-structure-algorithm]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[arrays]]></category>
            <dc:creator><![CDATA[My Algo Journey]]></dc:creator>
            <pubDate>Sat, 13 Sep 2025 04:42:47 GMT</pubDate>
            <atom:updated>2025-09-13T04:42:47.182Z</atom:updated>
            <content:encoded><![CDATA[<h3>Static Arrays — My First Real Data Structure</h3><p>In my last post, I shared how arrays are stored in memory — neat, contiguous blocks of data packed inside RAM. Now, I want to go deeper into the first “real” data structure I’m working with: the <strong>static array</strong>.</p><p>When I first heard <em>static</em>, it sounded intimidating, but here’s what it really means:</p><p>In <strong>statically typed languages</strong> like C, C++, and Java, when you create an array, you must specify:</p><ol><li><strong>The type</strong> (e.g., integer, character, float)</li><li><strong>The size</strong> (how many elements it can hold)</li></ol><p>Once you do that, the array is locked in place. If you declare an array of size 5, it can hold exactly 5 values — no more, no less. That’s why it’s called <strong>static</strong>: its size never changes.</p><p>On the other hand, in <strong>dynamically typed languages</strong> like Python or JavaScript, you don’t usually work with static arrays at all. Instead, you get resizable “lists” or “arrays” by default (my next milestone to learn).</p><h3>A Quick Refresher: What’s Big-O?</h3><p>Before diving into static array operations, I had to really understand <strong>time complexity</strong> and <strong>space complexity</strong>:</p><ul><li><strong>Time Complexity</strong>: How the number of operations grows as your input grows.</li><li>Example: If traversing an array of size 10 takes 10 steps, and traversing an array of size 100 takes 100 steps, we say the time complexity is <strong>O(n)</strong> (linear time).</li><li><strong>Space Complexity</strong>: How much extra memory an algorithm needs beyond the input.</li><li><strong>Big-O Notation</strong>: A mathematical way to describe the <em>upper bound</em> of an algorithm’s growth. It doesn’t tell you the exact time, just the rate at which time (or space) grows relative to the input.</li></ul><p>👉 A key takeaway I’ve learned: <strong>O(1) does not mean “fast,”</strong> it just means <em>constant time</em>. An O(1) operation might still involve 1000 steps behind the scenes, but that number doesn’t grow as the array grows.</p><h3>Core Operations of Static Arrays</h3><h3>1. Reading from an Array</h3><p>Accessing an element by index is instant.</p><pre>myArray = [1, 3, 5]<br>print(myArray[2])   # O(1)</pre><p>No matter how big the array is, the computer can jump directly to the element in memory.</p><ul><li><strong>Time Complexity:</strong> O(1)</li></ul><h3>2. Traversing an Array</h3><p>If I want to look at <em>every</em> element, I must loop through the array:</p><pre>for i in range(len(myArray)):<br>    print(myArray[i])</pre><p>This grows linearly with the size of the array.</p><ul><li><strong>Time Complexity:</strong> O(n)</li></ul><h3>3. Deleting from an Array</h3><ul><li><strong>At the End:</strong> Easy — just overwrite the last element with a default value (like 0 or null).</li><li><strong>O(1)</strong></li><li><strong>In the Middle:</strong> Much harder. You can’t just “remove” it; you must <strong>shift every element after it one step left</strong> to keep the array contiguous.</li><li><strong>O(n)</strong></li></ul><h3>4. Inserting into an Array</h3><ul><li><strong>At the End:</strong> Write the value at the next open position.</li><li><strong>O(1)</strong></li><li><strong>In the Middle:</strong> You must shift all elements to the right before inserting, or else you’d overwrite existing data.</li><li><strong>O(n)</strong></li></ul><h3>🧾 Big-O Summary Table</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YXvkQ793ziX4N4R4dRTnNQ.png" /></figure><h3>🧩 Why This Matters</h3><p>Here’s what I realized: arrays are the foundation for everything else. After learning about <strong>static arrays</strong>, I feel both impressed and limited.</p><ul><li>Impressed, because accessing an element in O(1) time felt almost magical.</li><li>Limited, because I quickly realized: once an array is full, that’s it. No more room.</li></ul><p>But here’s the thing — in real life, I rarely know <em>exactly</em> how many items I’ll need to store ahead of time. Imagine building a to-do list that can only hold 5 tasks. What if I suddenly need 6? Static arrays can’t handle that.</p><p>This is where probably <strong>dynamic arrays</strong> come in. I don’t fully understand them yet, but I know they somehow “resize themselves” when you run out of space. To me, that feels like the array equivalent of magic — but I’m about to dig in and figure out how it actually works.</p><p>For now, I’ll leave you with a question:</p><p>👉 <em>If you had to explain dynamic arrays to a beginner (like me), what analogy would you use?</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f934cff5c641" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Before Arrays — What Even Is a Data Structure?]]></title>
            <link>https://medium.com/@learning4ev/before-arrays-what-even-is-a-data-structure-e455bacd341c?source=rss-ff6d3faf0f55------2</link>
            <guid isPermaLink="false">https://medium.com/p/e455bacd341c</guid>
            <category><![CDATA[random-access-memories]]></category>
            <category><![CDATA[data-storage]]></category>
            <category><![CDATA[memory-management]]></category>
            <category><![CDATA[data-structures]]></category>
            <dc:creator><![CDATA[My Algo Journey]]></dc:creator>
            <pubDate>Fri, 12 Sep 2025 01:24:55 GMT</pubDate>
            <atom:updated>2025-09-12T01:24:55.565Z</atom:updated>
            <content:encoded><![CDATA[<h3>Before Arrays — What Even <em>Is</em> a Data Structure?</h3><p>When I first started learning algorithms, everyone kept saying: <em>“Master your data structures.”</em> But honestly, I didn’t even have a clear picture of what a data structure really <em>was</em>.</p><p>So before I dive into arrays, here’s the way I finally made sense of it:</p><p>A <strong>data structure</strong> is simply a way to store data efficiently in a computer’s memory — specifically, in something called <strong>RAM (Random Access Memory)</strong>. RAM is the short-term memory of your computer. Every time you run a program, it stores the numbers, strings, and objects you’re working with in RAM so your CPU can access them quickly.</p><p>But here’s the thing: computers don’t really understand numbers the way we do. They only understand <strong>bits</strong> — zeroes and ones. Everything we store — integers, characters, even emojis — eventually becomes a long sequence of 0s and 1s.</p><h3>Arrays in Memory</h3><p>An <strong>array</strong> is one of the simplest and most fundamental data structures. It’s just an ordered collection of elements stored <strong>contiguously</strong> in memory.</p><p>Take an array like this:</p><pre>[1, 3, 5]</pre><p>It looks simple enough. But in RAM, those values are stored in binary form. For example, if each integer takes up 1 byte (8 bits):</p><ul><li>1 → 00000001</li><li>3 → 00000011</li><li>5 → 00000101</li></ul><p>Since arrays are contiguous, they sit right next to each other in memory — no gaps. That’s why accessing the <em>i-th</em> element in an array is so fast: the computer just calculates its memory address using simple arithmetic.</p><p>In reality, integers usually occupy <strong>4 bytes (32 bits)</strong>, and characters occupy <strong>1 byte (8 bits)</strong>. But the principle is the same: each element sits right next to the next one, and the computer jumps to the correct spot by adding a multiple of the element size to the starting address.</p><h3>Why This Matters</h3><p>Most of the time, this low-level detail is hidden from us as developers. We don’t <em>have</em> to know where in memory our array is stored. But understanding that arrays are stored contiguously helps explain why some operations are lightning-fast (like accessing by index), while others are slower (like inserting in the middle).</p><p>This knowledge also becomes crucial later — when designing efficient algorithms, or even entire systems.</p><h3>Closing Thoughts</h3><p>This first step was mostly about theory. From here, I’ll move into the practical side: <strong>what we can actually do with arrays, how fast those operations are, and when to use them.</strong></p><p>If you’ve ever felt that computer memory was a mysterious black box, hopefully this clears things up: at its core, an array is just a neat little row of values, packed tightly together in memory.</p><ul><li><em>Drop me a memory-related question or challenge/puzzle below. I’ll try to tackle at least one in my next log before diving into arrays.</em></li><li><em>This is the foundation — before we touch arrays, let’s make sure I can answer your memory puzzles in my next post.</em></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e455bacd341c" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>