You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

咨询Clojure内置sort函数的时间复杂度(Big-O表示法)

Clojure内置sort函数的时间复杂度

Hey there! I totally get the frustration of not finding this detail on ClojureDocs—let me fill you in.

Clojure's built-in sort function delegates to Java's sorting implementations under the hood, which means its time complexity is O(n log n) in all cases (best, average, and worst). Here's a bit more context to clarify:

  • For sequences of primitive types (like integers, floats), it uses Java's dual-pivot quicksort, which locks in an O(n log n) worst-case time complexity (a big improvement over traditional quicksort's worst-case O(n²)).
  • For sequences of objects (like Clojure maps, strings, custom types), it uses TimSort—a hybrid sorting algorithm derived from merge sort and insertion sort—also with a worst-case time complexity of O(n log n).

One extra note: Clojure's sort is a stable sort, meaning elements with equal sort keys retain their original relative order in the output.

内容的提问来源于stack exchange,提问作者TheIE100

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.20 09:03:07