On log log n time complexity
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 O(n log log n) Time Complexity
In the study of algorithmic efficiency, time complexity is a critical concept that allows computer scientists to assess how the time to run an algorithm grows with the input size. While commonly encountered complexities include , , and , the less common complexity is fascinating and arises in some specific algorithms, particularly in number theory and sorting. This detailed examination will break down complexity, offering examples and context for its occurrence.
Breakdown of O(n log log n) Time Complexity
The complexity indicates that the running time of an algorithm increases linearly with respect to the input size , with an additional factor. This kind of growth is slower than but faster than . Understanding this complexity requires a deeper look at the double logarithmic function, .
The Double Logarithm Function
The function grows extremely slowly. To understand this, consider that:
- For , , and .
- For , , and .
Even for large , the double logarithm remains relatively small, showcasing its slow growth rate.
Practical Occurrences of O(n log log n)
Example 1: Sieve of Eratosthenes
One well-known instance of time complexity can be found in the Sieve of Eratosthenes for finding all prime numbers up to a given number . The algorithm involves iteratively marking the multiples of each prime number starting from 2.
The complexity arises as follows:
- The outer loop runs over all numbers up to .
- The inner loop marks the multiples of the found primes.
A detailed analysis using the properties of harmonic numbers reveals that the work done is proportional to .
Example 2: Certain Sorting Algorithms
In some sorting algorithms designed for special cases or specific data structures, the time complexity can reach . For instance, integer sorting algorithms like Radix Sort
or Counting Sort
achieve this complexity under certain conditions, such as when the range of numbers to sort is known and bounded.
Comparison with Other Time Complexities
To better understand the relative efficiency of , the following table summarizes it in comparison with other common complexities.
| Complexity | Typical Scenarios/Algorithms | Growth Rate |
| Constant-time lookup operations | Constant, unaffected by | |
| Binary search | Very slow growth | |
| Linear search | Directly proportional to | |
| Merge sort, Quick sort average-case | Faster than linear but feasible for moderate | |
| Sieve of Eratosthenes, special integer sorts | Very slow compared to | |
| Bubble sort, insertion sort worst-case | Quadratic growth unsustainable for large |
Additional Considerations
Understanding complexity not only involves recognizing where it occurs but also appreciating its implications on algorithm design and performance. In practice:
- Algorithms with this time complexity are generally efficient for large-scale problems.
- The choice of data structure can significantly impact achieving or optimizing such complexity.
Conclusion
While not as widely encountered as common complexities like or , time complexity represents an elegant intersection of theoretical computer science and practical algorithm design. This complexity provides an efficient solution for specific algorithmic problems in fields such as number theory and specialized sorting tasks. Understanding and leveraging this uncommon complexity can lead to improved performance in targeted applications, particularly where traditional complexities become computationally expensive.
Related reading
- On log n vs On -- practical differences in time complexity
- On of solution to solve boggle
- On On On?
- On Xorshift random number generator algorithm
- ONLogN algorithm for the following problem
- Only expose promethues metrics once per service
- One of the solution for finding the longest palindromic substring could not be understood
- Online algorithm for calculating absolute deviation

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.