O(n log n) — Linearithmic Time
DSA · Big-O Notationsyntax
Typical of efficient comparison-based sorts. You divide (log n levels) and do O(n) work per level.example
// JavaScript
// Merge sort achieves O(n log n) guaranteed
const sorted = [5, 2, 8, 1, 9].sort((a, b) => a - b);
// Built-in sort: V8 uses TimSort → O(n log n)
# Python
# Python's sorted() uses TimSort → O(n log n)
result = sorted([5, 2, 8, 1, 9])
# list.sort() is in-place, also O(n log n)output
Time: O(n log n) | Space: O(n) for merge sort, O(log n) for quicksort avgNote O(n log n) is the theoretical lower bound for comparison-based sorting. If an interviewer asks you to do better, the input must have special structure (e.g., bounded integers for counting sort). Heap operations on n elements also yield O(n log n).