Notes on Algorithms 3, Insertion Sort

Insertion Sort is yet another way to sort a list in ascending order just like we did with Selection Sort last week. Similar to selection sort, it will keep comparing the current value with other items and place it when it finds a suitable position. Given an array of unsorted integers, it will divide the list in 2 sections. The sorted left array and the unsorted right array. It will take the 1th item of the array as the key (or the right index) to make the comparisons. Since we start with the only one item in the left, we …

Read More

Notes on Algorithms 2, Selection Sort

Last time I practiced the binary search algorithm and then implemented it on JavaScript. This time I learned about Selection Sort. A selection sort is a sorting algorithm that will take an array of numbers (or strings) and then sort them into ascending order. If I give an input of [1, 5, 3, 4, 2] it will output [1, 2, 3, 4, 5]. In a nutshell I start with the first item of the list. Then I check the other items one by one and see if any of the other items are lower than my first item. If I …

Read More

Binary Search Algorithm in JavaScript

Binary Search algorithm cuts the list in half to find the given item. Here I will be implementing binary search algorithm in JavaScript. Pseudo code: Create a variable min, set it to 0 Create a variable max, set it to array length – 1 Create a variable guess While min is less than or equal max, keep going Add min and max and divided them by 2; make it an integer if the target value equals the value in the index of guess, return the guessed index If the guess is higher than the target value, set max to guess …

Read More

Notes on Algorithms 1, Binary Search

Algorithms are recipes to come up with a solution. Large algorithms are actually a collection of lots of smaller algorithms. When it comes to working with lots of data, making an efficient algorithm becomes important. The study of algorithms is needed to build big systems. This could result in the saving of computer time which translates into money saved. There are bunch of popular algorithms in the computer science land. Since computers like to work with a lot of data, it makes sense to come up with better ways to sort and search all these data. Data structures and algorithms …

Read More