# \#sorting

**URL:** https://discourse.julialang.org/tag/sorting/882.md

[Latest](https://discourse.julialang.org/latest.md) · [Categories](https://discourse.julialang.org/categories.md) · [Tags](https://discourse.julialang.org/tags.md)

---

## [\-0.0 == 0.0, but issorted(\[0.0, -0.0\]) returns false](https://discourse.julialang.org/t/0-0-0-0-but-issorted-0-0-0-0-returns-false/130966)

<div class="topic-metadata">

**Author:** [@heliosdrm](https://discourse.julialang.org/u/heliosdrm)\
**Replies:** 4\
**Last updated:** [July 23, 2025, 8:43am UTC](https://discourse.julialang.org/t/0-0-0-0-but-issorted-0-0-0-0-returns-false/130966 "2025-07-23T08:43:44Z")

</div>

There is some kind of sorting order between positive and negative zeros of float types: julia\> issorted(\[-0.0, 0.0\]) true julia\> issorted(\[0.0, -0.0\]) false But this is not observed when those numbers are compared to …

---

## [Interesting talk for the Julia sorting community](https://discourse.julialang.org/t/interesting-talk-for-the-julia-sorting-community/129385)

<div class="topic-metadata">

**Author:** [@Dan](https://discourse.julialang.org/u/Dan)\
**Replies:** 3\
**Last updated:** [May 27, 2025, 8:01pm UTC](https://discourse.julialang.org/t/interesting-talk-for-the-julia-sorting-community/129385 "2025-05-27T20:01:07Z")

</div>

Here is an interesting talk given lately: Giving details about TimSort and the new PowerSort and other interesting details. This may be for @Lilith and other people who like things to be in proper order. P…

---

## [Built-in binary search for sorted collections](https://discourse.julialang.org/t/built-in-binary-search-for-sorted-collections/128374)

<div class="topic-metadata">

**Author:** [@Leo\_I](https://discourse.julialang.org/u/Leo_I)\
**Replies:** 15\
**Last updated:** [April 28, 2025, 2:26pm UTC](https://discourse.julialang.org/t/built-in-binary-search-for-sorted-collections/128374 "2025-04-28T14:26:43Z")

</div>

Given integers N and k, I’d like to elegantly find the largest integer n for which binomial(n,k) \<= N. A way to do this is function max\_n\_binom\_leq(N::Integer, k::Integer) return maximum(n for n=k:N if binomial(big…

---

## [Another sorting algorithm](https://discourse.julialang.org/t/another-sorting-algorithm/125884)

<div class="topic-metadata">

**Author:** [@xiaodai](https://discourse.julialang.org/u/xiaodai)\
**Replies:** 1\
**Last updated:** [February 14, 2025, 10:02pm UTC](https://discourse.julialang.org/t/another-sorting-algorithm/125884 "2025-02-14T22:02:53Z")

</div>

Julia has the base sort which has massive improved and also a couple of more experimental libraries including SortingAlgorithms.jl and SortingLab.jl. I saw a sorting algorithm on Hacker News today which genuinely sounds…

---

## [Wanted: an API for merging sorted collections](https://discourse.julialang.org/t/wanted-an-api-for-merging-sorted-collections/115722)

<div class="topic-metadata">

**Author:** [@nsajko](https://discourse.julialang.org/u/nsajko)\
**Replies:** 1\
**Last updated:** [June 16, 2024, 6:57pm UTC](https://discourse.julialang.org/t/wanted-an-api-for-merging-sorted-collections/115722 "2024-06-16T18:57:56Z")

</div>

I don’t think there’s a public function for the merge algorithm anywhere in Julia or the ecosystem. It’s what merge sort is based on. Wikipedia introduces merging like this: Merge algorithms are a family of algorithms …

---

## [Sorting matrix according to the first column](https://discourse.julialang.org/t/sorting-matrix-according-to-the-first-column/112196)

<div class="topic-metadata">

**Author:** [@baprata](https://discourse.julialang.org/u/baprata)\
**Replies:** 12\
**Last updated:** [March 28, 2024, 12:43pm UTC](https://discourse.julialang.org/t/sorting-matrix-according-to-the-first-column/112196 "2024-03-28T12:43:49Z")

</div>

In the matrix below, the first, second, and third columns represent the height, area, and volume of rectangular objects, respectively. I need to sort the items in non-ascending order of height (from the highest to the lo…

---

## [Swap the two largest elements in a vector](https://discourse.julialang.org/t/swap-the-two-largest-elements-in-a-vector/108234)

<div class="topic-metadata">

**Author:** [@jcbritobr](https://discourse.julialang.org/u/jcbritobr)\
**Replies:** 13\
**Last updated:** [January 2, 2024, 7:34am UTC](https://discourse.julialang.org/t/swap-the-two-largest-elements-in-a-vector/108234 "2024-01-02T07:34:40Z")

</div>

Hello, good afternoon and Happy new Year. I would like to know how I can swap the two largest elements in a vector like \[1, 2, 3, 4, 5\]

---

## [Sort elements by frequency in julia](https://discourse.julialang.org/t/sort-elements-by-frequency-in-julia/103433)

<div class="topic-metadata">

**Author:** [@raman\_kumar](https://discourse.julialang.org/u/raman_kumar)\
**Replies:** 4\
**Last updated:** [September 5, 2023, 9:21pm UTC](https://discourse.julialang.org/t/sort-elements-by-frequency-in-julia/103433 "2023-09-05T21:21:20Z")

</div>

I want to sort elements by frequency . For example let x = \["a", "d", "d", "c", "c", "c", "f", "b", "b" ,"b", "b"\] I want to have output sorted as x = \["b", "b" ,"b", "b","c", "c", "c, "d", "d", "a", "f"\] where we ha…

---

## [Rownumber() in Dataframe like SQL](https://discourse.julialang.org/t/rownumber-in-dataframe-like-sql/72098)

<div class="topic-metadata">

**Author:** [@AlexanderChen](https://discourse.julialang.org/u/AlexanderChen)\
**Replies:** 9\
**Last updated:** [August 28, 2023, 4:21pm UTC](https://discourse.julialang.org/t/rownumber-in-dataframe-like-sql/72098 "2023-08-28T16:21:36Z")

</div>

Hi, In SQL you have a function called rownumber() over which you partition a certain column and get a column from 1 …n. Like this: dataframes has a function called rownumber but it only return an integer in specific…

---

## [What's wrong with this ordering function?](https://discourse.julialang.org/t/whats-wrong-with-this-ordering-function/103160)

<div class="topic-metadata">

**Author:** [@bertulli](https://discourse.julialang.org/u/bertulli)\
**Replies:** 5\
**Last updated:** [August 24, 2023, 3:21pm UTC](https://discourse.julialang.org/t/whats-wrong-with-this-ordering-function/103160 "2023-08-24T15:21:57Z")

</div>

Hi, I have a vector of tuples like this: julia\> results 75-element Vector{NamedTuple{(:program, :mean, :stddev, :score), Tuple{String, Float64, Float64, Float64}}}: (program = "fac\_ite\_#0", mean = 0.1477079562429519, s…

---

## [Fast permutation vector: code needed](https://discourse.julialang.org/t/fast-permutation-vector-code-needed/96357)

<div class="topic-metadata">

**Author:** [@PetrKryslUCSD](https://discourse.julialang.org/u/PetrKryslUCSD)\
**Replies:** 38\
**Last updated:** [March 21, 2023, 5:58pm UTC](https://discourse.julialang.org/t/fast-permutation-vector-code-needed/96357 "2023-03-21T17:58:57Z")

</div>

Hello all, I need to sort integer vectors, with entries of arbitrary size relative to the length of the vector. At the moment I use sort!(prm, Base.Sort.DEFAULT\_UNSTABLE, Base.Order.Perm(Base.Order.Forward, rows)) to…

---

## [Fast optimized non dominated sorting algorithms](https://discourse.julialang.org/t/fast-optimized-non-dominated-sorting-algorithms/86793)

<div class="topic-metadata">

**Author:** [@Michal\_Kvasnicka](https://discourse.julialang.org/u/Michal_Kvasnicka)\
**Replies:** 7\
**Last updated:** [September 5, 2022, 1:56pm UTC](https://discourse.julialang.org/t/fast-optimized-non-dominated-sorting-algorithms/86793 "2022-09-05T13:56:32Z")

</div>

I am looking for any Julia fast non dominated sorting (NDS) code. I just found the following thread, but algorithms here are very naive with quadratic complexity and no parallelization. Are there any more sophisticated …

---

## [Faster Alternatives to sortperm](https://discourse.julialang.org/t/faster-alternatives-to-sortperm/80170)

<div class="topic-metadata">

**Author:** [@Josa9321](https://discourse.julialang.org/u/Josa9321)\
**Replies:** 9\
**Last updated:** [May 10, 2022, 4:33pm UTC](https://discourse.julialang.org/t/faster-alternatives-to-sortperm/80170 "2022-05-10T16:33:18Z")

</div>

Hi, I am manipulating an matrix (one or more lines) that has the priority numbers of another one, for example: priority = \[0.1 0.9 0.4 0.7 0.3\] # matrix filled using rand() A = \[col1 col2 col3 col4 col5\] # matrix fille…

---

## [How to sort a vector by an expensive function in place efficiently?](https://discourse.julialang.org/t/how-to-sort-a-vector-by-an-expensive-function-in-place-efficiently/77540)

<div class="topic-metadata">

**Author:** [@taotree](https://discourse.julialang.org/u/taotree)\
**Replies:** 14\
**Last updated:** [March 8, 2022, 4:19pm UTC](https://discourse.julialang.org/t/how-to-sort-a-vector-by-an-expensive-function-in-place-efficiently/77540 "2022-03-08T16:19:20Z")

</div>

The normal sort!(...;by=f) sorts in place by a function, but it results in calling that function many more times than the length of the vector. I tried all the sorting algorithms included in Base and all of them resulted…

---

## [Dictionary values ascending or descending](https://discourse.julialang.org/t/dictionary-values-ascending-or-descending/74492)

<div class="topic-metadata">

**Author:** [@AlexanderChen](https://discourse.julialang.org/u/AlexanderChen)\
**Replies:** 4\
**Last updated:** [January 12, 2022, 3:12pm UTC](https://discourse.julialang.org/t/dictionary-values-ascending-or-descending/74492 "2022-01-12T15:12:27Z")

</div>

Hi, I have a dictionary of characters and their frequency in a text(or word): 'H' =\> 1 'l' =\> 2 'e' =\> 1 'o' =\> 1 and I want to order it by value so: 'H' =\> 1 'e' =\> 1 'o' =\> 1 'l' =\> 2 the order of …

---

## [Searchsortedlast performance](https://discourse.julialang.org/t/searchsortedlast-performance/72711)

<div class="topic-metadata">

**Author:** [@snowgum](https://discourse.julialang.org/u/snowgum)\
**Replies:** 43\
**Last updated:** [December 9, 2021, 9:57pm UTC](https://discourse.julialang.org/t/searchsortedlast-performance/72711 "2021-12-09T21:57:23Z")

</div>

I am trying to write a Julia port of the Weno4Interpolation python package, an algorithm based on Janett et al. (2019) to perform higher order interpolations. The code itself is not complex, but has many statements, mos…
