<?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 Gonzo Nieto on Medium]]></title>
        <description><![CDATA[Stories by Gonzo Nieto on Medium]]></description>
        <link>https://medium.com/@gonzon?source=rss-2ed411a5d62------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*8zC2RGisBWkxPYf2.jpg</url>
            <title>Stories by Gonzo Nieto on Medium</title>
            <link>https://medium.com/@gonzon?source=rss-2ed411a5d62------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 29 Nov 2026 05:59:54 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@gonzon/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[Singly-Linked Lists Are Your Friend]]></title>
            <link>https://medium.com/@gonzon/singly-linked-lists-are-your-friend-4f888396de51?source=rss-2ed411a5d62------2</link>
            <guid isPermaLink="false">https://medium.com/p/4f888396de51</guid>
            <dc:creator><![CDATA[Gonzo Nieto]]></dc:creator>
            <pubDate>Mon, 09 May 2022 18:24:06 GMT</pubDate>
            <atom:updated>2022-05-09T18:24:06.167Z</atom:updated>
            <content:encoded><![CDATA[<p>…but you might not know it yet. In order to properly appreciate this primer on singly-linked lists, it is important to first understand the problem that they solve.</p><h3>Static arrays and memory allocation</h3><p>In a compiled language, the program code is converted by the compiler into machine-readable instructions. This is in contrast to interpreted languages, for which code is executed on the fly, typically because it is being run by a program that is itself written in the machine’s native language.</p><p>One implication of compiled languages is that arrays are statically-sized. This means the size of an array must be known at runtime — it is not possible to ask the user to input a number n during the execution of the program, and then create an array of n elements.</p><p>This is because when we create an array, the computer sets aside a sequential chunk in memory that can hold that data—so if we ask for an integer array of 10 elements, it will set aside 10 * the number of bytes needed to represent an integer. Any memory outside the bounds of this array will be used for other purposes, so if we were to try to add an 11th element to the array, we would not be able to do so because the next space in memory is already occupied.</p><h3>Singly-linked lists to the rescue!</h3><p>A singly-linked list is a data structure that solves this problem and gives us a way to have dynamically-sized arrays in a compiled language.</p><p>The 10-element array we were previously discussing would have contained one field per element of the array — the field containing the integer value being stored at that element.</p><p>In contrast, a singly-linked list would have two fields per element:</p><ul><li>One field containing the integer value</li><li>A second field containing a pointer to the next element in the list</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/408/1*HfEmZF6ue2FcBIuKZ30hKQ.png" /><figcaption>Source: <a href="https://en.wikipedia.org/wiki/Linked_list">https://en.wikipedia.org/wiki/Linked_list</a></figcaption></figure><p>If you’ve never encountered pointers before, a pointer is a <strong>data type</strong> that stores a memory address.</p><p>With this structure, the elements of the list no longer need to be stored in memory sequentially, because each element carries a reference to where the next element in the list can be found.</p><p>Some key features of the singly-linked list:</p><ul><li>A given element can be found with a time complexity of O(n)</li><li>Insertion has a time complexity of O(1)</li><li>Traversal can only happen in one direction</li></ul><p>The concept of a singly-linked list is also usefully elaborated by some of its cousins:</p><ul><li><strong>Doubly-linked list:</strong> In this data structure, each element contains a pointer to the next element as well as a pointer to the previous element, which permits traversal in both directions.</li><li><strong>Skip list: </strong>In this data structure, elements are sorted, and each element contains multiple pointers allowing traversal to skip ahead in large segments instead of needing to go through the list one element at a time.</li></ul><p>If you’re used to working in higher-level languages, you may be spoiled with never needing to explicitly think about singly-linked lists. Still, it is worth having an appreciation for them, as in many cases, what we call “arrays” in higher level languages are really singly-linked lists being implemented under the hood for us.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4f888396de51" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>