Sign in

Full Time Web Developer. Part Time Hacker.

A beginners guide to using Queue and Stack data structures in your code.

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.

P.S.
You are already using these data structures in your code, you just don’t know it!

Queues

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…


Implement the Selection Sort Algorithm in JavaScript

Introduction

We are going to review the high level mechanics of a Selection Sort Algorithm (SSA) and then dive into 3 different implementations using JavaScript.

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,3
1. Is the element at index 0 [4] > than the element at index 1 [1] 2. Yes. 3. Swap the numbers…

Welcome to my tutorial on the wonderful, mysterious, and magical Heap Sort Algorithm (HSA), which we will build using JavaScript.

Introduction

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)

Review

Ok, first things first, before we can properly define what an Heap…


Here we go with another sort algorithm implemented in JavaScript!

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…


A guide to iterative and recursive implementations of the Insertion Sort Algorithm with JavaScript.

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.

Here is an example using a JavaScript array:

let array = [2,1,4,3];1. Is the number at index 1 [1] < than the number…

A straight forward guide to implementing a Bubble Sort Algorithm in JavaScript.

What is a Bubble Sort Algorithm (BSA)?

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.

How does it work?

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. …


A simple guide to implementing the Quick Sort Algorithm in JavaScript.

The Quick Sort Algorithm (QSA) is yet another path to sorting elements in a list. In our case, we will be implementing the QSA in JavaScript and passing it an array of numbers to be sorted in ascending order.

What is a Quick Sort Algorithm?

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  
[1,3,4,6,5]

At this point we partition the…


Let’s find things… fast-ish. This is a thorough look at Binary Search Algorithm implementations in JavaScript (Iterative and Recursive). Enjoy.

Building a search function is something that every developer has to do. In fact, basic Linear Search functions are usually some of the first patterns that developers learn to write. If you are unfamiliar with this concept I suggest you get up to speed with the basics of Linear Search Algorithms before you dig into Binary Search. Check out my guide to Linear Search implementations in JavaScript for a quick refresher:

The Concept

Ok, so what is a Binary Search Algorithm (BSA)?

This algorithm allows you to find out if a…


An overview of recursive and iterative merge sort implementations in JavaScript.

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…


Get a solid grip on Linear Search Algorithms and how to implement in JavaScript

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.

Who is this for? This article is designed to help Junior Developer’s get a solid grip on Linear Search Algorithms and how to implement in JavaScript. …

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store