JavaScript V8 : Sorting Algorithm behind the scene for Array.sort()
Recently I was scratching my head with sorting algorithms and their implementation in JavaScript.
Suddenly things came to my mind,
- How is built-in sort() method is executing?
- What is the implementation approach?
- What sorting algorithm they are using behind the scene?
To get answers, I went through the actual code available on github for V8 JavaScript's array.js. Here is the link
Bingo, here is the answer:
- It have combination of InsertionSort and QuickSort.
- It goes for InsertionSort if the array length is short (length <= 10) otherwise QuickSort takes you to the party :)
Thanks Dan, for sharing the link
Hmmm...but there are many versions of quicksort. I'll take a look at the code and see how modern it is.
Good stuff!!