QuickSort Algorithm in Javascript

So I was reading algorithms and was working on implementation of quick-sort in javascript, since this the language I’m totally love in. This is a great algorithm for sorting compared to insertion sort since it takes O(nlogn) processing time over O(n2) for insertion sort.

So if you are too concerned about performance of your sort function or if your web application needs to perform sorting on large data sets then this is the sorting that you should definitely use, Since directly using javascript’s array.sort() will implement merge-sort subroutine. Even though both merge-sort and quicksort consume the same time i.e their time is O(nlogn) but merge-sort creates new sub arrays and this will consume more memory. And since javascript runs in a single thread and if your dataset is really really huge, the tab/window may hang for some while or may end up dead.

Here is a Gist of the implementation. https://gist.github.com/vaibhavtolia/6747303

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s