DEV Community

Discussion on: Sorting Algorithms with Javascript (Part 1)

Collapse
 
gragoon profile image
Adrian Vaucoret

Hello guy ! Nice post !

What is the faster sort algorithm ? Is it depends of number of elements ?

Collapse
 
wangonya profile image
Kelvin Wangonya

Thanks for reading!

In this case, Merge sort is the faster of the three with time complexity O(nlogn). Time complexity (the estimated time taken by running an algorithm) is measured by how many operations are executed so yes, the number of elements will matter, but not as much as the order of the elements:

  • Worst-case time complexity (input elements in reversed order)
  • Best-case time complexity (already sorted)
  • Average-case time complexity (elements in random order)