<?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: Jack Cole</title>
    <description>The latest articles on DEV Community by Jack Cole (@123jackcole).</description>
    <link>https://dev.to/123jackcole</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%2F340255%2F1f238626-d737-4034-b126-0d6ec119a516.jpg</url>
      <title>DEV Community: Jack Cole</title>
      <link>https://dev.to/123jackcole</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/123jackcole"/>
    <language>en</language>
    <item>
      <title>How to Solve a Coding Challenge</title>
      <dc:creator>Jack Cole</dc:creator>
      <pubDate>Sun, 22 Nov 2020 04:58:05 +0000</pubDate>
      <link>https://dev.to/123jackcole/how-to-solve-a-coding-challenge-3pp2</link>
      <guid>https://dev.to/123jackcole/how-to-solve-a-coding-challenge-3pp2</guid>
      <description>&lt;p&gt;Recently I've been doing LeetCode's weekly contests and I recommend anyone wanting to practice for interviews do them as well. The contests are great because they mimic the environment of a real interview. You are given a set amount of time (often 90 minutes) to solve several problems that increase in difficulty. The tests do a good job of imitating a high pressure environment rather than practicing problems in a lax setting.&lt;/p&gt;

&lt;p&gt;After repeatedly taking these contests I feel that I've nailed down a method that works for me for solving problems and wanted to share. Anyway lets jump into how I solve each problem.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Take the time to read the problem 2-3 times until I'm confident I understand it. If I have a few confusions I continue to the next step anyway which is...&lt;/li&gt;
&lt;li&gt;Examine the test cases and make sure I understand why the test inputs lead to the test outputs.&lt;/li&gt;
&lt;li&gt;If you're given the expected time complexity you can narrow down approaches they want you to use. For example, if they want you to do an O(log n) search you can first try a binary search.&lt;/li&gt;
&lt;li&gt;At this point I think about how I'm going to approach the problem while looking at the provided code as well as the provided constraints. &lt;/li&gt;
&lt;li&gt;Always try to think of edge cases that could cause problems before you code as well as while you are coding&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Thanks for reading! I'd love to hear what works for you when you're solving a coding problem and how what you think I should do differently.&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>algorithms</category>
      <category>javascript</category>
      <category>computerscience</category>
    </item>
    <item>
      <title>Creating a Coding Interview Study Guide in Ruby</title>
      <dc:creator>Jack Cole</dc:creator>
      <pubDate>Sun, 15 Nov 2020 07:33:14 +0000</pubDate>
      <link>https://dev.to/123jackcole/creating-a-coding-interview-study-guide-in-ruby-2kpa</link>
      <guid>https://dev.to/123jackcole/creating-a-coding-interview-study-guide-in-ruby-2kpa</guid>
      <description>&lt;p&gt;As a follow up to my &lt;a href="https://dev.to/123jackcole/creating-a-coding-interview-study-guide-p37"&gt;previous post&lt;/a&gt;, I'm going to be creating a study guide on various computer science concepts that would be helpful for coding interviews. All of the code for this will be done in ruby. If I previously posted about a topic I'll be sure to link to it.&lt;/p&gt;

&lt;p&gt;You're going to need to know iteration and recursion, arrays and matrices, &lt;a href="https://dev.to/123jackcole/learning-linked-lists-6bf"&gt;linked lists&lt;/a&gt;, &lt;a href="https://dev.to/123jackcole/learning-queues-4jnc"&gt;queues&lt;/a&gt;, &lt;a href="https://dev.to/123jackcole/learning-the-stack-6n5"&gt;stacks&lt;/a&gt;, &lt;a href="https://dev.to/123jackcole/learning-heaps-in-javascript-1ocf"&gt;heaps&lt;/a&gt;, sets, hash maps, &lt;a href="https://dev.to/123jackcole/learning-binary-trees-part-1-implementation-55bb"&gt;trees&lt;/a&gt;, binary search, &lt;a href="https://dev.to/123jackcole/learning-graphs-part-1-implementation-4kpc"&gt;graphs&lt;/a&gt;, &lt;a href="https://dev.to/123jackcole/learning-graphs-part-2-traversal-3088"&gt;traversals&lt;/a&gt; like &lt;a href="https://dev.to/123jackcole/learning-binary-trees-part-2-breadth-first-search-454a"&gt;breadth-first search&lt;/a&gt; and &lt;a href="https://dev.to/123jackcole/learning-binary-trees-part-3-depth-first-search-2n8o"&gt;depth-first search&lt;/a&gt;, &lt;a href="https://dev.to/123jackcole/learning-tries-in-javascript-5geg"&gt;tries&lt;/a&gt;, and &lt;a href="https://dev.to/123jackcole/sorting-algorithms-in-javascript-5f4b"&gt;sorting algorithms&lt;/a&gt; (particularly merge sort and quick sort). Also knowing some dynamic programming concepts could be helpful such as &lt;a href="https://dev.to/123jackcole/learning-memoization-1gp7"&gt;memoization&lt;/a&gt; and &lt;a href="https://dev.to/123jackcole/divide-and-conqueror-1c4b"&gt;divide and conqueror&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;The file with all of the code examples can be found &lt;a href="https://github.com/123JackCole/Tech-Interview-Cheatsheet"&gt;here&lt;/a&gt;. I'll be continuously updating and refactoring the code. Hopefully this is helpful to anyone else reading this. If I miss anything be sure to let me know and I'll update it.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>computerscience</category>
      <category>ruby</category>
      <category>career</category>
    </item>
    <item>
      <title>Creating a Coding Interview Study Guide in Javascript</title>
      <dc:creator>Jack Cole</dc:creator>
      <pubDate>Sun, 08 Nov 2020 07:43:38 +0000</pubDate>
      <link>https://dev.to/123jackcole/creating-a-coding-interview-study-guide-p37</link>
      <guid>https://dev.to/123jackcole/creating-a-coding-interview-study-guide-p37</guid>
      <description>&lt;p&gt;In this post I'm going to be compiling all of the computer science concepts I've learned to create a study guide on most of the general technical skills you would need to know. If there's anything I missed please let me know and I'll be sure to add it to the list. All of the code for this is going to be in Javascript. If I previously posted about a topic I'll be sure to link to it. Here we go.&lt;/p&gt;

&lt;p&gt;You're going to need to know iteration and recursion, arrays and matrices, &lt;a href="https://dev.to/123jackcole/learning-linked-lists-6bf"&gt;linked lists&lt;/a&gt;, &lt;a href="https://dev.to/123jackcole/learning-queues-4jnc"&gt;queues&lt;/a&gt;, &lt;a href="https://dev.to/123jackcole/learning-the-stack-6n5"&gt;stacks&lt;/a&gt;, &lt;a href="https://dev.to/123jackcole/learning-heaps-in-javascript-1ocf"&gt;heaps&lt;/a&gt;, sets, hash maps, &lt;a href="https://dev.to/123jackcole/learning-binary-trees-part-1-implementation-55bb"&gt;trees&lt;/a&gt;, binary search, &lt;a href="https://dev.to/123jackcole/learning-graphs-part-1-implementation-4kpc"&gt;graphs&lt;/a&gt;, &lt;a href="https://dev.to/123jackcole/learning-graphs-part-2-traversal-3088"&gt;traversals&lt;/a&gt; like &lt;a href="https://dev.to/123jackcole/learning-binary-trees-part-2-breadth-first-search-454a"&gt;breadth-first search&lt;/a&gt; and &lt;a href="https://dev.to/123jackcole/learning-binary-trees-part-3-depth-first-search-2n8o"&gt;depth-first search&lt;/a&gt;, &lt;a href="https://dev.to/123jackcole/learning-tries-in-javascript-5geg"&gt;tries&lt;/a&gt;, and &lt;a href="https://dev.to/123jackcole/sorting-algorithms-in-javascript-5f4b"&gt;sorting algorithms&lt;/a&gt; (particularly merge sort and quick sort). Also knowing some dynamic programming concepts could be helpful such as &lt;a href="https://dev.to/123jackcole/learning-memoization-1gp7"&gt;memoization&lt;/a&gt; and &lt;a href="https://dev.to/123jackcole/divide-and-conqueror-1c4b"&gt;divide and conqueror&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;The file with all of the code examples can be found &lt;a href="https://github.com/123JackCole/Tech-Interview-Cheatsheet"&gt;here&lt;/a&gt;. I'll be continuously updating this file in the future and plan on posting a similar cheatsheet with all of the code implemented in Ruby.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>computerscience</category>
      <category>beginners</category>
      <category>career</category>
    </item>
    <item>
      <title>Learning How to Divide and Conqueror</title>
      <dc:creator>Jack Cole</dc:creator>
      <pubDate>Sun, 01 Nov 2020 03:14:16 +0000</pubDate>
      <link>https://dev.to/123jackcole/divide-and-conqueror-1c4b</link>
      <guid>https://dev.to/123jackcole/divide-and-conqueror-1c4b</guid>
      <description>&lt;p&gt;Last week I discussed the concept of &lt;a href="https://dev.to/123jackcole/learning-memoization-1gp7"&gt;memoization&lt;/a&gt;. This week I wanted to continue discussing concepts needed for dynamic programming and focus on using the method of divide and conqueror.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;What Is Divide and Conqueror&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Divide and conqueror is an algorithm paradigm based on multi branch recursion. More specifically you take the initial problem and breaking it down into sub-problems until the sub-problems are simple enough to effectively solve. The solutions of the sub-problems are then combined to form the solution of the original problem.&lt;/p&gt;

&lt;p&gt;Divide and conqueror is often used to solve problems such as sorting and multiplying large numbers. To show an example I'll show the implementation of merge sort and quick sort. Since I've previously covered these in a post on &lt;a href="https://dev.to/123jackcole/sorting-algorithms-in-javascript-5f4b"&gt;sorting algorithms&lt;/a&gt; this time I've coded them in Ruby!&lt;/p&gt;

&lt;p&gt;Remember that these methods are going to be following the following three steps.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Divide&lt;/strong&gt; the problem into sub-problems&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Conqueror&lt;/strong&gt; the sub-problems&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Merge&lt;/strong&gt; the results of the sub-problems into the final solution&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In my implementation I use two functions to clearly illustrate the process of dividing and conqueror. The first method divides the input into smaller arrays that can easily be sorted. The next methods then sorts the smaller arrays and then combines the sorted numbers to return the solution.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Wmfm1nEC--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/gpt6b93j0vrkxhil8u86.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Wmfm1nEC--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/gpt6b93j0vrkxhil8u86.png" alt="Merge Sort Divide"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s---E4hC588--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/4lmkshm0uhx26cbls89d.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s---E4hC588--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/4lmkshm0uhx26cbls89d.png" alt="Merge Sort Sort"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In the implementation of quick sort these concepts are also applied in a single method.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--qX0lC9h8--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/3glgqlj3bc08sn50ofn5.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--qX0lC9h8--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/3glgqlj3bc08sn50ofn5.png" alt="Quick Sort"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Thanks for reading! The code for this lesson can be found &lt;a href="https://github.com/123JackCole/Divide-and-Conqueror"&gt;here&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>ruby</category>
      <category>computerscience</category>
      <category>beginners</category>
      <category>algorithms</category>
    </item>
    <item>
      <title>Learning Memoization in Javascript Part 2</title>
      <dc:creator>Jack Cole</dc:creator>
      <pubDate>Sun, 25 Oct 2020 03:53:29 +0000</pubDate>
      <link>https://dev.to/123jackcole/learning-memoization-in-javascript-part-2-3jpa</link>
      <guid>https://dev.to/123jackcole/learning-memoization-in-javascript-part-2-3jpa</guid>
      <description>&lt;p&gt;After doing some research on how to implement memoization in a function with multiple arguments I realized this is a pretty unusual situation that will rarely occur... &lt;/p&gt;

&lt;p&gt;In my &lt;a href="https://dev.to/123jackcole/learning-memoization-1gp7"&gt;last post&lt;/a&gt; I went over implementing memoization in javascript using the fibonacci sequence as an example. However, in that example our function only utilized a single argument. But how do we memoize when a function needs to track multiple arguments?&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Implementation&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;In my example I'm going to use a nested map object. The map will have multiple dimensions and store the fibonacci data in the dimension that matches the specific method call. Remember, this is just an example displaying how we would go about doing this.&lt;/p&gt;

&lt;p&gt;Also going on a short tangent, notice how I use map objects instead of a regular hash. Javascript has a map object, learn to use it! You can read more about that &lt;a href="https://dev.to/katkelly/advantages-of-a-javascript-map-cen"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Sq_3fEE5--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/bq6nx9j97m9qxjh2hyze.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Sq_3fEE5--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/bq6nx9j97m9qxjh2hyze.png" alt="Memoization Multiple Functions"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Thanks for reading! I know that this is a pretty niche situation but memoization is a good skill to know and could come in handy in the future! The code for this post and my last post can be found &lt;a href="https://github.com/123JackCole/Memoization"&gt;here&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>computerscience</category>
      <category>javascript</category>
      <category>beginners</category>
      <category>codenewbie</category>
    </item>
    <item>
      <title>Learning Memoization</title>
      <dc:creator>Jack Cole</dc:creator>
      <pubDate>Sun, 18 Oct 2020 06:08:56 +0000</pubDate>
      <link>https://dev.to/123jackcole/learning-memoization-1gp7</link>
      <guid>https://dev.to/123jackcole/learning-memoization-1gp7</guid>
      <description>&lt;p&gt;In this post I'll be discussing what memoization is as well as when to use it.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;What is Memoization?&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Memoization at its core is the process of greatly decreasing the run time of expensive recursive or iterative function. More specifically, memoization stores and reuses precomputed values while passing them through recursive calls to improve the speed of your algorithms.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Why Use Memoization?&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;A great example of how and why to use memoization can be seen when creating a function to create the &lt;a href="https://en.wikipedia.org/wiki/Fibonacci_number" rel="noopener noreferrer"&gt;Fibonacci sequence&lt;/a&gt;. &lt;/p&gt;

&lt;p&gt;If you're not familiar, the Fibonacci sequence starts with 0 and 1, all further values are calculated by adding the previous two values. 0 + 1 = 1, 1 + 1 = 2, 1 + 2 = 3, 2 + 3 = 5, etc. &lt;/p&gt;

&lt;p&gt;This function is often made recursively like so.&lt;/p&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%2Fi%2Fbxl3csj76mk9lqh93yx3.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%2Fi%2Fbxl3csj76mk9lqh93yx3.png" alt="Fibonacci Function"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;When calling this function on small numbers it is relatively quick, but when we call it on large numbers the runtime will drastically increase. This is due to each call of fibonacci() doing the same amount of work, regardless of it was already run or not. The function is repeatedly doing the same calculations over and over again!&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;How to use Memoization?&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Instead of doing wasting time by doing the same work over and over again let's instead store the result of the work in case we need to use it again. In this case we can use a simple hash map to track what numbers have been computed and what results we got from the computations.&lt;/p&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%2Fi%2Fjdfst3ioj7qgb5ex8yqo.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%2Fi%2Fjdfst3ioj7qgb5ex8yqo.png" alt="Memoized Fibonacci Function"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Our main function contains our map that stores computed values as well as another function. This inner function checks if our hash contains the result of the called number, otherwise it does the fibonacci function from the original example. By doing this method we avoid any unnecessary work.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Conclusion&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Hopefully you now understand the basics of memoization. However, in this example we only really scratched the surface. Memoization gets much more complicated when the function needs to handle multiple arguments or store objects passed as arguments. In my next post I'll go over some more complicated scenarios and how to deal with them.&lt;/p&gt;

&lt;p&gt;Thanks for reading! The code used in this post can be found &lt;a href="https://github.com/123JackCole/Memoization" rel="noopener noreferrer"&gt;here&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>computerscience</category>
      <category>beginners</category>
      <category>javascript</category>
      <category>algorithms</category>
    </item>
    <item>
      <title>Learning Heap Sort in Javascript</title>
      <dc:creator>Jack Cole</dc:creator>
      <pubDate>Sat, 10 Oct 2020 01:12:29 +0000</pubDate>
      <link>https://dev.to/123jackcole/learning-heap-sort-in-javascript-5c5m</link>
      <guid>https://dev.to/123jackcole/learning-heap-sort-in-javascript-5c5m</guid>
      <description>&lt;p&gt;In this week's post I'll be going over how to do a heap sort using javascript. In a &lt;a href="https://dev.to/123jackcole/learning-heaps-in-javascript-1ocf"&gt;past post&lt;/a&gt; I've discussed heaps as a data structure. Since this sort utilizes a heap I recommend checking out that first.&lt;/p&gt;

&lt;p&gt;Now onto the heap sort. Heap sort works similarly to &lt;a href="https://dev.to/123jackcole/sorting-algorithms-in-javascript-part-2-40o1"&gt;selection sort&lt;/a&gt; in that they both find the maximum element and place it at the end.&lt;/p&gt;

&lt;h2&gt;
  
  
  Helper Methods
&lt;/h2&gt;

&lt;p&gt;Due the the comparing we're going to be doing between elements it's a good idea to have a method that can easily swap the location of elements. We can easily do this using some fancy ES6 syntax.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--O7qiT88f--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/ga3s4kckuwwkltv82zt7.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--O7qiT88f--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/ga3s4kckuwwkltv82zt7.png" alt="Swap"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We're also going to need a method that turns an array into a max heap. Remember that this means that each node will be  greater value than it's children.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ixRvQ_qz--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/agydp6rd3iuku8be0e5k.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ixRvQ_qz--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/agydp6rd3iuku8be0e5k.png" alt="Heapify"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  The Sort
&lt;/h2&gt;

&lt;p&gt;The function works by taking the input array and turning it into a max heap. From here we swap the location of the root node and the last node, and then we reduce the size of the heap by one, effectively removing the largest value. We then repeat this process until there are no more values in the heap.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--uWbPR3eA--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/fp145d2fwjced9nwsdsp.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--uWbPR3eA--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/fp145d2fwjced9nwsdsp.png" alt="Heap Sort"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Heap sort has a runtime of O(nlogn). This means that a good situation to use a heap sort is when you're want a consistently timed sort (in games) but don't necessarily need the quickest solution every time. Heap sort will always have a O(nlogn) whereas a quick sort is often faster but can potentially be very slow. &lt;/p&gt;

&lt;p&gt;Thanks for reading! The code for this post can be found &lt;a href="https://github.com/123JackCole/Heaps"&gt;here&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>computerscience</category>
      <category>javascript</category>
      <category>algorithms</category>
    </item>
    <item>
      <title>Sorting Algorithms in Javascript Part 2</title>
      <dc:creator>Jack Cole</dc:creator>
      <pubDate>Sun, 04 Oct 2020 04:44:47 +0000</pubDate>
      <link>https://dev.to/123jackcole/sorting-algorithms-in-javascript-part-2-40o1</link>
      <guid>https://dev.to/123jackcole/sorting-algorithms-in-javascript-part-2-40o1</guid>
      <description>&lt;p&gt;It's been a couple of weeks since I wrote my &lt;a href="https://dev.to/123jackcole/sorting-algorithms-in-javascript-5f4b"&gt;last post&lt;/a&gt; on sorting algorithms and I think it's finally time to revisit the topic. In this post I'll be covering additional sorting algorithms that are more uncommon than the ones I covered in my first post.&lt;/p&gt;

&lt;p&gt;In this article I'm going to cover:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Selection Sort&lt;/li&gt;
&lt;li&gt;Bucket Sort&lt;/li&gt;
&lt;li&gt;Counting Sort&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Helper Methods
&lt;/h2&gt;

&lt;p&gt;Just like in my first post, we're going to be doing a lot of swapping of elements. It makes sense to create some helper methods that can be used in our sorting methods.&lt;/p&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%2Fi%2F8yac3kofqr9sobjuxo0a.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%2Fi%2F8yac3kofqr9sobjuxo0a.png" alt="Helper Methods"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Selection Sort
&lt;/h2&gt;

&lt;p&gt;Selection sort works by dividing the input array into a sorted and unsorted list. The sorted list begins empty and while the unsorted begins as the initial array. We continuously loop through the array to find the smallest element and add that element to the sorted list. This repeats until the entire array is sorted.&lt;/p&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%2Fi%2Fr3v830d7u6bkq6d4uhdo.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%2Fi%2Fr3v830d7u6bkq6d4uhdo.png" alt="Selection"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Runtime: O(n^2) to O(n^2)&lt;/p&gt;

&lt;h2&gt;
  
  
  Bucket Sort
&lt;/h2&gt;

&lt;p&gt;Bucket sort works by distributing the elements of the input array into different sections or &lt;em&gt;buckets&lt;/em&gt;. The elements are then sorted with a different sorting method, most commonly selection sort. Bucket sort is much faster than solely using selection sort due to the strategic placement of elements into buckets at the cost of additional memory use.&lt;/p&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%2Fi%2F64ofs0qqn5uczuqpbn4y.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%2Fi%2F64ofs0qqn5uczuqpbn4y.png" alt="Bucket"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Runtime: O(n+k) to O(n^2)&lt;/p&gt;

&lt;h2&gt;
  
  
  Counting Sort
&lt;/h2&gt;

&lt;p&gt;Counting sort is unique in that it doesn't do any comparing between it's elements. Instead counting sort counts the number of elements having distinct key values. From there it uses arithmetic to calculate the position of each element. The main caveat of counting sort is that we need to know the min and max elements in the input array.&lt;/p&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%2Fi%2Fsoi15h09vmaa4h12c0ry.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%2Fi%2Fsoi15h09vmaa4h12c0ry.png" alt="Count"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Runtime: O(n)&lt;/p&gt;

&lt;p&gt;Thanks for readying! I intent to also cover heap sorting in a future post but wanted to cover heap data structures before getting to that. &lt;/p&gt;

&lt;p&gt;The code for this lesson can be found &lt;a href="https://github.com/123JackCole/sorting_algorithms" rel="noopener noreferrer"&gt;here&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>beginners</category>
      <category>algorithms</category>
      <category>computerscience</category>
    </item>
    <item>
      <title>Learning Regex in Javascript Part 2</title>
      <dc:creator>Jack Cole</dc:creator>
      <pubDate>Sat, 26 Sep 2020 00:12:59 +0000</pubDate>
      <link>https://dev.to/123jackcole/learning-regex-in-javascript-part-2-1o3i</link>
      <guid>https://dev.to/123jackcole/learning-regex-in-javascript-part-2-1o3i</guid>
      <description>&lt;p&gt;In this post I'll be be wrapping up my &lt;a href="https://dev.to/123jackcole/learning-regex-in-javascript-part-1-13pe"&gt;first post on regex&lt;/a&gt;. In a similar fashion to my last post, I'll be sure to provide examples that show the inputs and outputs. Let's jump into it!&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Some Shortcuts&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;There are a ton of characters you can use in your regex to create unique specifications in your queries. I'll list a bunch below.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;. gets any character that's not a line break&lt;/li&gt;
&lt;li&gt;\s gets a white space&lt;/li&gt;
&lt;li&gt;\S gets a non-white space&lt;/li&gt;
&lt;li&gt;\d gets a digit&lt;/li&gt;
&lt;li&gt;\D gets a non-digit&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--9HjA7hz9--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/fg01l7z9kuec8npfcbty.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--9HjA7hz9--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/fg01l7z9kuec8npfcbty.png" alt="Regex"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Only the Start or End&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;If you want to find a character at the beginning or end of your string, you can use &lt;code&gt;^&lt;/code&gt; or &lt;code&gt;$&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--N0q9DKyV--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/ubjg0rzqt40qxojn6tmd.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--N0q9DKyV--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/ubjg0rzqt40qxojn6tmd.png" alt="regex"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;The Caret (^)&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;^&lt;/code&gt; also has a second use. When used inside of brackets, &lt;code&gt;^&lt;/code&gt; indicates that you want anything except what's in the brackets.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--CQ3nWTmN--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/g9ar1x48r65fnyp2gtlt.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--CQ3nWTmN--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/g9ar1x48r65fnyp2gtlt.png" alt="Regex"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Quantifiers&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Quantifiers specify how many of the specified characters we want.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;? means zero or one&lt;/li&gt;
&lt;li&gt;* means zero or more&lt;/li&gt;
&lt;li&gt;+ means one or more&lt;/li&gt;
&lt;li&gt;{} specifies the exact quantity&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--pLZOdn9v--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/w8dbshqw4jp72n4w73yw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--pLZOdn9v--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/w8dbshqw4jp72n4w73yw.png" alt="Quantifiers"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Special Characters&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Finally, if you want to capture any special characters you need to precede them with a &lt;code&gt;\&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s---gbcbJ3P--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/orctnpymw8vrzp03arqz.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s---gbcbJ3P--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/orctnpymw8vrzp03arqz.png" alt="Special Characters"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>computerscience</category>
      <category>javascript</category>
    </item>
    <item>
      <title>Learning Regex in Javascript Part 1</title>
      <dc:creator>Jack Cole</dc:creator>
      <pubDate>Sun, 20 Sep 2020 01:28:20 +0000</pubDate>
      <link>https://dev.to/123jackcole/learning-regex-in-javascript-part-1-13pe</link>
      <guid>https://dev.to/123jackcole/learning-regex-in-javascript-part-1-13pe</guid>
      <description>&lt;p&gt;Today I'll be discussing the intimidating regex. Regex, or regular expressions are a sequence of characters that are used to define a search pattern. The search pattern is most often used in string searches to find or replace certain sections of a string.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Making a Regex Object&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;In javascript there are two different methods to create a regex. The first is using the constructor provided by javascript,  &lt;code&gt;new RegExp()&lt;/code&gt;. Here's a quick example.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--YL53Azn9--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/v0p3uytoh3g8pu8udw8g.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--YL53Azn9--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/v0p3uytoh3g8pu8udw8g.png" alt="RegExp constructor"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The other way is by creating a literal. Here's an example.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Lebzgtbf--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/18849vzrmckuh3ovoko1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Lebzgtbf--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/18849vzrmckuh3ovoko1.png" alt="Literal contructor"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Regex Methods&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Javascript has four helpful methods that can be used with regex objects.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;match&lt;/li&gt;
&lt;li&gt;test&lt;/li&gt;
&lt;li&gt;replace&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Match is called on a string and takes an input of a regex object. It returns an array with any characters that matched the regex.&lt;/p&gt;

&lt;p&gt;Test takes an input of a string and returns a boolean that indicates if the string had any matches with the regex.&lt;/p&gt;

&lt;p&gt;Replace is used on a string, takes a regex object and a string as input and returns the new string with any sections that matched the regex replaced by the specified string.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--QrIcv9g0--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/vti6xkazflu93lqsslxt.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--QrIcv9g0--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/vti6xkazflu93lqsslxt.png" alt="Test cases"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Brackets, Hyphens&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;If you use brackets around your regex you'll look for a single character. If you use a hyphen you'll look for anything in that range.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--9IPkWo1Y--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/elott7iva5dm5cawr1if.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--9IPkWo1Y--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/elott7iva5dm5cawr1if.png" alt="Brackets and hyphens"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Flags&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Flags can be added to to the end of a regex to change what is returned. In javascript the usable flags are,&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;i, ignore case&lt;/li&gt;
&lt;li&gt;g, global match (find all)&lt;/li&gt;
&lt;li&gt;m, multi line&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--fuo49Kpt--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/wi5fwqpdi0mhbeywkruv.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--fuo49Kpt--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/wi5fwqpdi0mhbeywkruv.png" alt="Flags"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Thanks for reading! Next week I'll continue to go through more complex uses of regex. The code for this lesson can be found &lt;a href="https://github.com/123JackCole/Regex/blob/master/regex.js"&gt;here&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>javascript</category>
      <category>computerscience</category>
    </item>
    <item>
      <title>Learning Heaps in Javascript</title>
      <dc:creator>Jack Cole</dc:creator>
      <pubDate>Sat, 12 Sep 2020 21:26:24 +0000</pubDate>
      <link>https://dev.to/123jackcole/learning-heaps-in-javascript-1ocf</link>
      <guid>https://dev.to/123jackcole/learning-heaps-in-javascript-1ocf</guid>
      <description>&lt;p&gt;In this weeks article I'll be discussing heaps. We'll go over how to implement a heap in javascript, but first let's go over what a heap is.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;What is a heap?&lt;/strong&gt;
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;A heap is an almost complete tree like data structure that satisfies the heaps property.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Let's dissect this definition. First, we need to know what a complete tree is. A complete tree is a &lt;a href="https://dev.to/123jackcole/learning-binary-trees-part-1-implementation-55bb"&gt;tree data structure&lt;/a&gt; where every node is filled except for the last level.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ORMP7g3Q--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/9wf1fkm8jgf6hycvcrxv.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ORMP7g3Q--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/9wf1fkm8jgf6hycvcrxv.jpg" alt="Full Tree"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Next we need to know what properties a heap can have. Heaps are often structures in one of two ways. As a min heap, or as a max heap. A min heap is a heap where the parent node is greater than it's children. A max heap is a heap where the parent node is less than it's children. Furthermore, heaps can be classified as a binary heap if each node only has two children. Below is an example of a non-complete binary min heap.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--dvdyVtSX--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/cvpz3b29le673iept6vn.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--dvdyVtSX--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/cvpz3b29le673iept6vn.png" alt="Binary Min Heap"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Why use a heap?&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;The main use for a heap is a priority queue. A priority queue is a normal &lt;a href="https://dev.to/123jackcole/learning-queues-4jnc"&gt;queue&lt;/a&gt; where each element has an additional value that indicates the priority it should exit the queue. Heaps are a perfect fit for priority queues because they support insert, delete, and extract max/min methods in O(logn) time. &lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Implementation of a heap&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Now that we've got through all of that let's learn how to go about implementing a heap. Due to heaps being a tree like structure you would think that implementing one would be similar to implementing a tree. However, due to the ordered structure of a heap we actually are going to be storing our heap in an array.&lt;/p&gt;

&lt;p&gt;We are able to store our heap in an array compactly because we don't need to use any pointers. We are instead able to locate the parent and children through arithmetic using the indicies of the array.&lt;/p&gt;

&lt;p&gt;Let's start with the heap class. All we need to do is create an empty array. For this implementation we'll be making a minHeap.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--3E_dL-42--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/b4du71an1w452krmi3pt.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--3E_dL-42--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/b4du71an1w452krmi3pt.png" alt="Heap class"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;From here we'll need a few helper methods that we'll use for our main functionality. First we'll need a method to swap the location of two elements in our heap given their indexes. This can cleanly be done in one line using ES6 syntax, nice!&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--_KiiH1PS--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/x7skdparlb5rd36wwfa8.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--_KiiH1PS--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/x7skdparlb5rd36wwfa8.png" alt="Swap method"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Next we'll need a method that takes an element and moves it up the tree until it is placed into the right location. We'll pass the method the index of the element we want to move. We'll then continuously loop, each time comparing current element with its parent. If the parent is greater than the current element, we'll swap their locations and repeat the process until the element is in the correct location.&lt;/p&gt;

&lt;p&gt;Notice how we are able to locate the parent note with a basic equation.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--FcVAEysm--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/ajvfqcv746h2nqwrogjt.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--FcVAEysm--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/ajvfqcv746h2nqwrogjt.png" alt="Move up method"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Similar to the moveUp method, we'll need a method to move an element down the tree. This method will be of a similar structure except we'll be comparing the parent to both of its children. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--BBksHBaG--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/7t7zyotmtttqy6ocw8u5.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--BBksHBaG--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/7t7zyotmtttqy6ocw8u5.png" alt="Move down method"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now that we have our helper methods we can easily implement the main functions of our heap. First, we need a method to insert elements into our heap. All we need to do is push our element to the end of our heap then move it up.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--tFyjE2aP--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/4c3vwdar7o6wqoe6wv3j.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--tFyjE2aP--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/4c3vwdar7o6wqoe6wv3j.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Next, we need a method to remove elements from the heap. This method is going to be a two in one. It defaults the argument to null so that when nothing is passed in we remove the last element from the heap. Otherwise, the method removes the specified node. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--beJeJJKH--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/imwxppuzhz2onho6njok.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--beJeJJKH--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/imwxppuzhz2onho6njok.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Thanks for reading! As usual, the code from this post can be found &lt;a href="https://github.com/123JackCole/Heaps"&gt;here&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>algorithms</category>
      <category>javascript</category>
      <category>computerscience</category>
    </item>
    <item>
      <title>Learning Tries in Javascript</title>
      <dc:creator>Jack Cole</dc:creator>
      <pubDate>Sun, 06 Sep 2020 00:12:16 +0000</pubDate>
      <link>https://dev.to/123jackcole/learning-tries-in-javascript-5geg</link>
      <guid>https://dev.to/123jackcole/learning-tries-in-javascript-5geg</guid>
      <description>&lt;p&gt;In this weeks article I'm going to be discussing Tries. A Trie is a data structure thats main purpose is re&lt;b&gt;trie&lt;/b&gt;val. Tries are most often used to store and retrieve strings in O(L) time, where L is the length of the string. A common use of a Trie data structure is to do prefix searching, such as an autocomplete form.&lt;/p&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%2Fi%2Fw4a3d5r11urr07335wwx.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%2Fi%2Fw4a3d5r11urr07335wwx.png" alt="Trie Example"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As you can see in the example above, each node contains a letter. Each chain of nodes will result in a string. In theory we could use a trie to store every word in the dictionary, but that would use an incredible amount of memory. For this reason Tries are often replaced by other data structures when a prefix search isn't necessary.&lt;/p&gt;

&lt;p&gt;Tries have two main functions: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Insert&lt;/li&gt;
&lt;li&gt;Search&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;But before we dive into those, let's first start with implementing the overall structure.&lt;/p&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%2Fi%2Fw8ph392f2sagdbhercem.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%2Fi%2Fw8ph392f2sagdbhercem.png" alt="Node and Trie Classes"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We need to create two classes, a node class and our tree class. Each node will contain a value, which is the letter it represents, a boolean representing if it's the last letter in a word, and an object for holding the nodes children. The Trie will only need the root, which is initialized as an empty node.&lt;/p&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%2Fi%2F161lb9v4aqt3tc7y00bk.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%2Fi%2F161lb9v4aqt3tc7y00bk.png" alt="Insert"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;For our insert method we need to traverse through our tree. So to start we initialize a node variable representing the node we are currently on, and set it to the root. For each character in the passed in word, we see if our current node is holding the character as a child, if it isn't we add it as a child. We then change our current node to that character and repeat until we've gone through the word. After our traversal we set the last node's status to show it is the last character of a word.&lt;/p&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%2Fi%2F4sxyiuqrl43faog3l0kn.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%2Fi%2F4sxyiuqrl43faog3l0kn.png" alt="Search"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Our search method is similar to our insert method in that we are doing another traversal. However, all we do in the loop is check if each letter is present in the word. If all of the characters are there and the last character's status shows it's the last character of a word then we return true, otherwise we return false.&lt;/p&gt;

&lt;p&gt;Thanks for reading! You can find the code for this post &lt;a href="https://github.com/123JackCole/Tries" rel="noopener noreferrer"&gt;here&lt;/a&gt;.&lt;/p&gt;

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