Check if a sorting algorithm is stable

Say I want to know if the default float sorting algorithm is stable. How can I check?

julia> Base.Sort.defalg(rand(3))
Base.Sort.MissingOptimization(
    Base.Sort.BoolOptimization(
        Base.Sort.Small{10}(
            Base.Sort.InsertionSortAlg(),
            Base.Sort.IEEEFloatOptimization(
                Base.Sort.IsUIntMappable(
                    Base.Sort.Small{40}(
                        Base.Sort.InsertionSortAlg(),
                        Base.Sort.CheckSorted(
                            Base.Sort.ComputeExtrema(
                                Base.Sort.ConsiderCountingSort(
                                    Base.Sort.CountingSort(),
                                    Base.Sort.ConsiderRadixSort(
                                        Base.Sort.RadixSort(),
                                        Base.Sort.Small{80}(
                                            Base.Sort.InsertionSortAlg(),
                                            Base.Sort.ScratchQuickSort(missing, missing,
                                                Base.Sort.InsertionSortAlg()))))))),
                    Base.Sort.StableCheckSorted(
                        Base.Sort.ScratchQuickSort(missing, missing,
                            Base.Sort.InsertionSortAlg())))))))

According to the sort docstring, “QuickSort is used by default for numeric arrays”. According to the QuickSort docstring, it is not stable. Does that answer your question?

1 Like