The Bubble Sort

The Bubble Sort is one of the simplest sorts you can write, from a developer’s perspective. Unfortunately, it is one of the slowest to run from the computer’s perspective. A bubble sort works on the following idea. Given a list of values, start at the top value and look at the next value. If the…

Binary Search

If our data is pre-sorted then a binary search starts to make a lot of sense. It is like the guessing game we mentioned earlier where you need to find a number between 1 and 100. No one asks for 1, then 2, then 3… until they find it. Instead we ask for the mid…

Brute Force Searching

Now in some cases, we’ll use a brute force method of searching. This is slow and inefficient from a run-time perspective. However, it is relatively fast to write. With a brute force search, you scan through every item in a list until you find the element. Why use Brute Force As you can imagine, scanning…

Binary Trees

A binary tree is often the easiest type of tree structure to build because it has at most two child nodes. We usually call these child nodes left and right. We add a top node, our first value. The first value is always at the top – and is a special case when creating the…

Priority Queues

In the real world, while we might say we’re using a queue, there are those who can, and will, skip ahead of members already in the queue. Now, I’m not talking about skipping ahead of a person, like a line skipper in elementary school. A simple example you might think of using a queue, is…

How Queues Work

A queue is a fairly common data storage method. However, unlike many methods of storing data, where we keep the data for the entire runtime of a function or even the entire application, a queue’s data is designed to be consumable. That is, at some point data will enter the queue, and then it will…