<?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 Oluwatomilola on Medium]]></title>
        <description><![CDATA[Stories by Oluwatomilola on Medium]]></description>
        <link>https://medium.com/@oluwatomilola.adeniran?source=rss-8ff26039bcc9------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*yTDvj3uPzKQ3Rhcb</url>
            <title>Stories by Oluwatomilola on Medium</title>
            <link>https://medium.com/@oluwatomilola.adeniran?source=rss-8ff26039bcc9------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 06 Dec 2026 20:42:44 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@oluwatomilola.adeniran/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[DSA (1): Singly Linked Lists]]></title>
            <link>https://medium.com/@oluwatomilola.adeniran/dsa-1-singly-linked-lists-57022a98e514?source=rss-8ff26039bcc9------2</link>
            <guid isPermaLink="false">https://medium.com/p/57022a98e514</guid>
            <category><![CDATA[computer-science-colleges]]></category>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[computer-science]]></category>
            <category><![CDATA[data-structure-algorithm]]></category>
            <category><![CDATA[data-structures]]></category>
            <dc:creator><![CDATA[Oluwatomilola]]></dc:creator>
            <pubDate>Mon, 22 Aug 2022 09:27:41 GMT</pubDate>
            <atom:updated>2022-08-22T09:37:01.776Z</atom:updated>
            <content:encoded><![CDATA[<p>Please, let me preface this entire series with a disclaimer: I am not a Computer Science student. This is just me trying to make sense of this course.</p><p>We begin this series by looking at the <strong>Singly Linked List</strong>.</p><p>The singly linked list is an interesting data structure. Anyone reading this is probably already familiar with arrays (so that’s what I’ll make more reference to). An array stores its information in contiguous (consecutive) memory blocks. This is what allows us to use an index to access elements of an array. The issue with this is that it has a time complexity of O(N) for most operations (insertion, removal and searching). This means the amount of time it takes to perform these operations grows as the inputs grow i.e. as the inputs grow bigger, the time gets slower. This relationship can be represented with a linear graph:</p><figure><img alt="Big O complexity charts for O(1), O(log n), O(n), O(n²) and O(n!)" src="https://cdn-images-1.medium.com/max/800/1*ECsCbiD1prAFdOouQikWRQ.png" /><figcaption>Image sourced from: <a href="https://cdn-media-1.freecodecamp.org/images/1*HwLR-DKk0lYNEMpkH475kg.png">https://cdn-media-1.freecodecamp.org/images/1*HwLR-DKk0lYNEMpkH475kg.png</a></figcaption></figure><p>Now that we’ve gotten all that out of the way, let’s focus on the singly linked list itself.</p><p>A singly linked list is made up of a bunch of nodes that have a pointer. This is perculiar because all a node knows is the next node, there’s no singular node that can represent the full node! Think of it as a conga line where everyone is holding the person infront of them.</p><p>We need two classes to implement the linked list:</p><ul><li>The Node Class</li><li>The Singly Linked List Class</li></ul><pre>class listNode() {<br>     constructor(value){<br>      this.value = value;<br>      this.next = null;<br>     }     <br>}</pre><pre>class singlyLinkedList() { <br>      constructor() {<br>           this.head = null;<br>           this.tail = null;<br>           this.length = 0;<br>      }     <br>}</pre><p>When defining our linked list class, we keep track of the <strong>head </strong>(beginning), the <strong>tail </strong>(end), and the length of the list.</p><figure><img alt="Linked list illustration from GeeksforGeeks" src="https://cdn-images-1.medium.com/max/759/1*6ReSYwX-z-n4jWPCRSxqBw.png" /><figcaption>Image sourced from: <a href="https://media.geeksforgeeks.org/wp-content/cdn-uploads/gq/2013/03/Linkedlist.png">https://media.geeksforgeeks.org/wp-content/cdn-uploads/gq/2013/03/Linkedlist.png</a></figcaption></figure><p>It’s useful for operations involving insertion and deletion (especially for removal from the <strong>beginning</strong>).</p><p><strong>Insertion</strong></p><p>When inserting a node into the linked list, there are three possible cases:</p><ol><li><strong>Insertion at the beginning:</strong> The time complexity of this is O(1) because we’re doing the same number of operations everytime we do this: creating a new node, setting it’s ‘next’ attribute to be the current head, updating the head of the list, and incrementing the length.</li><li><strong>Insertion at the end:</strong> The time complexity of this is O(1) because we keep track of the tail of the list, so we don’t have to iterate through the list. The process here is very similar to insertion at the beginning. <em>N.B: The last node of the linked list should always point to ‘null’</em></li><li><strong>Insertion at another (random) position:</strong> The time complexity of this is O(N) because you have to go through each node until you get to the one before the given position and the node that currently occupies that position so you don’t lose the link to it and then update the pointers accordingly. Here’s where the conga line comes in handy — if you want to add someone new to the middle of the line, you have to first ‘break’ the bond between the people currently before &amp; at that position, add the person to the line, then ‘rebuild’ the bonds.</li></ol><p><strong>Deletion</strong></p><p>A linked list is especially useful for removing a node from the beginning of the list because no matter how long the list is, we’re performing the same number of steps to delete a node from the beginning. The time complexity is <strong>O(1)</strong>, this is much faster compared to an array because if you have to delete an element from the beginning of an array, the entire array has to be reindexed. If you’re deleting from the end of a list though, it might be better to use an array.</p><p>We made it to the end! That’s everything we need to know about singly linked lists. Thanks for reading this, share it if you’ve found this useful ! If you have any questions, I’d be more than happy to help.</p><p>Since you’ve made it this far, here’s a list of methods you can implement that are handy for working with singly linked lists:</p><ol><li>push(value) — This inserts a node with the given value to the end of the list</li><li>pop() — This removes the last element of the list</li><li>shift() — This removes the first element of the list</li><li>unshift(value) — This inserts a node with the given value to the beginning of the list</li><li>get(index) — This returns the node at the given index</li><li>set(index,value) — This updates the node at the given index with the value passed in.</li><li>insert(index,value) — This inserts a node with the value at the given index</li><li>remove(index) — This removes a node at the given index</li><li>reverse() — This is used to reverse a linked list (a <strong>very </strong>common DSA assessment question).</li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=57022a98e514" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>