Computer Science
Intermediate

Linearithmic Time

Runtime of efficient comparison sorts.

Formula

O(nlog⁡n)O(n\log n)

Variables

nInput size

Example

Merge sort, heap sort

How it works

O(n\log n) means the running time grows a little faster than linearly but much slower than quadratic time. It usually appears when an algorithm repeatedly splits a problem into smaller pieces or uses a balanced tree-like process, so each of the n items is handled across about log n levels of work. In comparison sorting, this is the best typical performance you can get without using extra information about the data, because each comparison gives only limited information and the algorithm needs enough comparisons to determine the full order.

When to use it

Use this to describe algorithms that sort or process data by repeatedly dividing it, combining subresults, or maintaining balanced structures. It is especially relevant for efficient comparison-based sorting methods and for many divide-and-conquer routines.

Worked example, step by step

Suppose an algorithm takes O(n\log_2 n) time and you want to estimate its work for n = 1,024. Step 1: Compute the logarithm: log_2(1,024) = 10, because 2^10 = 1,024. Step 2: Multiply by n: 1,024 × 10 = 10,240. Step 3: So the estimated running-time scale is 10,240 basic operations (up to a constant factor). Final answer: O(1,024\log_2 1,024) = O(10,240).

Common mistakes to avoid

  • Treating log n as a constant instead of a slowly growing factor
  • Confusing O(n\log n) with O(log n) because both involve logarithms
  • Assuming all sorting algorithms have this runtime, even though some common ones are slower

Did You Know?

The best comparison sorts run in n log n time, a limit no such algorithm can ever beat.

Share this formula

Reviewed & maintained by the FormulaWon editorial teamLast reviewed September 2026