<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: jojongumi</title>
    <description>The latest articles on DEV Community by jojongumi (@jojongumi).</description>
    <link>https://dev.to/jojongumi</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F887256%2Fd460e45e-2de7-495f-9287-ee346d2670d7.png</url>
      <title>DEV Community: jojongumi</title>
      <link>https://dev.to/jojongumi</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/jojongumi"/>
    <language>en</language>
    <item>
      <title>Data Structures 102: Deep Dive into Data Structures and Algorithms.</title>
      <dc:creator>jojongumi</dc:creator>
      <pubDate>Tue, 05 Jul 2022 10:29:00 +0000</pubDate>
      <link>https://dev.to/jojongumi/data-structures-102-deep-dive-into-data-structures-and-algorithms-30a9</link>
      <guid>https://dev.to/jojongumi/data-structures-102-deep-dive-into-data-structures-and-algorithms-30a9</guid>
      <description>&lt;p&gt;In the &lt;a href="https://dev.to/jojongumi/data-structures-101-introduction-to-data-structures-and-algorithms-1698"&gt;previous article&lt;/a&gt; we outlined the various classifications of Data Structures that exist and some of the various Algorithms that are mainly performed on Data Structures. In this article we shall build upon those concepts by delving into the following: Arrays, Linked Lists, Trees, and Searching.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. Arrays
&lt;/h2&gt;

&lt;p&gt;This could be referred to as an indexed collection of data. Generally, arrays are declared with an opening square bracket and ended with a closing square bracket. A comma is put between each element and the data types enclosed within an array should all be of the same type, like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;//examples of arrays
const sandwich = ["peanut butter", "jelly", "bread"];
//or
int  scores[3] = [77, 73, 81];
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When accessing the array, we use zero-based indexing such that to access the third element (81) in the scores array we could say:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;scores[2];
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The disadvantage of using arrays is that it requires an allocation of a fixed size, back-to-back in memory. This makes it difficult to add new elements to the array as there may be values stored in the memory addresses immediately after the address of the array.&lt;/p&gt;

&lt;p&gt;One solution might be to allocate more memory where there’s enough space, and move our array there. This means we’ll need to allocate more memory to copy each of the original elements first, then add our new element and free the old array once we finish copying. Another solution may be to use a &lt;em&gt;Linked List&lt;/em&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. Linked Lists
&lt;/h2&gt;

&lt;p&gt;When we have a large enough array, there might not be enough free memory contiguously, in a row, to store all of our values. Rather than allocate a fixed size of memory back-to-back, linked lists allow us to add elements in different parts of memory while adding references to those elements that point to the next node so as to stitch all the elements together. This combination of a data element with the reference pointer forms a &lt;em&gt;node&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Nsv8_2bq--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/t0q0alx3l93jtvika41k.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Nsv8_2bq--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/t0q0alx3l93jtvika41k.png" alt="Image description" width="880" height="546"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As demonstrated in the image above, when we want to insert a new value, we allocate enough memory for both the value we want to store, and the address of the next value. For the last value in the Linked List, we use the null pointer since there’s no next group.&lt;/p&gt;

&lt;p&gt;With a linked list, we have the tradeoff of needing to allocate more memory for each value and pointer, in order to spend less time adding values.&lt;/p&gt;

&lt;h2&gt;
  
  
  3.   Trees
&lt;/h2&gt;

&lt;p&gt;Unlike arrays and linked lists that are linear data structures, trees outline a hierarchical relationship between data elements. A tree is another data structure where there are nodes; however, the nodes have two pointers and each node points to other nodes. This can be illustrated as shown in the figure below:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Y3PDk7Eb--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/o49bkygfoppap55ym6kw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Y3PDk7Eb--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/o49bkygfoppap55ym6kw.png" alt="Image description" width="880" height="381"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We might have a tree where the root node points to one node on the left and one node on the right. The nodes to the right and left of the root are &lt;em&gt;Parent&lt;/em&gt; nodes and form the first hierarchical level of the tree. The immediate lower level nodes of the parent node are the &lt;em&gt;children&lt;/em&gt;. Two children sharing a parent node are referred to as &lt;em&gt;siblings&lt;/em&gt;. A node without a child is referred to as a &lt;em&gt;leaf&lt;/em&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  4. Searching
&lt;/h2&gt;

&lt;p&gt;Since computers cannot look at all data elements at once, for arrays that are zero-indexed we can access the elements of an array of n items by going through index 0 to the highest index (which would be n-1). If the particular value of the element required matches the value that has been accessed, then we have achieved &lt;strong&gt;Searching&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;There are algorithms for searching with varying levels of efficiency depending on their running times. To describe the running time of a program we use &lt;strong&gt;Big Ω notation&lt;/strong&gt;, which describes the lower bound of number of steps for our algorithm (i.e. how few steps it might take in the best case). We also use &lt;strong&gt;Big O notation&lt;/strong&gt;, which is the upper bound of number of steps for our algorithm (i.e. how many steps it might take in the worst case)&lt;/p&gt;

&lt;p&gt;Some common running times:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;O(n^2)&lt;br&gt;
O(nlog n)&lt;br&gt;
O(n)&lt;br&gt;
O(log n)&lt;br&gt;
O(1)&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Ω(n^2)&lt;br&gt;
Ω(nlog n)&lt;br&gt;
Ω(n)&lt;br&gt;
Ω(log n)&lt;br&gt;
Ω(1)&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;An algorithm with running time of O(1) means that a constant number of steps is required, no matter how big the problem is. This is illustrated in the figure below:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--D_VxHdqB--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/o3zd697ypk44rv5l3ynj.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--D_VxHdqB--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/o3zd697ypk44rv5l3ynj.png" alt="Image description" width="880" height="585"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In a linear data structure such as an array or linked list, if we didn’t know anything about the values, the simplest search algorithm would be going from left to right. This type of algorithm is referred to as &lt;strong&gt;Linear Search&lt;/strong&gt; and it is not very efficient with a running time of O(n).&lt;/p&gt;

&lt;p&gt;In a non-linear data structure such as a tree, to search for a number, we’ll start at the root node, and be able to recursively search the left or right subtree. Since we might have to keep dividing the number of elements by two until there are no more elements left, this type of algorithm is referred to as &lt;strong&gt;Binary Search&lt;/strong&gt; and it has an upper bound of O(log n) . If the number we’re looking for is in the middle (i.e. where we happen to start) then the lower bound for binary search would be Ω(1).&lt;/p&gt;

&lt;p&gt;Even though binary search might be much faster than linear search, it requires our elements to be sorted first. With a balanced binary search tree, the running time will be O(log n); however if our tree isn’t balanced, it can devolve into a linked list with running time of O(n).&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Data Structures 101: Introduction to Data Structures and Algorithms.</title>
      <dc:creator>jojongumi</dc:creator>
      <pubDate>Tue, 05 Jul 2022 04:56:38 +0000</pubDate>
      <link>https://dev.to/jojongumi/data-structures-101-introduction-to-data-structures-and-algorithms-1698</link>
      <guid>https://dev.to/jojongumi/data-structures-101-introduction-to-data-structures-and-algorithms-1698</guid>
      <description>&lt;h2&gt;
  
  
  Definitions:
&lt;/h2&gt;

&lt;p&gt;A &lt;strong&gt;Data Structure&lt;/strong&gt; refers to a way of organizing so as to use it effectively.&lt;br&gt;
The 'use' of this data is during processes such as when storing, retrieving or modifying it in a computer's memory.&lt;br&gt;
The ideal requirement from a programmer during the design of any of these processes would be to use minimum space in memory while still maintaining minimum running time.&lt;br&gt;
Therefore, the need for Data Structure can be summarized as follows:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;To allow for efficient management of huge amount of data&lt;/li&gt;
&lt;li&gt;To allow for fast sorting and searching data&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Types of Data Structure:
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Primitive Data Structure&lt;/li&gt;
&lt;li&gt;Adaptive Data Structure&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The figure below shows the different classifications of data structures:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--3SkdVysR--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/oy0uzwnrevrmal0gmv7c.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--3SkdVysR--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/oy0uzwnrevrmal0gmv7c.PNG" alt="Image description" width="799" height="567"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  1. Primitive Data Structure
&lt;/h2&gt;

&lt;p&gt;These refer to data structures such as integer, char, float and Boolean etc. that come built-in to programs.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. Non-Primitive (Adaptive) Data Structure
&lt;/h2&gt;

&lt;p&gt;These refer to more complex data structures that are built upon from primitive data structures.&lt;br&gt;
Their formation is as a set of data elements that are either of the same data type (homogenous) or of different data type (heterogeneous).&lt;/p&gt;

&lt;p&gt;These are further divided into:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Linear Data Structure:&lt;/strong&gt; These emphasize on data that has been arranged in one dimension (i.e. sequentially) such as arrays, linked lists, stacks, queues.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Non-Linear Data Structure:&lt;/strong&gt; These emphasize on data that has been arranged in multiple dimensions (i.e. hierarchically) such as trees, graphs, tables.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Algorithms
&lt;/h2&gt;

&lt;p&gt;An &lt;strong&gt;Algorithm&lt;/strong&gt; refers to a set of instructions which are executed in order so as to perform a certain task.&lt;br&gt;
Some of the various algorithms that are mainly performed on Data Structures include:-&lt;br&gt;
    - &lt;strong&gt;Traversing:&lt;/strong&gt; this refers to accessing a data element for processing&lt;br&gt;
    - &lt;strong&gt;Searching:&lt;/strong&gt; this refers to finding the location of one or more data items&lt;br&gt;
    - &lt;strong&gt;Inserting:&lt;/strong&gt; this refers to adding a new data element to a pre-existing collection of data elements&lt;br&gt;
    - &lt;strong&gt;Deleting:&lt;/strong&gt; this refers to removing a data element from a pre-existing collection of data elements&lt;br&gt;
    - &lt;strong&gt;Sorting:&lt;/strong&gt; this refers to arranging data elements in a certain order&lt;br&gt;
    - &lt;strong&gt;Merging:&lt;/strong&gt; this refers to combining two separate collection of data elements that have been sorted into one list of sorted data elements&lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
