You are not logged in. Please login at www.codechef.com to post your questions!

×

# Fastest sorting algorithm .

 2 1 Which is the fastest sorting algorithm? asked 10 Nov '16, 00:29 2★rashedcs 497●6●17●55 accept rate: 4%

12 Answers:
 5 Inbuilt function of sort available in "algorithm" header file of C/C++.. sort() are much faster than any other implemented sort!! answered 10 Nov '16, 00:44 2.8k●1●4●19 accept rate: 16%
 2 Merge Sort is the fastest stable sorting algorithm with worst-case complexity of O(nlogn), but it requires extra space. Although, if memory constraints are very tight you can use Quick Sort, whose worst-time compelxity is O($n^{2}$) but average case complexity is O(nlogn). A sorting algorithm is stable if whenever there are two records R and S with the same key, and R appears before S in the original list, then R will always appear before S in the sorted list. If you feel your question has been answered, mark it as accepted. answered 10 Nov '16, 00:44 5★srd091 1.6k●1●11 accept rate: 42%
 1 answered 10 Nov '16, 00:48 4★kay_kay 1.2k●7●21 accept rate: 20%
 4 Answer is hidden as author is suspended. Click here to view. answered 10 Nov '16, 17:22 4★pkien (suspended) accept rate: 12%
 2 This is a good link for time complexity of various algorithms and data structures. http://bigocheatsheet.com/ answered 24 Nov '16, 23:58 2.6k●1●10●34 accept rate: 7%
 1 1)Merge Sort is unarguably the fastest sorting algorithm with a worst-case complexity= O(n logn) . This means that whatever be the arrangement of the elements in the array, it won't take more than n*logn steps to sort the array. A standard computer generally takes 1 second to perform 10^8 such steps/operations. An important point to note here is that the base of the logarithm is 2 and not 10 or e as generally taken in schools. The only disadvantage of Merge Sort is that it requires extra space , i.e. an extra array to merge the sorted elements into. This is important to know because sometimes additional space has a great cost attached with it. 2)Quicksort is usually the sorting algorithm that is used everywhere. A few examples of this would be the inbuilt java, C++ sorting functions, MS Excel ,etc. Quicksort has an average worst-case complexity of O(n logn) but a worst-case complexity of O(n^2). However, this only occurs when the array is already sorted and can be overcome by randomizing the position of the pivot everytime. This is a very convenient technique since it does not have the additional cost of an entire new array. answered 25 Nov '16, 00:27 865●2●14 accept rate: 10%
 4 For competitive programming purposes, the standard library sort() should do just fine. In C++ it is an implementation of introsort. Mergesort is often not a great candidate because of all the extra memory used. On a side note, there is a sorting algorithm, block sort, that: Uses O(1) extra memory Is stable Runs in O(N log N) in worst case Runs in O(N) in best case answered 25 Nov '16, 18:05 0★wefgef 702●4 accept rate: 14%
 1 I use sorted().This is built-in in Python and is over 4 times faster than other sorting techniques. answered 26 Nov '16, 11:15 26●2 accept rate: 25% I think that a.sort() and sorted(a) have the same time complexity. Both use Tim Sort and I don't it's like 4 times faster or anything like that but it has a best case time complexity of O(n). (26 Nov '16, 11:44)
 0 in java Arrays.sort(arr_name); answered 26 Nov '16, 18:07 1★app_geek 1 accept rate: 0%
 1 Well there's no de facto 'fastest sorting algorithm (Else there'd be just one sorting algorithm and everybody would've used that). It all depends on how the input data is. If the array is nearly sorted, then Insertion sort, Selection sort would be the algorithm of my choice. If I already know the input elements range, eg. If I want to sort 1 billion characters, I know there're just 26 unique elements, I'd go with Counting sort If I'm sorting objects, I want the sort to be stable. I'd use Java's Collections.sort() which internally uses Tim Sort If I'm just sorting random numbers of which I have no data about(eg. range), I'd use Java's Arrays.sort() which uses Double Pivoted Quick sort answered 26 Nov '16, 19:32 31●2 accept rate: 0%
 0 fastest sorting algorithm will be the merge sort.since the time complexity is less even in the worst case(nlogn).Even if the array is properly arranged or not,it wouldn't take more than nlogn steps to sort the array. answered 26 Nov '16, 20:15 0★sanah 1 accept rate: 0%
 0 C++ STL sort function is fastest. If you want your own implementation then randomized quick sort and heap sort are really good candidates as they are universal unlike radix sort which is O(n) but demands keys in lexicographic order. Thus, overall inbuilt sort functions are quite fast and are thus widely used answered 24 Feb '17, 12:48 453●7 accept rate: 10% Dear, don't take it in wrong way, but the Q was asked last year, and already answered. Even what you said about C++ stl is what bansal said in his accepted answer. I know you want to help, but I don't think bumping these 3-4 month old thread would be that helpful (many OPs wont be around now, or even they are ,chances are they might have already found the answers). Just take care that you don't bump to the extent that threads more closer to current affairs get neglected. I hope I put my point across amicably. (24 Feb '17, 14:55) I totally agree with you mate. Thanks (24 Feb '17, 15:02)
 toggle preview community wiki:
Preview

### Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

• *italic* or _italic_
• **bold** or __bold__
• link:[text](http://url.com/ "title")
• image?![alt text](/path/img.jpg "title")
• numbered list: 1. Foo 2. Bar
• to add a line break simply add two spaces to where you would like the new line to be.
• basic HTML tags are also supported
• mathemetical formulas in Latex between \$ symbol

Question tags:

×846

question asked: 10 Nov '16, 00:29

question was seen: 31,844 times

last updated: 24 Feb '17, 15:02