Data Structures: 5. Binary Tree

Introduction#

A binary tree is a tree where each node has up to two leaves, and each of those leaves has up to two leaves. So you start with a root node and then fan out, like a genealogical tree.

The way the insertion works is that you look at the root …

Data Structures: 4. Doubly Linked List

Introduction#

A doubly linked list is the same as a linked list, execept that now each item is linked to both the next one and the previous one. So if you have a linked list with the following items (1, 2, 3, 4) it would look like this:

flowchart LR; …

Data Structures: 3. Linked List

Introduction#

A linked list is literally that, a list where each item is linked to the next one. So if you have a linked list with the following items (1, 2, 3, 4) it would look like this:

flowchart LR;
    H(["HEAD"]) --> A([1]);
    A([1]) …

Data Structures: 2. Queues

Introduction#

Queues, in there simplest form, are like stacks, except that the first element in is the first element out, or FIFO (First In First Out). It’s a bit like a stack of plates were you alway put on the top of the stack but if you remove a …

Data Structures: 1. Stack

Introduction#

The stack is one of the simplest data structures and one that is easy to image from every day life. If you have a stack of dishes, you normally add to the top of the stack and when you want to take one off you also take it from the top. This …

Algorithms: 6. Quick Sort

Introduction#

The Quick Sort algorithm uses what is known as a divide and conquor technique. It revolves around the idea of choosing a particular element in the array and then doing what is called pivoting around that. Essentially, all the elements less …

Algorithms: 5. Merge Sort

Introduction#

The merge sort is a bit more complicated than the bubble sort and insertion sort as you can see by the code below. In principle the merge sort works by splitting the array in half, and then splitting each of those two parts in half, and then …

Algorithms: 4. Insertion Sort

Introduction#

Another way of sorting an array is by using the insertion sort method. In this case we start at position 1 in the array1. We then set j = i, or in this case, 1. We then compare array[j - 1] with array[j], i.e. array[0] and array[1]. If …

Algorithms: 3. Bubble Sort

Introduction#

There are many different ways of sorting an array. One the simplest ways is the bubble sort. Essentially you start at the beginning of the array and compare element i with element i + 1. If i > i + 1, swap them, and increment i. This way …

Algorithms: 2. The Fibonacci Sequence

Introduction#

The Fibonacci sequence is probably one of the best know number sequences, with each number in the sequence being the sum of the two numbers that precede it, with 0 and 1 normally being the first two numbers of the sequence. The mathematical …