In this tutorial, we’re going to implement insertion sort algorithm using JavaScript.

Other tutorials of this series.

Notes for this tutorial:

Task for this tutorial:

- Implement insertion sort algorithm

There are many sorting algorithm, e.g.:

- quick sort
- merge sort
- insertion sort
- bubble sort

What is an array?

- a contiguous block of allocated memory used to store a list of data
- fixed size

What is a list?

- just like array but with dynamic size

Operations of a list

1 | //initialization |

for loop

1 | const list = [1, 2, 3, 4, 5]; |

while loop

1 | const list = [1, 2, 3, 4, 5]; |

Using debugger

- Set breakpoints
- Step over
- Step into
- Examine the values of variables

Time complexity of insertion sort

- \(O(n^2)\)

The source code of the program in this tutorial on GitHub.