Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between inbuilt qsort function and stable sort function?

From various sources cited I know that in-built C function, stable_sort is stable but qsort is unstable. If that is the case why do we use qsort at all? Isn't it redundant? Why not use stable_sort instead?

like image 722
markroxor Avatar asked Dec 05 '22 02:12

markroxor


1 Answers

A stable sort means that the order of equal elements is preserved. This is not always required.

If it is not required, the algorithm is simpler, and sometimes faster and/or more memory-efficient.
A typical example of a stable sort algorithm is merge sort.

like image 115
alain Avatar answered Feb 15 '23 08:02

alain