liveBook · Manning

O(n * log n)

As explained in Clojure: The Essential Reference

O(n log n) complexity is an asymptotic growth rate in which computation increases proportionally to input size times its logarithm.

O(n log n) describes a linearithmic growth rate: sorting a collection requires work proportional to its size multiplied by its logarithm. In Clojure, sort and sort-by use this performance profile, making collection size important when processing large datasets. section 8.3.5

For sorting operations, the practical implications are:

  • Expect O(n log n) steps and O(n) memory for sort and sort-by. section 8.3.5
  • Review sorting on large datasets; around 100,000 entries, the linearithmic cost may become noticeable. section 8.3.5
  • Timsort detects ordered segments, extends short segments with insertion sort, and merges them. section 8.3.5

Sorting a collection

(sort > [18 43 3 0 9]) ;; (43 18 9 3 0) The result is descending, while the sorting work follows the O(n log n) profile. section 8.3.5

How Clojure: The Essential Reference covers it

How deep it goes
Explains steps, memory, Timsort, ordered segments, insertion sort, and merging.
Examples
Uses Clojure sort results, large-dataset guidance, chunked parallel sorting, and performance comparisons by input ordering.
What you can do after
Evaluate sorting performance and recognize when collection size makes sort or sort-by noticeably slower.
How it connects
Connects asymptotic complexity with sorting, Timsort, insertion sort, merge sort, and ordered sequences.

Also explained in

Compare how 2 books explain O(n * log n) →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Clojure: The Essential Reference. The section links point to the parts of the book it draws on.