Big-O of log versus square root
Data Structures & Algorithms practice on Codemia
Step through 300 algorithm problems with animated visualisers that show the data structure changing as the code runs.
Introduction
In the realm of computer science, algorithm efficiency is a topic of critical importance. At the core of this discussion lies the Big-O notation, which provides a formal definition to express how the running time or space requirements for an algorithm grow relative to the input size. Among the various complexities described using Big-O, the logarithmic and square root complexities offer unique perspectives on algorithm performance.
This article explores the intricacies of logarithmic complexity, expressed as , and square root complexity, expressed as , providing a detailed comparison, examples, and technical explanations.
Logarithmic Complexity:
Definition
The notation describes a logarithmic complexity, where n
is the size of the input. It indicates that as the input size grows, the running time increases logarithmically. This type of complexity often occurs in algorithms that progressively reduce the size of a problem by a constant factor at each step—essentially cutting down the problem size by half with each iteration.
Examples
- Binary Search: One of the classic examples of complexity is the binary search algorithm. By repeatedly dividing the search interval in half, binary search is able to find an element in a sorted array efficiently.
• Efficient on large datasets.
• Characterized by operations that halve the remaining work.
• Provides a significant performance advantage as n
grows compared to linear or polynomial complexities.
• Often emerges in problems with a spatial or geometric context.
• Shows better performance than linear complexity but less efficient than logarithmic complexity for large n
.
• Useful when input size is restricted due to inherent physical or logical limitations.
• Growth Rate: Logarithmic complexity grows significantly slower than square root complexity. As n
becomes very large, is generally more efficient.
• Algorithm Type: is usually found in divide-and-conquer strategies, while often involves algorithmic operations on number sets or geometric properties.
• Application Domain: Logarithmic complexities are common in search algorithms and data structures, whereas square root complexities often appear in mathematical and geometric computations.
Related reading
- Big-O summary for Java Collections Framework implementations?
- Big-oh vs big-theta
- Big O - Ologn code example
- Big O complexity of the basic arithmetic operations
- Big O for worst-case running time and Ω is for the best-case, but why is Ω used in worst case sometimes?
- Big O, how do you calculate/approximate it?
- Big O, how do you calculate/approximate it?
- Big O notation Log Base 2 or Log Base 10

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.