loading...

What time and space complexity of JavaScript Built-In Sort method?

edisonnpebojot profile image Edison Pebojot(👨‍💻) Updated on ・1 min read

While I can't find an accurate answer even on Google search and even on Quora[See on Quora] (🙄):

Alt Text

Every clear description of the time and space complexity of the JavaScript Built-In approach must at least be closely related to the fundamental algorithm theory. TIA! (😭😀👍)

Discussion

pic
Editor guide
 

That Quora reply is correct: it depends on the implementation.

But the most common JavaScript engine (V8), which is used in Chromium browsers as well as Node.js, uses an algorithm known as Timsort, which has a worst-case time performance of O(n log n) and worst-case space complexity of O(n). You can find a great but technical write-up here.

 

Thank you very much!