<?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"><channel><title><![CDATA[devdave]]></title><description><![CDATA[The Money Stack is a ten-part series on the history and technology of how money moves.]]></description><link>https://the-money-stack.hashnode.dev</link><image><url>https://cdn.hashnode.com/uploads/logos/644295b12f36d2e5857fb2c6/67573c3d-1569-4a86-9ebe-3a6299447ece.png</url><title>devdave</title><link>https://the-money-stack.hashnode.dev</link></image><generator>RSS for Node</generator><lastBuildDate>Tue, 01 Sep 2026 11:30:16 GMT</lastBuildDate><atom:link href="https://the-money-stack.hashnode.dev/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[Understanding Linked List as Data Structures.]]></title><description><![CDATA[Welcome back! In the last episode, we started exploring data structures in detail. We discussed fundamental concepts, including the definition of a data structure, the categories of data structures, and specifically explored arrays as a type of linea...]]></description><link>https://the-money-stack.hashnode.dev/understanding-linked-list-as-data-structures</link><guid isPermaLink="true">https://the-money-stack.hashnode.dev/understanding-linked-list-as-data-structures</guid><category><![CDATA[JavaScript]]></category><category><![CDATA[algorithms]]></category><category><![CDATA[datastructure]]></category><category><![CDATA[programming]]></category><dc:creator><![CDATA[David Olabode]]></dc:creator><pubDate>Sat, 07 Jun 2025 00:50:16 GMT</pubDate><content:encoded><![CDATA[<p>Welcome back! In the last episode, we started exploring data structures in detail. We discussed fundamental concepts, including the definition of a data structure, the categories of data structures, and specifically explored arrays as a type of linear data structure.</p>
<p>In this episode, we'll explore Linked Lists as another type of linear data structure.</p>
<ul>
<li><p><strong>Linked List:</strong> A linked list is a collection of nodes, with each node containing a data element and a reference (or pointer) to the next node in the sequence. Unlike arrays, linked lists do not require contiguous memory allocation. This characteristic enables dynamic memory allocation and facilitates efficient insertion and deletion operations. Linked lists can be categorized into two major types: singly linked lists and doubly linked lists.</p>
<ul>
<li><p><strong>Singly linked List:</strong> A singly linked list is a fundamental data structure widely used in computer science and programming. It consists of nodes, where each node has two components: data and a reference (or pointer) to the next node in the sequence. In a singly linked list, each node points only to the next node in the sequence, with the last node pointing to null, indicating the end of the list. Various operations can be performed on a singly linked list, similar to those on an array. These operations include access, insertion/deletion, traversal, and search. A picture of a singly linked list is shown below.</p>
<p>  <img src="https://dev-to-uploads.s3.amazonaws.com/uploads/articles/l4wessv6l6j8m9csnrm8.png" alt="singly linked list" /></p>
<p>  An implementation of a singly linked list with its various operations is illustrated below.</p>
<pre><code class="lang-js">  <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Node</span> </span>{
    <span class="hljs-keyword">constructor</span>(data) {
      <span class="hljs-built_in">this</span>.data = data;
      <span class="hljs-built_in">this</span>.next = <span class="hljs-literal">null</span>;
    }
  }

  <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">SinglyLinkedList</span> </span>{
    <span class="hljs-keyword">constructor</span>() {
      <span class="hljs-built_in">this</span>.head = <span class="hljs-literal">null</span>;
    }

    <span class="hljs-comment">// Insertion at the beginning</span>
    insertFirst(data) {
      <span class="hljs-keyword">const</span> newNode = <span class="hljs-keyword">new</span> Node(data);
      newNode.next = <span class="hljs-built_in">this</span>.head;
      <span class="hljs-built_in">this</span>.head = newNode;
    }

    <span class="hljs-comment">// Insertion at the end</span>
    insertLast(data) {
      <span class="hljs-keyword">const</span> newNode = <span class="hljs-keyword">new</span> Node(data);
      <span class="hljs-keyword">if</span> (!<span class="hljs-built_in">this</span>.head) {
        <span class="hljs-built_in">this</span>.head = newNode;
        <span class="hljs-keyword">return</span>;
      }
      <span class="hljs-keyword">let</span> current = <span class="hljs-built_in">this</span>.head;
      <span class="hljs-keyword">while</span> (current.next) {
        current = current.next;
      }
      current.next = newNode;
    }

    <span class="hljs-comment">// Deletion by value</span>
    <span class="hljs-keyword">delete</span>(value) {
      <span class="hljs-keyword">if</span> (!<span class="hljs-built_in">this</span>.head) <span class="hljs-keyword">return</span>;

      <span class="hljs-keyword">if</span> (<span class="hljs-built_in">this</span>.head.data === value) {
        <span class="hljs-built_in">this</span>.head = <span class="hljs-built_in">this</span>.head.next;
        <span class="hljs-keyword">return</span>;
      }

      <span class="hljs-keyword">let</span> current = <span class="hljs-built_in">this</span>.head;
      <span class="hljs-keyword">while</span> (current.next) {
        <span class="hljs-keyword">if</span> (current.next.data === value) {
          current.next = current.next.next;
          <span class="hljs-keyword">return</span>;
        }
        current = current.next;
      }
    }

    <span class="hljs-comment">// Search</span>
    search(value) {
      <span class="hljs-keyword">let</span> current = <span class="hljs-built_in">this</span>.head;
      <span class="hljs-keyword">while</span> (current) {
        <span class="hljs-keyword">if</span> (current.data === value) {
          <span class="hljs-keyword">return</span> <span class="hljs-literal">true</span>;
        }
        current = current.next;
      }
      <span class="hljs-keyword">return</span> <span class="hljs-literal">false</span>;
    }

    <span class="hljs-comment">// Traversal</span>
    printList() {
      <span class="hljs-keyword">let</span> current = <span class="hljs-built_in">this</span>.head;
      <span class="hljs-keyword">while</span> (current) {
        <span class="hljs-built_in">console</span>.log(current.data);
        current = current.next;
      }
    }
  }

  <span class="hljs-comment">// Example usage:</span>
  <span class="hljs-keyword">const</span> singlyLinkedList = <span class="hljs-keyword">new</span> SinglyLinkedList();
  singlyLinkedList.insertFirst(<span class="hljs-number">3</span>);
  singlyLinkedList.insertFirst(<span class="hljs-number">2</span>);
  singlyLinkedList.insertFirst(<span class="hljs-number">1</span>);
  singlyLinkedList.insertLast(<span class="hljs-number">4</span>);
  singlyLinkedList.insertLast(<span class="hljs-number">5</span>);

  singlyLinkedList.printList(); <span class="hljs-comment">// Output: 1 -&gt; 2 -&gt; 3 -&gt; 4 -&gt; 5</span>

  singlyLinkedList.delete(<span class="hljs-number">3</span>);
  <span class="hljs-built_in">console</span>.log(<span class="hljs-string">'\nLinked List after deleting 3:'</span>);
  singlyLinkedList.printList(); <span class="hljs-comment">// Output: 1 -&gt; 2 -&gt; 4 -&gt; 5</span>

  <span class="hljs-built_in">console</span>.log(<span class="hljs-string">'\nIs 4 present in the list?'</span>, singlyLinkedList.search(<span class="hljs-number">4</span>)); <span class="hljs-comment">// Output: true</span>
  <span class="hljs-built_in">console</span>.log(<span class="hljs-string">'Is 6 present in the list?'</span>, singlyLinkedList.search(<span class="hljs-number">6</span>)); <span class="hljs-comment">// Output: false</span>
</code></pre>
</li>
<li><p><strong>Doubly linked lists:</strong> A doubly linked list is a data structure similar to a singly linked list, but with the addition of each node containing references to both the next node and the previous node in the sequence. In a doubly linked list, each node has three fields: data, a pointer to the next node (often called 'next'), and a pointer to the previous node (often called 'prev'). This bidirectional linkage allows traversal in both forward and backward directions. Various operations can be performed on a doubly linked list, similar to those on an array. These operations include access, insertion/deletion, traversal, and search. A picture of a doubly linked list is shown below.</p>
<p>  <img src="https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6bn1f08wb786i7410n3k.png" alt="doubly linked list" /></p>
<p>  An implementation of a doubly linked list with its various operations is illustrated below.</p>
<pre><code class="lang-js">  <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Node</span> </span>{
    <span class="hljs-keyword">constructor</span>(data) {
      <span class="hljs-built_in">this</span>.data = data;
      <span class="hljs-built_in">this</span>.next = <span class="hljs-literal">null</span>;
      <span class="hljs-built_in">this</span>.prev = <span class="hljs-literal">null</span>;
    }
  }

  <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">DoublyLinkedList</span> </span>{
    <span class="hljs-keyword">constructor</span>() {
      <span class="hljs-built_in">this</span>.head = <span class="hljs-literal">null</span>;
      <span class="hljs-built_in">this</span>.tail = <span class="hljs-literal">null</span>;
    }

    <span class="hljs-comment">// Insertion at the beginning</span>
    insertFirst(data) {
      <span class="hljs-keyword">const</span> newNode = <span class="hljs-keyword">new</span> Node(data);
      <span class="hljs-keyword">if</span> (!<span class="hljs-built_in">this</span>.head) {
        <span class="hljs-built_in">this</span>.head = newNode;
        <span class="hljs-built_in">this</span>.tail = newNode;
      } <span class="hljs-keyword">else</span> {
        newNode.next = <span class="hljs-built_in">this</span>.head;
        <span class="hljs-built_in">this</span>.head.prev = newNode;
        <span class="hljs-built_in">this</span>.head = newNode;
      }
    }

    <span class="hljs-comment">// Insertion at the end</span>
    insertLast(data) {
      <span class="hljs-keyword">const</span> newNode = <span class="hljs-keyword">new</span> Node(data);
      <span class="hljs-keyword">if</span> (!<span class="hljs-built_in">this</span>.head) {
        <span class="hljs-built_in">this</span>.head = newNode;
        <span class="hljs-built_in">this</span>.tail = newNode;
      } <span class="hljs-keyword">else</span> {
        <span class="hljs-built_in">this</span>.tail.next = newNode;
        newNode.prev = <span class="hljs-built_in">this</span>.tail;
        <span class="hljs-built_in">this</span>.tail = newNode;
      }
    }

    <span class="hljs-comment">// Deletion by value</span>
    <span class="hljs-keyword">delete</span>(value) {
      <span class="hljs-keyword">if</span> (!<span class="hljs-built_in">this</span>.head) <span class="hljs-keyword">return</span>;

      <span class="hljs-keyword">let</span> current = <span class="hljs-built_in">this</span>.head;
      <span class="hljs-keyword">while</span> (current) {
        <span class="hljs-keyword">if</span> (current.data === value) {
          <span class="hljs-keyword">if</span> (current === <span class="hljs-built_in">this</span>.head &amp;&amp; current === <span class="hljs-built_in">this</span>.tail) {
            <span class="hljs-built_in">this</span>.head = <span class="hljs-literal">null</span>;
            <span class="hljs-built_in">this</span>.tail = <span class="hljs-literal">null</span>;
          } <span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span> (current === <span class="hljs-built_in">this</span>.head) {
            <span class="hljs-built_in">this</span>.head = current.next;
            <span class="hljs-built_in">this</span>.head.prev = <span class="hljs-literal">null</span>;
          } <span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span> (current === <span class="hljs-built_in">this</span>.tail) {
            <span class="hljs-built_in">this</span>.tail = current.prev;
            <span class="hljs-built_in">this</span>.tail.next = <span class="hljs-literal">null</span>;
          } <span class="hljs-keyword">else</span> {
            current.prev.next = current.next;
            current.next.prev = current.prev;
          }
          <span class="hljs-keyword">return</span>;
        }
        current = current.next;
      }
    }

    <span class="hljs-comment">// Search</span>
    search(value) {
      <span class="hljs-keyword">let</span> current = <span class="hljs-built_in">this</span>.head;
      <span class="hljs-keyword">while</span> (current) {
        <span class="hljs-keyword">if</span> (current.data === value) {
          <span class="hljs-keyword">return</span> <span class="hljs-literal">true</span>;
        }
        current = current.next;
      }
      <span class="hljs-keyword">return</span> <span class="hljs-literal">false</span>;
    }

    <span class="hljs-comment">// Traversal forward</span>
    printListForward() {
      <span class="hljs-keyword">let</span> current = <span class="hljs-built_in">this</span>.head;
      <span class="hljs-keyword">while</span> (current) {
        <span class="hljs-built_in">console</span>.log(current.data);
        current = current.next;
      }
    }

    <span class="hljs-comment">// Traversal backward</span>
    printListBackward() {
      <span class="hljs-keyword">let</span> current = <span class="hljs-built_in">this</span>.tail;
      <span class="hljs-keyword">while</span> (current) {
        <span class="hljs-built_in">console</span>.log(current.data);
        current = current.prev;
      }
    }
  }

  <span class="hljs-comment">// Example usage:</span>
  <span class="hljs-keyword">const</span> doublyLinkedList = <span class="hljs-keyword">new</span> DoublyLinkedList();
  doublyLinkedList.insertFirst(<span class="hljs-number">3</span>);
  doublyLinkedList.insertFirst(<span class="hljs-number">2</span>);
  doublyLinkedList.insertFirst(<span class="hljs-number">1</span>);
  doublyLinkedList.insertLast(<span class="hljs-number">4</span>);
  doublyLinkedList.insertLast(<span class="hljs-number">5</span>);

  <span class="hljs-built_in">console</span>.log(<span class="hljs-string">'Forward Traversal:'</span>);
  doublyLinkedList.printListForward(); <span class="hljs-comment">// Output: 1 -&gt; 2 -&gt; 3 -&gt; 4 -&gt; 5</span>

  <span class="hljs-built_in">console</span>.log(<span class="hljs-string">'\nBackward Traversal:'</span>);
  doublyLinkedList.printListBackward(); <span class="hljs-comment">// Output: 5 -&gt; 4 -&gt; 3 -&gt; 2 -&gt; 1</span>

  doublyLinkedList.delete(<span class="hljs-number">3</span>);
  <span class="hljs-built_in">console</span>.log(<span class="hljs-string">'\nList after deleting 3:'</span>);
  doublyLinkedList.printListForward(); <span class="hljs-comment">// Output: 1 -&gt; 2 -&gt; 4 -&gt; 5</span>
</code></pre>
</li>
</ul>
</li>
</ul>
<p>This concludes our discussion on Linked Lists. In the next episode, we will explore Stacks and Queues as additional data structures.</p>
<h3 id="heading-conclusion">Conclusion</h3>
<p>In this episode, we have comprehensively discussed linked lists as a type of linear data structure in JavaScript. We explored their main types and implemented a detailed example demonstrating how to create and manipulate linked lists, covering various operations. In the next episode, we'll continue our exploration by discussing stacks and queues, which are also linear data structures.</p>
<h3 id="heading-resources-and-references">Resources and References</h3>
<p>You can check out some of the resources listed below to learn more about linked list as a linear data structure:</p>
<ul>
<li><p><a target="_blank" href="https://www.geeksforgeeks.org/data-structures/linked-list/">GeeksforGeeks - Linked List</a></p>
</li>
<li><p><a target="_blank" href="https://www.udemy.com/course/js-algorithms-and-data-structures-masterclass/">JavaScript Algorithms and Data Structures Masterclass by Colt Steele</a>Welcome back! In the last episode, we started exploring data structures in detail. We discussed fundamental concepts, including the definition of a data structure, the categories of data structures, and specifically explored arrays as a type of linear data structure.</p>
<p>  In this episode, we'll explore Linked Lists as another type of linear data structure.</p>
<ul>
<li><p><strong>Linked List:</strong> A linked list is a collection of nodes, with each node containing a data element and a reference (or pointer) to the next node in the sequence. Unlike arrays, linked lists do not require contiguous memory allocation. This characteristic enables dynamic memory allocation and facilitates efficient insertion and deletion operations. Linked lists can be categorized into two major types: singly linked lists and doubly linked lists.</p>
<ul>
<li><p><strong>Singly linked List:</strong> A singly linked list is a fundamental data structure widely used in computer science and programming. It consists of nodes, where each node has two components: data and a reference (or pointer) to the next node in the sequence. In a singly linked list, each node points only to the next node in the sequence, with the last node pointing to null, indicating the end of the list. Various operations can be performed on a singly linked list, similar to those on an array. These operations include access, insertion/deletion, traversal, and search. A picture of a singly linked list is shown below.</p>
<p>  <img src="https://dev-to-uploads.s3.amazonaws.com/uploads/articles/l4wessv6l6j8m9csnrm8.png" alt="singly linked list" /></p>
<p>  An implementation of a singly linked list with its various operations is illustrated below.</p>
<pre><code class="lang-js">  <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Node</span> </span>{
    <span class="hljs-keyword">constructor</span>(data) {
      <span class="hljs-built_in">this</span>.data = data;
      <span class="hljs-built_in">this</span>.next = <span class="hljs-literal">null</span>;
    }
  }

  <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">SinglyLinkedList</span> </span>{
    <span class="hljs-keyword">constructor</span>() {
      <span class="hljs-built_in">this</span>.head = <span class="hljs-literal">null</span>;
    }

    <span class="hljs-comment">// Insertion at the beginning</span>
    insertFirst(data) {
      <span class="hljs-keyword">const</span> newNode = <span class="hljs-keyword">new</span> Node(data);
      newNode.next = <span class="hljs-built_in">this</span>.head;
      <span class="hljs-built_in">this</span>.head = newNode;
    }

    <span class="hljs-comment">// Insertion at the end</span>
    insertLast(data) {
      <span class="hljs-keyword">const</span> newNode = <span class="hljs-keyword">new</span> Node(data);
      <span class="hljs-keyword">if</span> (!<span class="hljs-built_in">this</span>.head) {
        <span class="hljs-built_in">this</span>.head = newNode;
        <span class="hljs-keyword">return</span>;
      }
      <span class="hljs-keyword">let</span> current = <span class="hljs-built_in">this</span>.head;
      <span class="hljs-keyword">while</span> (current.next) {
        current = current.next;
      }
      current.next = newNode;
    }

    <span class="hljs-comment">// Deletion by value</span>
    <span class="hljs-keyword">delete</span>(value) {
      <span class="hljs-keyword">if</span> (!<span class="hljs-built_in">this</span>.head) <span class="hljs-keyword">return</span>;

      <span class="hljs-keyword">if</span> (<span class="hljs-built_in">this</span>.head.data === value) {
        <span class="hljs-built_in">this</span>.head = <span class="hljs-built_in">this</span>.head.next;
        <span class="hljs-keyword">return</span>;
      }

      <span class="hljs-keyword">let</span> current = <span class="hljs-built_in">this</span>.head;
      <span class="hljs-keyword">while</span> (current.next) {
        <span class="hljs-keyword">if</span> (current.next.data === value) {
          current.next = current.next.next;
          <span class="hljs-keyword">return</span>;
        }
        current = current.next;
      }
    }

    <span class="hljs-comment">// Search</span>
    search(value) {
      <span class="hljs-keyword">let</span> current = <span class="hljs-built_in">this</span>.head;
      <span class="hljs-keyword">while</span> (current) {
        <span class="hljs-keyword">if</span> (current.data === value) {
          <span class="hljs-keyword">return</span> <span class="hljs-literal">true</span>;
        }
        current = current.next;
      }
      <span class="hljs-keyword">return</span> <span class="hljs-literal">false</span>;
    }

    <span class="hljs-comment">// Traversal</span>
    printList() {
      <span class="hljs-keyword">let</span> current = <span class="hljs-built_in">this</span>.head;
      <span class="hljs-keyword">while</span> (current) {
        <span class="hljs-built_in">console</span>.log(current.data);
        current = current.next;
      }
    }
  }

  <span class="hljs-comment">// Example usage:</span>
  <span class="hljs-keyword">const</span> singlyLinkedList = <span class="hljs-keyword">new</span> SinglyLinkedList();
  singlyLinkedList.insertFirst(<span class="hljs-number">3</span>);
  singlyLinkedList.insertFirst(<span class="hljs-number">2</span>);
  singlyLinkedList.insertFirst(<span class="hljs-number">1</span>);
  singlyLinkedList.insertLast(<span class="hljs-number">4</span>);
  singlyLinkedList.insertLast(<span class="hljs-number">5</span>);

  singlyLinkedList.printList(); <span class="hljs-comment">// Output: 1 -&gt; 2 -&gt; 3 -&gt; 4 -&gt; 5</span>

  singlyLinkedList.delete(<span class="hljs-number">3</span>);
  <span class="hljs-built_in">console</span>.log(<span class="hljs-string">'\nLinked List after deleting 3:'</span>);
  singlyLinkedList.printList(); <span class="hljs-comment">// Output: 1 -&gt; 2 -&gt; 4 -&gt; 5</span>

  <span class="hljs-built_in">console</span>.log(<span class="hljs-string">'\nIs 4 present in the list?'</span>, singlyLinkedList.search(<span class="hljs-number">4</span>)); <span class="hljs-comment">// Output: true</span>
  <span class="hljs-built_in">console</span>.log(<span class="hljs-string">'Is 6 present in the list?'</span>, singlyLinkedList.search(<span class="hljs-number">6</span>)); <span class="hljs-comment">// Output: false</span>
</code></pre>
</li>
<li><p><strong>Doubly linked lists:</strong> A doubly linked list is a data structure similar to a singly linked list, but with the addition of each node containing references to both the next node and the previous node in the sequence. In a doubly linked list, each node has three fields: data, a pointer to the next node (often called 'next'), and a pointer to the previous node (often called 'prev'). This bidirectional linkage allows traversal in both forward and backward directions. Various operations can be performed on a doubly linked list, similar to those on an array. These operations include access, insertion/deletion, traversal, and search. A picture of a doubly linked list is shown below.</p>
<p>  <img src="https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6bn1f08wb786i7410n3k.png" alt="doubly linked list" /></p>
<p>  An implementation of a doubly linked list with its various operations is illustrated below.</p>
<pre><code class="lang-js">  <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Node</span> </span>{
    <span class="hljs-keyword">constructor</span>(data) {
      <span class="hljs-built_in">this</span>.data = data;
      <span class="hljs-built_in">this</span>.next = <span class="hljs-literal">null</span>;
      <span class="hljs-built_in">this</span>.prev = <span class="hljs-literal">null</span>;
    }
  }

  <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">DoublyLinkedList</span> </span>{
    <span class="hljs-keyword">constructor</span>() {
      <span class="hljs-built_in">this</span>.head = <span class="hljs-literal">null</span>;
      <span class="hljs-built_in">this</span>.tail = <span class="hljs-literal">null</span>;
    }

    <span class="hljs-comment">// Insertion at the beginning</span>
    insertFirst(data) {
      <span class="hljs-keyword">const</span> newNode = <span class="hljs-keyword">new</span> Node(data);
      <span class="hljs-keyword">if</span> (!<span class="hljs-built_in">this</span>.head) {
        <span class="hljs-built_in">this</span>.head = newNode;
        <span class="hljs-built_in">this</span>.tail = newNode;
      } <span class="hljs-keyword">else</span> {
        newNode.next = <span class="hljs-built_in">this</span>.head;
        <span class="hljs-built_in">this</span>.head.prev = newNode;
        <span class="hljs-built_in">this</span>.head = newNode;
      }
    }

    <span class="hljs-comment">// Insertion at the end</span>
    insertLast(data) {
      <span class="hljs-keyword">const</span> newNode = <span class="hljs-keyword">new</span> Node(data);
      <span class="hljs-keyword">if</span> (!<span class="hljs-built_in">this</span>.head) {
        <span class="hljs-built_in">this</span>.head = newNode;
        <span class="hljs-built_in">this</span>.tail = newNode;
      } <span class="hljs-keyword">else</span> {
        <span class="hljs-built_in">this</span>.tail.next = newNode;
        newNode.prev = <span class="hljs-built_in">this</span>.tail;
        <span class="hljs-built_in">this</span>.tail = newNode;
      }
    }

    <span class="hljs-comment">// Deletion by value</span>
    <span class="hljs-keyword">delete</span>(value) {
      <span class="hljs-keyword">if</span> (!<span class="hljs-built_in">this</span>.head) <span class="hljs-keyword">return</span>;

      <span class="hljs-keyword">let</span> current = <span class="hljs-built_in">this</span>.head;
      <span class="hljs-keyword">while</span> (current) {
        <span class="hljs-keyword">if</span> (current.data === value) {
          <span class="hljs-keyword">if</span> (current === <span class="hljs-built_in">this</span>.head &amp;&amp; current === <span class="hljs-built_in">this</span>.tail) {
            <span class="hljs-built_in">this</span>.head = <span class="hljs-literal">null</span>;
            <span class="hljs-built_in">this</span>.tail = <span class="hljs-literal">null</span>;
          } <span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span> (current === <span class="hljs-built_in">this</span>.head) {
            <span class="hljs-built_in">this</span>.head = current.next;
            <span class="hljs-built_in">this</span>.head.prev = <span class="hljs-literal">null</span>;
          } <span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span> (current === <span class="hljs-built_in">this</span>.tail) {
            <span class="hljs-built_in">this</span>.tail = current.prev;
            <span class="hljs-built_in">this</span>.tail.next = <span class="hljs-literal">null</span>;
          } <span class="hljs-keyword">else</span> {
            current.prev.next = current.next;
            current.next.prev = current.prev;
          }
          <span class="hljs-keyword">return</span>;
        }
        current = current.next;
      }
    }

    <span class="hljs-comment">// Search</span>
    search(value) {
      <span class="hljs-keyword">let</span> current = <span class="hljs-built_in">this</span>.head;
      <span class="hljs-keyword">while</span> (current) {
        <span class="hljs-keyword">if</span> (current.data === value) {
          <span class="hljs-keyword">return</span> <span class="hljs-literal">true</span>;
        }
        current = current.next;
      }
      <span class="hljs-keyword">return</span> <span class="hljs-literal">false</span>;
    }

    <span class="hljs-comment">// Traversal forward</span>
    printListForward() {
      <span class="hljs-keyword">let</span> current = <span class="hljs-built_in">this</span>.head;
      <span class="hljs-keyword">while</span> (current) {
        <span class="hljs-built_in">console</span>.log(current.data);
        current = current.next;
      }
    }

    <span class="hljs-comment">// Traversal backward</span>
    printListBackward() {
      <span class="hljs-keyword">let</span> current = <span class="hljs-built_in">this</span>.tail;
      <span class="hljs-keyword">while</span> (current) {
        <span class="hljs-built_in">console</span>.log(current.data);
        current = current.prev;
      }
    }
  }

  <span class="hljs-comment">// Example usage:</span>
  <span class="hljs-keyword">const</span> doublyLinkedList = <span class="hljs-keyword">new</span> DoublyLinkedList();
  doublyLinkedList.insertFirst(<span class="hljs-number">3</span>);
  doublyLinkedList.insertFirst(<span class="hljs-number">2</span>);
  doublyLinkedList.insertFirst(<span class="hljs-number">1</span>);
  doublyLinkedList.insertLast(<span class="hljs-number">4</span>);
  doublyLinkedList.insertLast(<span class="hljs-number">5</span>);

  <span class="hljs-built_in">console</span>.log(<span class="hljs-string">'Forward Traversal:'</span>);
  doublyLinkedList.printListForward(); <span class="hljs-comment">// Output: 1 -&gt; 2 -&gt; 3 -&gt; 4 -&gt; 5</span>

  <span class="hljs-built_in">console</span>.log(<span class="hljs-string">'\nBackward Traversal:'</span>);
  doublyLinkedList.printListBackward(); <span class="hljs-comment">// Output: 5 -&gt; 4 -&gt; 3 -&gt; 2 -&gt; 1</span>

  doublyLinkedList.delete(<span class="hljs-number">3</span>);
  <span class="hljs-built_in">console</span>.log(<span class="hljs-string">'\nList after deleting 3:'</span>);
  doublyLinkedList.printListForward(); <span class="hljs-comment">// Output: 1 -&gt; 2 -&gt; 4 -&gt; 5</span>
</code></pre>
</li>
</ul>
</li>
</ul>
</li>
</ul>
<p>    This concludes our discussion on Linked Lists. In the next episode, we will explore Stacks and Queues as additional data structures.</p>
<h3 id="heading-conclusion-1">Conclusion</h3>
<p>    In this episode, we have comprehensively discussed linked lists as a type of linear data structure in JavaScript. We explored their main types and implemented a detailed example demonstrating how to create and manipulate linked lists, covering various operations. In the next episode, we'll continue our exploration by discussing stacks and queues, which are also linear data structures.</p>
<h3 id="heading-resources-and-references-1">Resources and References</h3>
<p>    You can check out some of the resources listed below to learn more about linked list as a linear data structure:</p>
<ul>
<li><p><a target="_blank" href="https://www.geeksforgeeks.org/data-structures/linked-list/">GeeksforGeeks - Linked List</a></p>
</li>
<li><p><a target="_blank" href="https://www.udemy.com/course/js-algorithms-and-data-structures-masterclass/">JavaScript Algorithms and Data Structures Masterclass by Colt Steele</a></p>
</li>
</ul>
]]></content:encoded></item><item><title><![CDATA[Understanding Big O Notation in Data Structures & Algorithms.]]></title><description><![CDATA[Welcome to the world of Data Structures and Algorithms using JavaScript! This comprehensive guide is designed to equip you with the essential knowledge and skills necessary to navigate the complex landscape of data manipulation and algorithmic proble...]]></description><link>https://the-money-stack.hashnode.dev/understanding-big-o-notation-in-data-structures-and-algorithms</link><guid isPermaLink="true">https://the-money-stack.hashnode.dev/understanding-big-o-notation-in-data-structures-and-algorithms</guid><category><![CDATA[algorithms]]></category><category><![CDATA[datastructure]]></category><category><![CDATA[#big o notation]]></category><category><![CDATA[JavaScript]]></category><category><![CDATA[software development]]></category><dc:creator><![CDATA[David Olabode]]></dc:creator><pubDate>Sat, 07 Jun 2025 00:21:11 GMT</pubDate><content:encoded><![CDATA[<p>Welcome to the world of Data Structures and Algorithms using JavaScript! This comprehensive guide is designed to equip you with the essential knowledge and skills necessary to navigate the complex landscape of data manipulation and algorithmic problem-solving with JavaScript.</p>
<p>Whether you're a seasoned developer looking to enhance your proficiency or a beginner eager to explore the realms of data structures and algorithms, this content is tailored to provide clarity and practical insights. Join us on a journey that combines theoretical foundations with hands-on coding examples, empowering you to write robust and efficient solutions in JavaScript.</p>
<h3 id="heading-prerequisites">Prerequisites</h3>
<p>To effectively engage with data structures and algorithms using JavaScript, it is important to have a strong understanding of JavaScript fundamentals. This includes proficiency in basic syntax, variables, data types, control flow structures, functions, and scope.</p>
<p>This lesson will cover data structures and algorithms in series. In this first episode, we'll dive into Big O notation's fundamentals, a crucial concept for understanding algorithmic efficiency and performance analysis.</p>
<h3 id="heading-big-o-notation">Big O notation</h3>
<p>Big O notation is a powerful tool for analyzing and articulating the efficiency or complexity of an algorithm. Notably, it provides insights into both time and space complexities. When addressing time complexity, Big O is represented as <strong>O(f(n))</strong>, where 'O' signifies the 'order of,' denoting the upper bound or worst-case scenario for the algorithm's growth rate. The 'f' corresponds to a function, much like those in mathematics, while 'n' signifies the size of inputs the function processes. This 'n' typically represents the number of elements in data structures like arrays, the length of strings, the number of nodes in a graph, or any other relevant metric related to the input size. Consequently, 'f(n)' becomes a function representing the algorithm's time complexity growth rate in relation to the input size 'n'. Similarly, Big O notation for space complexity adopts the form <strong>O(g(n))</strong>, where 'g' represents another function, reflecting the upper bound of the algorithm's space usage as it scales with the input size 'n'. Like time complexity, space complexity analysis aims to provide an understanding of how the algorithm's memory consumption grows with increasing input size.</p>
<p>In JavaScript, the execution time of an algorithm can be accurately measured using the <a target="_blank" href="http://performance.now"><strong>performance.now</strong></a><strong>()</strong> method. This allows developers to compare the efficiency of different algorithmic solutions or implementations for the same problem. By timing the execution of each function and analyzing the differences in performance, valuable insights can be gained into the efficiency levels of the respective algorithms. In the example below, we'll compare two functions that solve the same problem, showcasing the difference in their efficiency levels.</p>
<pre><code class="lang-js"><span class="hljs-comment">// 1st approach: which is less efficient</span>
<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">findDivisor1</span>(<span class="hljs-params">number</span>) </span>{
  <span class="hljs-keyword">const</span> startime = performance.now();
  <span class="hljs-keyword">const</span> arrayOfDivisor = [];
  <span class="hljs-keyword">for</span> (<span class="hljs-keyword">let</span> i = <span class="hljs-number">1</span>; i &lt;= number; i++) {
    <span class="hljs-keyword">if</span> (number % i === <span class="hljs-number">0</span>) {
      arrayOfDivisor.push(i);
    }
  }
  <span class="hljs-keyword">const</span> endtime = performance.now();
  <span class="hljs-keyword">const</span> elapsedTime = endtime - startime;
  <span class="hljs-built_in">console</span>.log(<span class="hljs-string">"Elapsed Time for 1st approach:"</span>, elapsedTime);
  <span class="hljs-keyword">return</span> arrayOfDivisor;
}
<span class="hljs-comment">// Example usage:</span>
<span class="hljs-built_in">console</span>.log(<span class="hljs-string">"findDivisor1"</span>, findDivisor1(<span class="hljs-number">10000000</span>));
<span class="hljs-comment">// result: Elapsed Time for 1st approach: 56.06390005350113</span>
</code></pre>
<pre><code class="lang-js"><span class="hljs-comment">// 2nd approach: which is more efficient</span>
<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">findDivisor2</span>(<span class="hljs-params">number</span>) </span>{
  <span class="hljs-keyword">const</span> startime = performance.now();
  <span class="hljs-keyword">const</span> arrayOfDivisor = [];
  <span class="hljs-keyword">for</span> (<span class="hljs-keyword">let</span> i = <span class="hljs-number">1</span>; i &lt;= <span class="hljs-built_in">Math</span>.sqrt(number); i++) {
    <span class="hljs-keyword">if</span> (number % i === <span class="hljs-number">0</span>) {
      arrayOfDivisor.push(i);
      <span class="hljs-comment">// If the divisor is not equal to the square root, add its pair</span>
      <span class="hljs-keyword">if</span> (i !== <span class="hljs-built_in">Math</span>.sqrt(number)) {
        arrayOfDivisor.push(number / i);
      }
    }
  }
  <span class="hljs-comment">//   sorts the array in ascending order</span>
  <span class="hljs-keyword">const</span> sortedArrayOfDivisor = arrayOfDivisor.sort(<span class="hljs-function">(<span class="hljs-params">a, b</span>) =&gt;</span> a - b);
  <span class="hljs-keyword">const</span> endtime = performance.now();
  <span class="hljs-keyword">const</span> elapsedTime = endtime - startime;
  <span class="hljs-built_in">console</span>.log(<span class="hljs-string">"Elapsed Time for 2nd approach:"</span>, elapsedTime);
  <span class="hljs-keyword">return</span> sortedArrayOfDivisor;
}
<span class="hljs-comment">// Example usage:</span>
<span class="hljs-built_in">console</span>.log(<span class="hljs-string">"findDivisor2"</span>, findDivisor2(<span class="hljs-number">10000000</span>));
<span class="hljs-comment">// result: Elapsed Time for 2nd approach: 0.35019999742507935</span>
</code></pre>
<p>The difference between the efficiency in those examples written above leads us to discuss the analysis of Big O notation for algorithm complexity.</p>
<h3 id="heading-big-o-notation-for-algorithm-complexity-analysis">Big O notation for algorithm complexity analysis:</h3>
<ul>
<li><strong>O(1) Constant complexity:</strong> Constant complexity, denoted as <strong>O(1)</strong>, signifies an algorithm's efficiency where the execution time and space remain constant regardless of input size. This implies that the algorithm's performance does not depend on the size of the input data. A classic example demonstrating constant complexity is accessing an element in an array by its index as shown below.</li>
</ul>
<pre><code class="lang-js"><span class="hljs-comment">// function for retrieving an item from an array by index</span>
<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">accessElementByIndex</span>(<span class="hljs-params">arr, index</span>) </span>{
  <span class="hljs-keyword">if</span> (
    !<span class="hljs-built_in">isNaN</span>(index) &amp;&amp;
    <span class="hljs-built_in">Number</span>.isInteger(index) &amp;&amp;
    index &gt;= <span class="hljs-number">0</span> &amp;&amp;
    index &lt; arr.length
  ) {
    <span class="hljs-keyword">return</span> arr[index];
  } <span class="hljs-keyword">else</span> {
    <span class="hljs-keyword">return</span> <span class="hljs-string">"Index is out of bounds"</span>;
  }
}
<span class="hljs-comment">// Example usage:</span>
<span class="hljs-keyword">const</span> arrayOfNumbers = [<span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>, <span class="hljs-number">4</span>, <span class="hljs-number">5</span>, <span class="hljs-number">6</span>, <span class="hljs-number">7</span>, <span class="hljs-number">8</span>];
<span class="hljs-built_in">console</span>.log(accessElementByIndex(arrayOfNumbers, <span class="hljs-number">2</span>));
<span class="hljs-comment">//result: 3</span>
</code></pre>
<ul>
<li><strong>O(log n) Logarithmic complexity:</strong> Logarithmic complexity, denoted as <strong>O(log n)</strong>, characterizes algorithms whose execution time or space usage grows logarithmically with the size of the input data. In other words, as the input size increases, the time or space required increases at a logarithmic rate. For example, binary search algorithms exhibit logarithmic complexity, as they halve the search space with each step, resulting in a time complexity proportional to the logarithm of the input size. An example of a logarithmic complexity is shown below.</li>
</ul>
<pre><code class="lang-js"><span class="hljs-comment">// A binary search function for finding the index of a target element in a sorted array.</span>
<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">binarySearch</span>(<span class="hljs-params">arr, target</span>) </span>{
  <span class="hljs-keyword">let</span> low = <span class="hljs-number">0</span>;
  <span class="hljs-keyword">let</span> high = arr.length - <span class="hljs-number">1</span>;

  <span class="hljs-keyword">while</span> (low &lt;= high) {
    <span class="hljs-keyword">let</span> mid = <span class="hljs-built_in">Math</span>.floor((low + high) / <span class="hljs-number">2</span>);

    <span class="hljs-keyword">if</span> (arr[mid] === target) {
      <span class="hljs-keyword">return</span> mid;
    } <span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span> (arr[mid] &lt; target) {
      low = mid + <span class="hljs-number">1</span>;
    } <span class="hljs-keyword">else</span> {
      high = mid - <span class="hljs-number">1</span>;
    }
  }

  <span class="hljs-keyword">return</span> <span class="hljs-number">-1</span>; <span class="hljs-comment">// Target not found</span>
}

<span class="hljs-comment">// Example usage:</span>
<span class="hljs-keyword">const</span> arrayOfNumbers = [<span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>, <span class="hljs-number">4</span>, <span class="hljs-number">5</span>, <span class="hljs-number">6</span>, <span class="hljs-number">7</span>];
<span class="hljs-built_in">console</span>.log(binarySearch(arrayOfNumbers, <span class="hljs-number">5</span>));
<span class="hljs-comment">//   result: 4</span>
</code></pre>
<ul>
<li><strong>O(n) Linear complexity:</strong> Linear complexity, denoted as <strong>O(n)</strong>, represents algorithms whose execution time and space usage increase linearly with the size of the input data. In simpler terms, as the input size grows, the time and space required by the algorithm also grow proportionally. An example illustrating linear complexity is presented below.</li>
</ul>
<pre><code class="lang-js"><span class="hljs-comment">// A function for finding the maximum element in an array</span>
<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">findMaxElement</span>(<span class="hljs-params">arr</span>) </span>{
  <span class="hljs-keyword">let</span> max = arr[<span class="hljs-number">0</span>];

  <span class="hljs-keyword">for</span> (<span class="hljs-keyword">let</span> i = <span class="hljs-number">1</span>; i &lt; arr.length; i++) {
    <span class="hljs-keyword">if</span> (arr[i] &gt; max) {
      max = arr[i];
    }
  }

  <span class="hljs-keyword">return</span> max; <span class="hljs-comment">// Return the maximum element in the array</span>
}

<span class="hljs-comment">// Example usage:</span>
<span class="hljs-keyword">const</span> arrayOfNumbers = [<span class="hljs-number">5</span>, <span class="hljs-number">2</span>, <span class="hljs-number">8</span>, <span class="hljs-number">1</span>, <span class="hljs-number">9</span>, <span class="hljs-number">4</span>];
<span class="hljs-built_in">console</span>.log(findMaxElement(arrayOfNumbers));
<span class="hljs-comment">// result: 9</span>
</code></pre>
<ul>
<li><strong>O(n^2) Quadratic complexity:</strong> Quadratic complexity, denoted as <strong>O(n^2)</strong>, characterizes algorithms whose execution time and space requirements increase quadratically with the size of the input data. Put simply, as the input size grows, the time and space needed to complete the algorithm increase proportionally to the square of the input size. An example demonstrating quadratic complexity is provided below.</li>
</ul>
<pre><code class="lang-js"><span class="hljs-comment">// A bubble sort function for sorting numbers in an array</span>
<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">bubbleSort</span>(<span class="hljs-params">arr</span>) </span>{
  <span class="hljs-keyword">const</span> n = arr.length;

  <span class="hljs-keyword">for</span> (<span class="hljs-keyword">let</span> i = <span class="hljs-number">0</span>; i &lt; n - <span class="hljs-number">1</span>; i++) {
    <span class="hljs-keyword">for</span> (<span class="hljs-keyword">let</span> j = <span class="hljs-number">0</span>; j &lt; n - i - <span class="hljs-number">1</span>; j++) {
      <span class="hljs-keyword">if</span> (arr[j] &gt; arr[j + <span class="hljs-number">1</span>]) {
        <span class="hljs-comment">// Swap them if they are in the wrong order</span>
        <span class="hljs-keyword">const</span> temp = arr[j];
        arr[j] = arr[j + <span class="hljs-number">1</span>];
        arr[j + <span class="hljs-number">1</span>] = temp;
      }
    }
  }

  <span class="hljs-keyword">return</span> arr;
}

<span class="hljs-comment">// Example usage:</span>
<span class="hljs-keyword">const</span> unsortedArrayOfNumbers = [<span class="hljs-number">64</span>, <span class="hljs-number">25</span>, <span class="hljs-number">12</span>, <span class="hljs-number">22</span>, <span class="hljs-number">11</span>];
<span class="hljs-built_in">console</span>.log(bubbleSort(unsortedArrayOfNumbers));
<span class="hljs-comment">// result: [ 11, 12, 22, 25, 64 ]</span>
</code></pre>
<ul>
<li><strong>O(n^3) Cubic complexity:</strong> Cubic complexity, denoted as <strong>O(n^3)</strong>, is a measure of algorithmic efficiency where the execution time and space of an algorithm grows cubically with the size of the input data. In simpler terms, as the input size increases, the time and space required to complete the algorithm increases proportionally to the cube of the input size. An example illustrating cubic time complexity is provided below.</li>
</ul>
<pre><code class="lang-js"><span class="hljs-comment">// Function to calculate the sum of all elements in a 3D matrix</span>
<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">sumOfMatrix</span>(<span class="hljs-params">matrix</span>) </span>{
  <span class="hljs-keyword">const</span> n = matrix.length;
  <span class="hljs-keyword">let</span> totalSum = <span class="hljs-number">0</span>;

  <span class="hljs-keyword">for</span> (<span class="hljs-keyword">let</span> i = <span class="hljs-number">0</span>; i &lt; n; i++) {
    <span class="hljs-keyword">for</span> (<span class="hljs-keyword">let</span> j = <span class="hljs-number">0</span>; j &lt; n; j++) {
      <span class="hljs-keyword">for</span> (<span class="hljs-keyword">let</span> k = <span class="hljs-number">0</span>; k &lt; n; k++) {
        <span class="hljs-comment">// Accumulate the sum of all elements</span>
        totalSum += matrix[i][j][k];
      }
    }
  }

  <span class="hljs-keyword">return</span> totalSum;
}

<span class="hljs-comment">// Example usage:</span>
<span class="hljs-keyword">const</span> threeDMatrix = [
  [
    [<span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>],
    [<span class="hljs-number">4</span>, <span class="hljs-number">5</span>, <span class="hljs-number">6</span>],
    [<span class="hljs-number">7</span>, <span class="hljs-number">8</span>, <span class="hljs-number">9</span>],
  ],
  [
    [<span class="hljs-number">10</span>, <span class="hljs-number">11</span>, <span class="hljs-number">12</span>],
    [<span class="hljs-number">13</span>, <span class="hljs-number">14</span>, <span class="hljs-number">15</span>],
    [<span class="hljs-number">16</span>, <span class="hljs-number">17</span>, <span class="hljs-number">18</span>],
  ],
  [
    [<span class="hljs-number">19</span>, <span class="hljs-number">20</span>, <span class="hljs-number">21</span>],
    [<span class="hljs-number">22</span>, <span class="hljs-number">23</span>, <span class="hljs-number">24</span>],
    [<span class="hljs-number">25</span>, <span class="hljs-number">26</span>, <span class="hljs-number">27</span>],
  ],
];

<span class="hljs-built_in">console</span>.log(sumOfMatrix(threeDMatrix));
<span class="hljs-comment">// result: 378</span>
</code></pre>
<ul>
<li><strong>O(2^n) Exponential complexity:</strong> Exponential complexity, denoted as <strong>O(2^n</strong>) or sometimes <strong>O(k^n)</strong>, is a measure of algorithmic efficiency where the execution time and space of an algorithm grows exponentially with the size of the input data. In simple terms, as the input size increases, the time and space required to complete the algorithm increases exponentially, typically doubling with each additional element in the input. An example demonstrating exponential time complexity is provided below.</li>
</ul>
<pre><code class="lang-js"><span class="hljs-comment">// A Fibonacci function to calculate the nth Fibonacci number recursively</span>
<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">fibonacci</span>(<span class="hljs-params">n</span>) </span>{
  <span class="hljs-keyword">if</span> (n &lt;= <span class="hljs-number">1</span>) {
    <span class="hljs-keyword">return</span> n;
  } <span class="hljs-keyword">else</span> {
    <span class="hljs-keyword">return</span> fibonacci(n - <span class="hljs-number">1</span>) + fibonacci(n - <span class="hljs-number">2</span>);
  }
}

<span class="hljs-comment">// Example usage:</span>
<span class="hljs-built_in">console</span>.log(fibonacci(<span class="hljs-number">7</span>));
<span class="hljs-comment">// result: 13</span>
</code></pre>
<p>Algorithm analysis aims to understand the efficiency of algorithms, predicting their performance as input sizes grow. This involves calculating both time (f(n)) and space (g(n)) complexities. However, it can be a little bit challenging to calculate. Big-O notation provides some fundamental ways to simplify any algorithm to help developers calculate.</p>
<h3 id="heading-simplifying-big-o-expressions">Simplifying Big O expressions</h3>
<ul>
<li><p>O(2n) simplifies to O(n)</p>
</li>
<li><p>O(500) simplifies to O(1)</p>
</li>
<li><p>O(13n^2) simplifies to O(n^2)</p>
</li>
<li><p>O(n+10) simplifies to O(n)</p>
</li>
<li><p>O(1000n+50) simplifies to O(n)</p>
</li>
<li><p>O(n^2+5n+8) simplifies to O(n^2)</p>
</li>
</ul>
<h3 id="heading-little-tricks-to-take-note-in-big-o-notation">Little tricks to take note in Big O notation</h3>
<h4 id="heading-time-complexity">Time complexity</h4>
<ul>
<li><p>Arithmetic operations, variable assignments, and accessing elements in arrays or objects are typically constant time.</p>
</li>
<li><p>In loops, the complexity depends on the number of iterations multiplied by the complexity of operations within the loop.</p>
</li>
</ul>
<h4 id="heading-space-complexity">Space complexity</h4>
<ul>
<li><p>Most primitive data types have constant space complexity.</p>
</li>
<li><p>Strings require O(n) space, where n is the length of the string.</p>
</li>
<li><p>Reference types like arrays or objects generally have O(n) space complexity, where n is the number of elements or keys.</p>
</li>
</ul>
<p>It's important to note that while these rules provide general guidelines, analyzing algorithm complexity can sometimes be more complex depending on specific contexts and implementations.</p>
<h3 id="heading-conclusion">Conclusion</h3>
<p>This series has provided a comprehensive exploration of Big O notation. Understanding the efficiency of algorithms is crucial for making informed decisions in software development. By unraveling the complexities of Big O notation, we've gained valuable insights into how algorithms scale and perform under different input sizes. Moving forward, applying this knowledge will undoubtedly contribute to the enhancement of software performance and the optimization of computational resources in real-world applications.</p>
<h3 id="heading-resources-and-references">Resources and References</h3>
<p>You can check out some of the resources listed below to learn more about Big O notation</p>
<ul>
<li><p>JavaScript Data Structures and Algorithms by Sammie Bae</p>
</li>
<li><p><a target="_blank" href="https://www.udemy.com/course/js-algorithms-and-data-structures-masterclass/">js algorithms and data structures masterclass by Colt Steele</a></p>
</li>
</ul>
]]></content:encoded></item><item><title><![CDATA[My 2024: The Good, The Bad, and The Ugly]]></title><description><![CDATA[Started the year with a lot of goals and aspirations in all aspects of life, including spiritual, career, and financial. It was a promising kick-off since the 2024 race had begun.
I had promised my boss, who is more like a brother, that I would help ...]]></description><link>https://the-money-stack.hashnode.dev/my2024journey</link><guid isPermaLink="true">https://the-money-stack.hashnode.dev/my2024journey</guid><category><![CDATA[2024]]></category><category><![CDATA[goals]]></category><category><![CDATA[aspirations]]></category><category><![CDATA[Node.js]]></category><category><![CDATA[programming]]></category><dc:creator><![CDATA[David Olabode]]></dc:creator><pubDate>Tue, 31 Dec 2024 18:49:08 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1735299355653/05c2244a-5a2b-49ba-b3a1-568c1808ec1c.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Started the year with a lot of goals and aspirations in all aspects of life, including spiritual, career, and financial. It was a promising kick-off since the 2024 race had begun.</p>
<p>I had promised my boss, who is more like a brother, that I would help him complete his software product. On January 3rd, I left Ibadan and traveled to Ile Ife to join him in developing the software. My plan was to finish the software project and then focus on creating tech content, which I believed was a profitable path in tech and a quick way to gain recognition as a developer. I started working for my boss on January 8th, 2024. With just the two of us on the project, we managed both backend and frontend programming simultaneously. Our goal was to ship the first version of the software by the first week of February, as my boss was running out of funds and urgently needed to get our first subscribers.</p>
<p>Working on the project was a significant learning experience for me. I developed a deep affection for it because it allowed me to explore advanced features of Node.js. The work continued day and night, and eventually, we needed to start designing frontend pages. Up until then, our frontend work had primarily been about sending important requests to the backend and receiving responses. Designing beautiful frontend pages became a pressing need. My boss, being more of a backend developer, was not very accustomed to coding frontend designs. He had a habit of sourcing ready-made designs and customizing them to meet his needs. For our project, he found all the pages from a website with a similar implementation and handed them to me to integrate into a React application.</p>
<p>As I began integrating these designs, I encountered a problem but was reluctant to inform him. I decided to code the pages from scratch instead of fixing the pre-made designs. That’s where the problem began. After handing me the pages, my boss left for home to focus on resolving a backend issue—a part of the code was consuming too much memory, and the remote server we planned to deploy on had only 2GB of RAM. He worked on this issue for a week before finding a solution and returning to the office.</p>
<p>When he returned, he asked about the progress of the frontend designs. I told him I had completed only the landing page. He was upset, feeling I had been lazy since all I had to do was adapt the pre-made designs. However, I felt I had done a lot of work because I had written the designs from scratch. These designs were complex, and implementing them manually required significant effort. After explaining that I had encountered issues with the provided designs and opted to code them myself, we reviewed the problem together. We discovered that the pre-made designs indeed had issues and wouldn’t work as intended. My boss decided we should manually get the designs, and this time, everything worked out fine.</p>
<p>On Wednesday, January 31st, 2024, I didn't follow my boss's instructions, and as a result, he decided I should stop working on his project. I apologized, but it was too late. It was a difficult experience because I was attached to the project. Despite my regret, I had to stop working on it. While I was no longer involved, I started thinking about my next steps. I remembered that I needed to write some technical articles for my DEV.to account as part of my goals. I quickly got into it, and it turned out to be a fascinating experience. I realized I had developed a passion for explaining concepts. One of the topics I wrote about was Big O notation, a fundamental concept in data structures and algorithms, which got a lot of likes because my article was very detailed and clear.</p>
<p>After publishing the article, I found Ile Ife boring and decided to return to Ibadan, even though the electricity there is unreliable. After two days of doing nothing at home, I went to the University of Ibadan to use their electricity so I could work on my laptop and update my LinkedIn profile and portfolios. While there, my former roommate, now a master's student, asked for help with a software project. Once I finished updating my profiles, I started working on his project. I became very involved and worked on it all day until late at night. Realizing it was too late to go home, I called a friend of my boss, who was also a master's student at the University of Ibadan, to ask if I could stay over. He agreed, and his roommate picked me up, allowing me to spend the night there.</p>
<p>I woke up early and returned to the Student Union Building to continue working on the project. I coded all day and accepted my former roommate's offer to stay in his room since he had an empty bed. With no electricity at home, it was a better option. Using his laptop, which had a better battery life and more RAM, made my work faster and more enjoyable. I considered upgrading my own laptop's RAM. After making significant progress on the project over three days, I decided to take a break and go home, promising to return</p>
<p>On my way home, I considered upgrading my laptop's RAM and decided to find a side job. I applied to one of the best schools nearby and was invited to take a test the following week. After the test, I was called for an interview, and by the end of February, I was told to start working in the first week of March. The school closed at 3:30 PM, but the principal often stayed late to handle administrative tasks. The school library was my favourite place to code without distractions. I took this chance to stay a bit longer to code. I really enjoyed this experience because I was working on a personal project that I believed could make a big difference.</p>
<p>By April, I received my salary and bought the additional RAM. I also finished the personal project I was working on, and everything was running smoothly. However, I wanted to add an extra feature that I couldn't manage directly. I decided to use an API for this, but I soon discovered that the API I was using wasn't reliable. I began researching better APIs while still visiting the school during the three-week holiday in April. Eventually, I found another API that could add the feature. Unfortunately, when I tried to integrate it into my application, it didn't work as expected.</p>
<p>While dealing with this issue, I got a call from a friend asking if I could recommend someone for a small frontend project. I said I could do it. My friend connected me with the project owner, and we discussed the details. He sent me the Figma prototype, which included animated pages. We agreed on the price and estimated it would take two weeks to complete. Two days before the deadline, I hosted it for the client to review. Aside from a few minor corrections, everything was complete, and I delivered the final project on time. Additionally, I received an email from a company that had been following my technical content on <a target="_blank" href="https://dev.to/davidevlops">DEV.to</a>. They wanted me to work as a Technical Content Creator for them. I seriously considered the offer because it was an opportunity abroad. However, I had a strange feeling about it, so I decided to decline the offer.</p>
<p>With the payment from the front-end project, I felt a strong urge to use the money differently than I had planned. I trusted my instincts and spent it in a way that brought me fulfillment. Meanwhile, I continued working at the school and coding on my laptop every day, which I found engaging and fulfilling. By June, during our mid-term break at school, I decided to go to the University of Ibadan (UI) to access electricity since no one would be at school. I was completely focused on reaching my financial goal for the first half of the year. I worked tirelessly, spending three days straight glued to my laptop, persistently applying for opportunities on various freelance platforms.</p>
<p>On Saturday evening, I left UI and went home to prepare for church the next day, which was also Sallah. On Sunday afternoon, after returning from church, I decided to check my <a target="_blank" href="https://www.linkedin.com/in/david-olabode/">LinkedIn account</a>. To my surprise, I found a gig opportunity that could help me reach my financial goal for the first half of the year. Excited, I applied via email and received a response. The hiring team scheduled an interview for the next day. The following day, I completed the interview, and the interviewer informed me that I had been shortlisted for the final round. I was set to meet with the CEO on Friday. He also advised me to prepare thoroughly for cloud computing questions, focusing on AWS. I felt somewhat confident, as I had previously worked with some AWS services, though I wasn’t deeply experienced.</p>
<p>On Friday, the day of the interview, I met the CEO, a Nigerian living in Germany. The conversation started well. His first question was about deploying an application to AWS EC2. I couldn’t answer because I only had experience with AWS Lambda. He moved on to the next question, which I answered correctly. However, I took a long time to respond to the third question, and the CEO mistakenly accused me of looking up the answer during the interview. He decided to end the interview, saying he couldn't offer me the gig. I was devastated. Missing out on that gig meant I couldn't reach my financial goal for the first half of the year. It was a tough and disappointing experience, one of the low points of my journey.</p>
<p>I learned a lot from my past mistakes and promised myself to do better next time. In August, I received a message from the same person who had introduced me to the Nigerian CEO in Germany, whose interview I didn't pass. This time, he wanted me to create something amazing. However, the amount he offered was quite low. When I mentioned this, he explained that it was just an internship. Since I wanted to explore reverse engineering some apps with features similar to what he wanted, I decided to take on the project. I discovered some interesting hacks related to the project and jumped right in. To focus fully on the project, I resigned from my teaching job in September, as I'm not good at multitasking. Plus, the project was very demanding.</p>
<p>Focusing only on this project turned out to be a big mistake. I later realized the client didn't have a clear idea of what he wanted. I was both the software architect and the tech lead. I carefully planned the algorithms and solutions, but he often suggested other non-technical approaches. I explained that I had considered the trade-offs carefully, but he often prioritized speed over building robust applications. It was frustrating, but I kept going. In mid-October, the national power grid collapsed, and I urgently needed to finish a part of the web app to show a progress report by Friday. To get electricity, I went to the University of Ibadan (UI), where they had power. I worked hard through the night, and around 5:30 AM, I decided to take a short break while my phone was charging in front of me. Feeling comfortable, I rested my head for a moment. Unfortunately, I fell into a deep sleep.</p>
<p>When I woke up around 6:15 AM, I discovered that my phone had been stolen. Those 45 minutes felt like the most distressing moments of my life. Panicking, I tried everything to locate the phone, knowing it was probably still on campus. I rushed downstairs to ask someone to call my phone. It rang, but no one answered. After persistent dialing, a man finally picked up and claimed he would return the phone but said he was far away. I immediately knew he was lying—this is a common excuse thieves use. At that moment, I began to worry about my SIM card being misused for fraudulent or dangerous activities. I quickly visited my network provider’s office to retrieve my line. I completed the SIM replacement almost immediately and resorted to using an old, abandoned smartphone I found at home. This unpleasant experience marked the end of my habit of moving around in search of electricity. The project’s progress slowed significantly after that incident. By the end of the month, I wasn’t paid a full salary and was informed that the work would be halted due to a lack of funding from investors.</p>
<p>In November, I decided it was time to go for NYSC, something I had been avoiding because I felt it was a waste of time. While waiting for NYSC registration to begin, I took up a tutorial job introduced to me by my sister's friend in my neighborhood. I thought it would be a good way to earn some cash. The job turned out to be quite enjoyable, and I liked the flexibility of the per-hour arrangement, as it gave me the freedom to focus on other activities.</p>
<p>While working at the tutorial, I was discussing my intended NYSC posting with my sister's friend at the tutorial center. He advised me to reconsider my choice of location, saying that serving in that part of the country might not be worth it. Curious, I turned to Google for research and reached out to people who had done their service there. Their opinions were unanimous—they all discouraged serving in that area. After careful thought, I decided to pick the state where I already lived. It felt like a more practical choice since I wouldn’t have to deal with the hassle of moving my belongings around.</p>
<p>When NYSC registration started, I did everything I could to make sure I registered with the batch. Everything went smoothly, and I was posted to the state I wanted. I had always dreaded the NYSC orientation camp, but my mom encouraged me to embrace the experience. To my surprise, camp turned out to be an exciting chapter. I met many people and really enjoyed the activities. When camp ended, I was posted to a place for my primary assignment, marking the beginning of my career. I returned home to a festive atmosphere, as the Christmas season was already in full swing.</p>
<p>As I look back on 2024, I feel grateful for all the experiences, both good and bad. Life is a mix of highs and lows, with each experience offering valuable lessons. From missed opportunities and tough projects to moments of resilience and personal growth, every phase had a purpose. The year had its struggles, but it was also filled with achievements, new beginnings, and meaningful connections. Through it all, I learned the importance of perseverance, adaptability, and gratitude. Each challenge was a chance to grow, and each success reminded me of what’s possible with hard work and faith. 2024 may not have been perfect, but it was significant, and for that, I am deeply thankful. Here’s to welcoming the new year with optimism, courage, and a commitment to becoming even better.</p>
]]></content:encoded></item><item><title><![CDATA[Computer Programming 101: The Keys to Mastering Any Programming Language]]></title><description><![CDATA[Throughout my years as a software developer, I've written programs in various programming languages. During this journey, I've encountered certain fundamental concepts that remain consistent across all these languages.
In this blog, I'll be exploring...]]></description><link>https://the-money-stack.hashnode.dev/computer-programming-101-the-keys-to-mastering-any-programming-language</link><guid isPermaLink="true">https://the-money-stack.hashnode.dev/computer-programming-101-the-keys-to-mastering-any-programming-language</guid><category><![CDATA[Programming Blogs]]></category><category><![CDATA[programming languages]]></category><category><![CDATA[Programming Tips]]></category><category><![CDATA[Software Engineering]]></category><category><![CDATA[software development]]></category><category><![CDATA[software]]></category><category><![CDATA[programming]]></category><dc:creator><![CDATA[David Olabode]]></dc:creator><pubDate>Fri, 22 Sep 2023 23:00:00 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1693829415426/5bcbcc84-7a22-4be3-b5bb-067b39885f1b.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Throughout my years as a software developer, I've written programs in various programming languages. During this journey, I've encountered certain fundamental concepts that remain consistent across all these languages.</p>
<p>In this blog, I'll be exploring essential concepts that every programmer should grasp, regardless of the programming language they work with.</p>
<h3 id="heading-prerequisites">Prerequisites</h3>
<p>To write software programs in any programming language, you'll require the following essential prerequisites:</p>
<ul>
<li><p><strong>Text editor:</strong> A software application designed for creating and editing text files. Text editors tailored for programming offer syntax highlighting and auto-completion features to facilitate coding. Popular choices include Notepad++, Atom, Sublime Text, and Visual Studio Code.</p>
</li>
<li><p><strong>Compiler:</strong> This program translates source code written in a programming language into machine code usually in 1’s and 0’s, which the computer can directly execute. It reads your source code and generates a file containing the machine code for your program, which can be run on the computer.</p>
</li>
<li><p><strong>Interpreter:</strong> An interpreter directly executes the source code without the need for a compilation step. This means you can run your program immediately after writing it, without compiling it first. However, interpreters can be slower than compilers and might only support some programming languages.</p>
</li>
</ul>
<p>These prerequisites collectively form the programming "environment," providing the necessary tools and resources to write and execute programs. Remember that the specific environment can vary depending on the programming language used; for instance, the environment for C++ differs from that of Python.</p>
<h3 id="heading-understanding-programming-and-programming-languages">Understanding Programming and Programming Languages</h3>
<p>Programming is the art of providing instructions, typically in a computer-readable language, to execute specific tasks.
A programming language serves as a means of communication with the computer. While each language may have its unique syntax and features.</p>
<h3 id="heading-basic-concepts-common-in-all-programming-languages">Basic Concepts Common in all programming languages.</h3>
<p>Fundamental concepts are shared among all programming languages. Some of these concepts include variable declaration, syntax, data types, control flows (conditionals and loops), functions, Object-Oriented Programming, and debugging. Mastery of these core concepts empowers programmers to harness the capabilities of any programming language effectively.</p>
<ul>
<li><p><strong>Variable Declaration</strong>
In computer programming, a variable declaration is a statement that defines a variable. A variable is a named location in memory that can store a value. The variable declaration specifies the variable's name, the variable's data type, and the variable's initial value. The syntax for a variable declaration varies in different programming languages.</p>
</li>
<li><p><strong>Data Types</strong>
In computer programming, a data type is a classification of data that tells the compiler or interpreter how the programmer intends to use the data. Most programming languages support various types of data, including integer, character or string, and boolean.</p>
</li>
<li><p><strong>Control Flow</strong>
In computer programming, control flow refers to the order in which the statements in a program are executed. Control flow statements are used to alter the order of execution, such as by repeating a block of code or branching to a different part of the program. There are two main types of control flow statements: loops and conditionals.
<strong>Loops</strong> serve the purpose of repeating a block of code either for a specific number of iterations or until a particular condition is satisfied. This repetition process is commonly referred to as iteration. There are two primary types of loops: the 'for' loop, used for a predetermined number of iterations, and the 'while' loop, employed to continue until a given condition holds.
<strong>Conditionals</strong> are vital for controlling a program's flow based on specific conditions. There are two primary types of conditionals: the 'if' statement, which enables branching based on the truth of a condition, and the 'switch' statement, which facilitates selecting different paths in the program based on the value of a variable.</p>
</li>
<li><p><strong>Functions</strong>
Functions serve as essential building blocks in code, encapsulating a clear and reusable set of instructions for accomplishing specific tasks efficiently. As self-contained units, functions can accept input parameters (arguments), process them, and generate meaningful output results. To define a function, programmers must indicate its name, any necessary input parameters, and the code block containing the sequence of operations to execute. Importantly, not all functions require input parameters; some can operate based solely on their internal logic or access global variables.</p>
</li>
<li><p><strong>Object-Oriented Programming (OOP)</strong>
Object-Oriented Programming (OOP) is a programming paradigm that revolves around the concept of objects, which are instances of classes. It is a powerful and widely used approach to software development that aims to organize code in a way that models real-world entities and their interactions.</p>
</li>
<li><p><strong>Debugging</strong>
Debugging is very important for every programmer because every programmer makes mistakes when writing code. Debugging is the process of identifying and resolving errors or defects in a software program. It is an essential skill that involves locating and fixing issues that cause the program to behave unexpectedly or crash. Debugging involves processes such as: Identifying Bugs, Locating the Cause, Using Debugging Tools, Fixing the Bug, and Testing.</p>
</li>
</ul>
<h3 id="heading-conclusion">Conclusion</h3>
<p>Irrespective of the programming language one employs. These fundamental principles play a pivotal role in shaping effective and efficient code. By grasping these essential concepts, programmers can enhance their problem-solving skills, promote code reusability, and confidently navigate various programming languages. Remember, mastering these basics serves as a solid stepping stone toward becoming a proficient and versatile programmer capable of tackling diverse challenges in the dynamic world of software development.</p>
]]></content:encoded></item></channel></rss>