Skip to main content

Posts

Showing posts from December, 2015

JS: Insertion Sort

Insertion sort is a simple sorting algorithm that builds the final sorted array (or list) one item at a time. Insertion sort iterates, consuming one input element each repetition, and growing a sorted output list. Each iteration, insertion sort removes one element from the input data, finds the location it belongs within the sorted list, and inserts it there. It repeats until no input elements remain. Here is a practical implementation of it.     

JS: Fibonacci sequence

The first 21 Fibonacci numbers F n for n = 0, 1, 2, ..., 20 are: 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584, 4181, 6765. The sequence can also be extended to negative index n using the re-arranged recurrence relation F n-2 = F n - F n-1 So here is a sample program to generate Fibonacci series or sequence.