Hardware FixRecommendedDevice not working? Your driver may be the problemCheck updates for common hardware issues.Fix DriversOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsClean PCRecommendedOne scan can reveal what keeps slowing WindowsLook for cleanup and repair opportunities.Run Scan×
Skip to content
World desk6 min

Logarithms vs Exponentials: The Simple Idea Behind O(log n) and O(2ⁿ)

O(log n) grows by one step each time the input doubles; O(2ⁿ) doubles the work with each extra item. Here is why binary search and subset enumeration produce these patterns, and where Big-O stops being useful.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

The short answer: O(log n) means the work grows by one more step each time the input size doubles, while O(2ⁿ) means that each extra input item doubles the work. The first pattern usually comes from repeatedly cutting the problem in half. The second usually comes from trying every possible combination of the inputs. The difference is large: a logarithmic method barely notices a million-item input, while an exponential method with the same input size can be hopeless.

First, decide what n measures

Big-O notation is written in terms of n, and n has to mean something specific before the expression says anything useful. In most beginner examples, n is the number of entries in a list, the number of nodes in a graph, or the number of items in a set. An analysis should also name the operation being counted, such as a comparison between two values, because the count of those operations is what the notation describes.

As an Amazon Associate I earn from qualifying purchases.

Time complexity describes how the amount of work changes as n grows. It is often stated for the worst case, meaning the most work the algorithm could need for an input of size n, although average-case and best-case analyses also exist. Big-O gives an upper bound on growth that hides constant factors and lower-order terms. It is not a prediction of seconds on a particular computer. Stanford’s CS106B lecture notes on Big-O make this point directly, and Boston University’s CS112 lecture notes walk through how to count operations to arrive at a time-complexity expression.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

What a logarithm means in this context

A logarithm answers the question “how many times must I do something before I get down to the starting point?” The base-2 logarithm, written log₂(n), counts how many times 2 must be multiplied by itself to reach n. Equivalently, it counts how many times n can be divided by 2 before the result drops to about 1.

For example, log₂(8) = 3, because 2 × 2 × 2 = 8. Start with 8 items, cut them in half to get 4, cut again to get 2, and cut once more to get 1. That is three halvings. Doubling the starting size from 8 to 16 adds exactly one more halving, which is the core reason logarithmic growth is so slow.

In Big-O, the base is dropped. log₂(n), log₁₀(n), and ln(n) differ only by a constant factor, and Big-O ignores constant factors. So O(log n) is the standard way to write all of them.

Where O(log n) comes from: repeated halving

The most common logarithmic pattern in introductory courses is binary search. It works on a sorted list, and the sorted order is essential. If the list is not sorted, checking the middle element tells you nothing about which half could contain the target, so the halving step is invalid.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

How binary search halves the search space

  1. Start with the whole sorted list and set a left boundary and a right boundary that enclose every candidate position.
  2. Compute the middle position and compare the target with the element stored there.
  3. If the target matches, stop. If the target is smaller, discard the right half, including the middle. If the target is larger, discard the left half, including the middle.
  4. Repeat on the remaining half until the target is found or the remaining range is empty.

Each comparison removes about half of the remaining candidates. Because the range is cut in half every time, the number of comparisons needed in the worst case grows roughly as log₂(n). A sorted list of 1,000,000 entries needs on the order of 20 comparisons in the worst case, not a million. Stanford and Boston University both use this halving argument to explain why binary search is O(log n).

A plain linear scan of the same list has no such shortcut. It may need to check every entry, so its worst case is O(n). Sorting the data first has a cost of its own, which is why the comparison is only fair when the sorted list is searched many times.

Where O(2ⁿ) comes from: trying every combination

Exponential growth appears when an algorithm must consider every possible combination of its inputs. The classic example is listing every subset of a set. A subset is made by deciding, for each item, whether to include it or leave it out. Since each item has two independent choices, a set of n items has 2ⁿ subsets.

Stanford’s CS106B example uses a set of three items, which has eight subsets. Written out for the set {a, b, c}, they are: the empty set, {a}, {b}, {c}, {a, b}, {a, c}, {b, c}, and {a, b, c}. Adding a fourth item does not add four subsets; it doubles the list from eight to sixteen.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

An algorithm that checks every subset to find one with a property, such as a subset that sums to a target value, does work proportional to the number of subsets. That is why such brute-force searches are usually described as O(2ⁿ).

Comparing the two growth patterns side by side

The table below uses the arithmetic of the two formulas directly. It shows how many halvings are needed to reduce n to 1, and how many subsets exist for n items. These are counts of the formulas, not measured running times.

Rank #4
Sale
Discrete Mathematics with Applications
  • brand new, sealed, online access card
Input size n Halvings to reach 1 (log₂ n) Subsets of n items (2ⁿ)
3 about 1.6 8
8 3 256
16 4 65,536
32 5 4,294,967,296
1,024 10 roughly 1.8 × 10³⁰⁸

Two comparisons follow from the table. Going from n = 8 to n = 16 adds one halving but multiplies the subsets by 256. And for the subset count, doubling n does not double the work; it squares the count, because 2^(2n) equals (2ⁿ)².

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

What Big-O does and does not tell you

Big-O is useful for asking how an approach will scale when inputs become very large. It is not a complete answer to practical performance questions. The following points matter when you apply it.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  • It ignores constants. An O(log n) algorithm with a large constant can be slower than an O(n) algorithm on small inputs. Big-O only says what happens as n becomes large.
  • It depends on the operation counted. A count of comparisons and a count of memory accesses can lead to different expressions for the same code.
  • It is not an exact runtime. Hardware, language, caching, and implementation details change the seconds, while the growth shape stays the same.
  • Same bound does not mean same speed. Two O(n log n) sorting algorithms can differ considerably in real-world performance.
  • Exponential does not mean impossible. An O(2ⁿ) method can be practical for small n, such as a dozen items, and impractical for a few hundred. Whether it is feasible depends on the constants, the available resources, and the input sizes you actually face.

Keep one distinction clear. The functions log n and 2ⁿ are mathematical functions. The Big-O label on an algorithm comes from analyzing that algorithm’s steps and assumptions. Binary search is logarithmic because of its halving steps and its sorted-input requirement. A different algorithm that happens to involve logarithms in its description is not automatically logarithmic in time.

A practical way to read a complexity expression

When you see a complexity expression, ask three questions. What is n? What operation is being counted? Does the analysis describe the worst case, and what preconditions does it require? For binary search, the answers are: the number of list entries, comparisons, worst case, and a sorted list. For subset enumeration, they are: the number of items, subsets generated, and no precondition beyond having a finite set. Answering these before reading the notation prevents most misunderstandings of what O(log n) and O(2ⁿ) actually promise.

For further reading on the formal definitions, OpenStax’s introductory computer science text covers formal properties of algorithms at openstax.org, including its illustrative execution-time table. That table comes from a third-party tutorial and shows example values, not measurements of a specific implementation, so treat it as a teaching illustration rather than benchmark data.

Quick Recap

“

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
PC Slower Than It Used to Be?Free scan - under a minute
Crashes, No Sound, or Screen Glitches?Free driver scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.