When you start learning about data structures and algorithms, things can get complicated really fast. So this article is meant to slow things down and get you comfortable with two common data structures (Queues & Stacks) that are often used as the basic building blocks in more complex algorithm implementations.
You are already using these data structures in your code, you just don’t know it!
Alright so what is a queue? A more official definition reads something like this:
“A collection of elements that is maintained in sequence and can be modified by the addition of a new element…
The general idea behind an SSA is to scan through a list of integers, find the smallest element, move it to the front of the list and repeat this process using the next element in the list.
Here is a step-by-step example that highlights how this actually happens:
array --> [4,1,5,2]
index --> 0,1,2,31. Is the element at index 0  > than the element at index 1  2. Yes. 3. Swap the numbers…
I’ll be honest, for any Junior Developers who are not familiar with Binary Search Trees, Max/Min Heaps, and other related concepts, this gonna be a pretty intense walkthrough. My suggestion, take your time with each step and make sure you are solid with the fundamentals as you move through the material. And as Samuel L. Jackson so eloquently put it…
“Hold on to your butts.” (Jurassic Park, 1993)
Ok, first things first, before we can properly define what an Heap…
Ok, so I have to admit, I really like this algorithm. It’s not the fastest sorting algorithm, nor is it the most efficient. But I happen to love the fact that this algorithm doesn’t compare values in a list to produce an ordered result! That’s right, the counting sort algorithm takes a conceptual left-turn and approaches this fundamental problem from different angle. This approach exemplifies the kind of creative thinking that drew to me to programming in the first place.
Before we dig into the specifics I think it’s important to note that this solution and its implementations are strongly…
The Insertion Sort Algorithm (ISA) is another sorting algorithm that sorts a list (or array) of numbers. Unlike divide and conquer algorithms, the ISA scans through an array to find the smallest number and swaps it with the number at the beginning of the list. This process repeats until no more swaps occur and the array has been sorted in ascending order.
let array = [2,1,4,3];1. Is the number at index 1  < than the number…
The BSA is a relatively simple algorithm to understand and implement. It is designed to sort an array of unsorted numbers. Unfortunately, it’s not a particularly efficient sorting algorithm and is rarely (if ever) used in enterprise level code.
The BSA works by comparing each element in an array to its immediate (adjacent neighbour) to determine which one is greater. The larger of the two elements ends up on the right and the smaller element ends up on the left. …
The QSA is a kind of divide and conquer algorithm that starts by choosing a pivot point (an arbitrary element in the array), which acts as an anchor to compare all of the other elements.
// Let's choose 4 as the pivot point
At this point we partition the…
This algorithm allows you to find out if a…
Here we go! So here are 3 implementations of the infamous Merge Sort Algorithm in vanilla JS. When I revisited this algorithm, I was reminded of my first glance at the logic behind it. From a high level, it’s not super difficult to wrap your head around. But as I descended further into the implementations I realized that a precise understanding of the algorithm is actually pretty hard!
Don’t feel bad if you struggle to understand the order of operations or even some of the patterns found in each…
Intimidated? Scared? Don’t be, the basics aren’t nearly as bad as some people make them out to be. In my experience, articles and online guides move a little to fast for Junior Developers to digest and include a lot of assumptions that aren’t as common as some Senior's think.
So let’s start with the basics.