<?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: GerryJ</title>
    <description>The latest articles on DEV Community by GerryJ (@gerryj).</description>
    <link>https://dev.to/gerryj</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%2F879668%2Fd40cba0c-dda9-420a-b602-1e3a42154b55.jpeg</url>
      <title>DEV Community: GerryJ</title>
      <link>https://dev.to/gerryj</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/gerryj"/>
    <language>en</language>
    <item>
      <title>Data Structure and Algorithms 102: Deep Dive into Data Structure and Algorithms, Java</title>
      <dc:creator>GerryJ</dc:creator>
      <pubDate>Tue, 28 Jun 2022 19:46:20 +0000</pubDate>
      <link>https://dev.to/gerryj/data-structure-and-algorithms-102-deep-dive-into-data-structure-and-algorithms-java-1fkm</link>
      <guid>https://dev.to/gerryj/data-structure-and-algorithms-102-deep-dive-into-data-structure-and-algorithms-java-1fkm</guid>
      <description>&lt;p&gt;In my previous article, I highlighted an overview of the various data structures and the difference between time and space complexities. However, that was just a scratch on the surface; This article will dig deeper to offer more understanding into linear data structures while also providing some examples. We will highlight some of the most commonly used data types, i.e, arrays and stacks.\&lt;/p&gt;

&lt;h2&gt;
  
  
  Common Data Structure Operations
&lt;/h2&gt;

&lt;p&gt;These are the fundamental operations that ought to be possible on all data structures.&lt;/p&gt;

&lt;h5&gt;
  
  
  Access
&lt;/h5&gt;

&lt;p&gt;This operation deals with the accessibility of the pieces that are currently kept in the structure.&lt;/p&gt;

&lt;h5&gt;
  
  
  Search
&lt;/h5&gt;

&lt;p&gt;The position of a certain element within a specific structure is handled by this procedure.&lt;/p&gt;

&lt;h5&gt;
  
  
  Insertion
&lt;/h5&gt;

&lt;p&gt;This procedure outlines the procedure for adding additional elements to the structure.&lt;/p&gt;

&lt;h5&gt;
  
  
  Deletion
&lt;/h5&gt;

&lt;p&gt;The removal of existing elements from the structure is described in this operation.&lt;/p&gt;

&lt;h2&gt;
  
  
  Arrays
&lt;/h2&gt;

&lt;p&gt;A fixed number of comparable elements with the same name are stored in an array. These elements are stored in contagious memory locations. It is one of the simplest data structures. The majority of contemporary programming languages come with arrays by default.&lt;/p&gt;

&lt;p&gt;In the sample block below, I've initialized my list of colors into an array denoted by the square brackets[] and assigned them indexes based on their position in the array&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--cZyyKtTt--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/yoj8kzc7wddf15bdqrp1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--cZyyKtTt--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/yoj8kzc7wddf15bdqrp1.png" alt="Image description" width="415" height="190"&gt;&lt;/a&gt;&lt;br&gt;
Arrays can be also be multidimensional (2D), see the image below;&lt;/p&gt;

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

&lt;p&gt;Running the above will print out below&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--yHVwNzcl--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/t9xhvv5zirolbfghs0b5.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--yHVwNzcl--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/t9xhvv5zirolbfghs0b5.png" alt="Image description" width="391" height="92"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h4&gt;
  
  
  Advantages of Arrays
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;Arrays represent multiple data items of the same type using a single name.&lt;/li&gt;
&lt;li&gt;In arrays, the elements can be accessed randomly by using the index number.&lt;/li&gt;
&lt;li&gt;Arrays allocate memory in contiguous memory locations for all its elements. Hence there is no chance of extra memory being allocated in case of arrays. This avoids memory overflow or shortage of memory in arrays.&lt;/li&gt;
&lt;li&gt;Using arrays, other data structures like linked lists, stacks, queues, trees, graphs etc can be implemented.&lt;/li&gt;
&lt;li&gt;Two-dimensional arrays are used to represent matrices.&lt;/li&gt;
&lt;/ul&gt;
&lt;h4&gt;
  
  
  Disadvantages of arrays
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;The number of elements to be stored in an array should be known in advance.&lt;/li&gt;
&lt;li&gt;An array is a static structure (which means the array is of fixed size). Once declared the size of the array cannot be modified. The memory which is allocated to it cannot be increased or decreased.&lt;/li&gt;
&lt;li&gt;Insertion and deletion are quite difficult in an array as the elements are stored in consecutive memory locations and the shifting operation is costly.&lt;/li&gt;
&lt;li&gt;Allocating more memory than the requirement leads to wastage of memory space and less allocation of memory also leads to a problem.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;
  
  
  Stacks
&lt;/h2&gt;

&lt;p&gt;Stack is kind of data structure which allows operations on data only at one end. It allows access to the last inserted data only. Stack is also called LIFO (Last In First Out) data structure and Push and Pop operations are related in such a way that only last item pushed (added to stack) can be popped (removed from the stack).&lt;br&gt;
There is few more operations supported by stack which are following.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Peek − get the top element of the stack.&lt;/li&gt;
&lt;li&gt;isFull − check if stack is full.&lt;/li&gt;
&lt;li&gt;isEmpty − check if stack is empty.&lt;/li&gt;
&lt;/ul&gt;
&lt;h4&gt;
  
  
  Push Operation
&lt;/h4&gt;

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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// push item on the top of the stack 
public void push(int data) {

   if(!isFull()){
      // increment top by 1 and insert data 
      intArray[++top] = data;
   }else{
      System.out.println("Cannot add data. Stack is full.");
   }      
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Pop Operation
&lt;/h4&gt;

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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// pop item from the top of the stack 
public int pop() {
   // retrieve data and decrement the top by 1 
   return intArray[top--];        
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The main funcation implementing the array would be:&lt;/p&gt;

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

&lt;h4&gt;
  
  
  Advantages of Stack
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;Stack is easy to learn and implement for beginners.&lt;/li&gt;
&lt;li&gt;Stacks are used to solving problems that work on recursion.&lt;/li&gt;
&lt;li&gt;It allows you to control how memory is allocated and deallocated.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Disadvantages of Stack
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;Random access of elements is impossible in stacks.&lt;/li&gt;
&lt;li&gt;Stacks are neither flexible nor scalable.&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>programming</category>
      <category>dsa</category>
    </item>
    <item>
      <title>Data Structures 101: Introduction to Data Structures and Algorithms.</title>
      <dc:creator>GerryJ</dc:creator>
      <pubDate>Mon, 20 Jun 2022 04:43:49 +0000</pubDate>
      <link>https://dev.to/gerryj/data-structures-101-introduction-to-data-structures-and-algorithms-1d78</link>
      <guid>https://dev.to/gerryj/data-structures-101-introduction-to-data-structures-and-algorithms-1d78</guid>
      <description>&lt;p&gt;Difference between Data Structures and Algorithms?&lt;br&gt;
An &lt;strong&gt;algorithm&lt;/strong&gt; is "a finite sequence of instructions, each of which has a clear meaning and can be completed with a finite amount of effort in a finite amount of time_" for a specific activity. Simply put, an algorithm defines a collection of instructions that must be followed in a certain order to get the intended result. Algorithms are often written without regard to the underlying programming languages; that is, an algorithm can be written in more than one computer language.&lt;br&gt;
The capacity of computer scientists to create an effective algorithm is dependent on their ability to arrange data properly. As a result, &lt;strong&gt;data structures&lt;/strong&gt; are systemic methods of structuring data for certain operations. To note, no single data structure works well for all purposes, therefore, it is important to learn the strengths and limitations of several of them.&lt;/p&gt;

&lt;p&gt;Data structures can be categorized into;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Linear Data Structure &lt;/li&gt;
&lt;li&gt;Non-linear Data Structure&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5g3vkul0kh6mf35rss4n.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5g3vkul0kh6mf35rss4n.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Linear Data Structure
&lt;/h2&gt;

&lt;p&gt;If the elements of a data structure combine to generate a certain order, it is said to be linear. A linear relationship between all the pieces represented by a linear memory location is one technique of describing such linear structure inside memory. A good example of such are Arrays.&lt;br&gt;
The second method uses the idea of pointers or links to create a linear relationship between all of the objects displayed, e.g, Linked lists.&lt;br&gt;
&lt;strong&gt;&lt;em&gt;Arrays, Queues, Stacks, and Linked Lists&lt;/em&gt;&lt;/strong&gt; are all instances of linear data structures.&lt;/p&gt;

&lt;h2&gt;
  
  
  Non-Linear Data Structure
&lt;/h2&gt;

&lt;p&gt;This structure is mostly used to describe data that has a hierarchical relationship between the various parts.&lt;/p&gt;

&lt;p&gt;The following are some examples of non-linear data structures;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Graphs&lt;/li&gt;
&lt;li&gt;Trees&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Characteristics of an Algorithm
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Unambiguous&lt;/strong&gt; − Each of its steps and their inputs/outputs should be clear and must lead to only one meaning.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Input&lt;/strong&gt;− Have 0 or more well-defined inputs.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Output&lt;/strong&gt; − Have 1 or more well-defined outputs, and should match the desired output.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Finite&lt;/strong&gt;− Must terminate after a finite number of steps.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Feasibility&lt;/strong&gt;− Should be feasible with the available resources.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Independent&lt;/strong&gt;− An algorithm should have step-by-step directions, which should be independent of any programming code.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Efficiency of an algorithm
&lt;/h2&gt;

&lt;p&gt;The efficiency of an algorithm can be determined by two main factors; time and space &lt;/p&gt;

&lt;h5&gt;
  
  
  Time complexity
&lt;/h5&gt;

&lt;p&gt;Entails calculating the amount of time it takes to run an algorithm. the rule of thumb is that an effective algorithm should take the shortest time possible given a set of inputs.&lt;/p&gt;

&lt;h5&gt;
  
  
  Space Complexity
&lt;/h5&gt;

&lt;p&gt;Calculates the amount of memory an algorithm requires to run given a certain set of inputs. the rule of thumb here is that an algorithm should use the minimum amount of memory space possible.&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>dsa</category>
      <category>algorithms</category>
      <category>computerscience</category>
    </item>
  </channel>
</rss>
