Merge Sort in JavaScript. Time Complexity O(nlogn)
Merge Sort is the most popular and efficient algorithm after quick sort that uses divide and conquer algorithm.
We split arr into two sub arrays using splice function recursively and we start merging them when the sub array reaches to the length 1 array.
The key difference in this implementation from other common implementation is the usage of iterators, … es6 spread operators.
Time complexity is O(nlogn). To explain why, I’ll show you visual demonstration.
Each level includes cn operations. And there are logn levels. For example, log base 2 of n, because of the nature of splitting into two in merge sort algorithm.
Hope this helps!
For more programming tutorials in JavaScript, React, Node.js, visit SeunghunLee.net
Thanks