What type of sort does the SORT function in MATLAB perform?
53 views (last 30 days)
Show older comments
MathWorks Support Team
on 27 Jun 2009
Edited: MathWorks Support Team
on 9 Jul 2021
Could you tell me the algorithm and/or the running time of the SORT function?
I need to know which sorting algorithm is used by MATLAB when the SORT function is executed.
Accepted Answer
MathWorks Support Team
on 27 Jun 2009
Edited: MathWorks Support Team
on 6 Apr 2018
The type of sort that is done is a Quick Sort. It is not an 'adaptive sorting' algorithm, and does not deviate much from the standard Quick Sort algorithm. Quick Sort has been found to be one of the fastest algorithms for sorting; it is an O(n log n) operation. We do not have specific time information, since it depends on both the system and the numerical data used in the sort.
2 Comments
More Answers (1)
Alex
on 1 Sep 2015
Edited: MathWorks Support Team
on 9 Jul 2021
Hi MathWorks Support Team.
I wonder whether you can tell me whether the quicksort algorithm you have implemented keeps the within group ordering. Here is a link to my original question on Stack Overflow:
2 Comments
Eli4ph
on 23 Oct 2017
Also, one can check by
edit sort
There is a sentence in comment saying
% When more than one element has the same value, the order of the
% elements is preserved in the sorted result and the indices
% relating to equal elements will be ascending.
See Also
Categories
Find more on Shifting and Sorting Matrices in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!