n log n is On?
Data Structures & Algorithms practice on Codemia
Step through 300 algorithm problems with animated visualisers that show the data structure changing as the code runs.
Understanding algorithmic complexity is crucial for computer science and software development, especially when it comes to sorting operations, data structures, and other performance-critical tasks. Within this context, it's common to encounter complexity expressions like and . This article will delve into why is considered but not , exploring its meaning, implications, and applications.
Asymptotic Notation
Asymptotic notation provides a way to describe the efficiency and performance of an algorithm in terms of its time or space complexity, particularly as the input size grows indefinitely. The three most frequently used asymptotic notations are:
- Big O (-notation): Provides an upper bound on the time complexity, indicating the worst-case scenario.
- Big Omega (-notation): Offers a lower bound, showing the best-case scenario.
- Big Theta (-notation): Describes a tight bound, representing the average or expected scenario.
Big O Notation:
Big O notation, , provides an upper bound for the growth rate of a function. If is the time complexity of an algorithm, then is if there exist constants and such that for all , .
Understanding
The term is frequently encountered in algorithms such as Merge Sort, Quick Sort, and Heap Sort, which have average-case time complexities of . Here, the function often refers to , the binary logarithm, which is common in computer science contexts where binary data is processed.
Why is Not
To understand why is not , consider the relationship between these two functions:
- Growth Rate: The growth rate of is faster than for large values of . While grows very slowly compared to linear or polynomial functions, when multiplied by , the combined function grows more quickly than .
- Proof by Contradiction: Let's attempt to prove that is . It implies there exist constants and such that for all , . Simplifying, we get . Since grows indefinitely as increases, no such constant can exist, thus proving is not .
n log n in the Hierarchy of Functions
To visualize this, consider the following hierarchy of growth rates:
- Constant:
- Logarithmic:
- Linear:
- Linearithmic:
- Quadratic:
- Cubic:
- Exponential:
Practical Example
Consider a Merge Sort algorithm, which efficiently sorts an array of elements. The algorithm divides the array in half, sorts each half recursively, and then merges the sorted halves. This divide-and-conquer approach has a time complexity of . While it is significantly better than algorithms like Bubble Sort for large , it is still not as efficient as linear time algorithms like Counting Sort, which are feasible when certain conditions are met.
Summary Table
| Function | Description | Growth Relative to |
| Constant time | Same | |
| Logarithmic time | Slower | |
| Linear time | Baseline | |
| Linearithmic time | Faster | |
| Quadratic time | Much Faster |
Conclusion
While often appears in algorithm analysis as a desirable and efficient time complexity, particularly in sorting and other divide-and-conquer algorithms, it is strictly not . Understanding these distinctions allows developers to make informed choices about algorithm selection and performance optimization. Recognizing that grows more rapidly than linear time but less so than quadratic time helps calibrate expectations about algorithm performance, especially with large data sets.
Related reading
- n steps with 1, 2 or 3 steps taken. How many ways to get to the top?
- nᵗʰ ugly number
- Naive Bayes Imbalanced Test Dataset
- Naive Bayes without Naive assumption
- name of algorithm related to load balancing / re-distribution
- Native JavaScript sort performing slower than implemented mergesort and quicksort
- Names of Graph Traversal Algorithms
- Natural Sorting algorithm

DSA Fundamentals
Master algorithmic patterns and data structures through hands-on LeetCode-style problems - from arrays and hashing to dynamic programming and advanced graphs.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
Data Structures & Algorithms practice on Codemia
Step through 300 algorithm problems with animated visualisers that show the data structure changing as the code runs.