CS Thinking · Computational Thinking · Grade 9-12 · 5 min read

Algorithm Efficiency

⚡ In one breath

Algorithm efficiency, captured by Big-O notation, describes how an algorithm's cost grows with input size nn — written O(n)O(n), O(n2)O(n^2), O(logn)O(\\log n), and so on.

Orient

The one-line idea, why it matters, and the intuition.

Section 1

Quick Answer

Algorithm efficiency, captured by Big-O notation, describes how an algorithm's cost grows with input size nn — written O(n)O(n), O(n2)O(n^2), O(logn)O(\\log n), and so on. Big-O gives the upper bound on growth: an algorithm is O(f(n))O(f(n)) if its running time T(n)leqccdotf(n)T(n) \\leq c\\cdot f(n) for large nn. Recognize an efficiency question when you are asked how time or memory scales as nn grows, not how one fixed run behaves (scanning a list once is O(n)O(n); comparing every pair is O(n2)O(n^2)). The nearest confusions are Time Complexity (growth of time only), Space Complexity (growth of memory), and the Algorithm itself (the steps, not their scaling), so confirm you are measuring growth-with-nn before computing a class.

Section 2

Why This Matters

Efficiency determines whether software can handle real-world data sizes. Google's search engine processes billions of queries because it uses O(logn)O(\log n) algorithms, not O(n2)O(n^2). In fields from genomics to finance, choosing the right algorithm can mean the difference between seconds and centuries of computation.

Section 3

Intuitive Explanation

Whenever an algorithm processes data, the question that matters at scale is not \"how long did this one run take?\" but \"what happens when the data gets ten times, or a million times, bigger?\" Algorithm efficiency, written in Big-O notation, is the answer: it tells you how the cost grows as the input size nn grows. Reading every name in a list once scales linearly — O(n)O(n) — so a list twice as long takes about twice as long. Comparing every pair of items scales as O(n2)O(n^2), so doubling the data roughly quadruples the work. Repeatedly halving the search space, like looking up a word in a sorted dictionary, is O(logn)O(\\log n) and barely grows even when the data is huge.\n\nThe trick to reading Big-O is that it keeps only the dominant term and throws away constants: O(2n+5)O(2n + 5) is just O(n)O(n), because for large nn the linear part is what controls the growth. Formally, an algorithm is O(f(n))O(f(n)) if there are constants cc and n0n_0 so that T(n)leqccdotf(n)T(n) \\leq c\\cdot f(n) for all ngeqn0n \\geq n_0 — an upper bound on how fast the cost can rise.\n\nThe hint that you are in efficiency territory is a question about scaling: an input you can call nn, loops or recursion that repeat based on nn, and an answer expressed as a growth class rather than a stopwatch reading. This is why it can decide whether software works at all: an O(n2)O(n^2) algorithm that is fine on a hundred items can take centuries on a billion, while an O(logn)O(\\log n) one stays fast — which is how a search engine answers a query over billions of pages in a fraction of a second.

Core idea

Algorithm efficiency matters increasingly as data grows—a slow algorithm on small data may fail completely on large data.

Recognize

The cues that signal this concept and how to distinguish it from look-alikes.

Section 4

When to Use

Use Algorithm Efficiency analysis when a problem gives you an algorithm or piece of code and asks how its running time or memory grows as the input size nn increases — its Big-O class. The recognition test is: \"how does the cost scale when nn doubles?\" If the answer is a growth rate like O(n)O(n), O(nlogn)O(n\\log n), or O(n2)O(n^2), you are doing efficiency analysis: count the dominant work as a function of nn and drop constants and lower-order terms. If you are only describing the steps of the procedure, that is the Algorithm itself; if you care specifically about extra memory, that is Space Complexity; if only about run time, that is Time Complexity. A single loop over the data is O(n)O(n), a nested loop is usually O(n2)O(n^2), and repeatedly halving the search space is O(logn)O(\\log n).

Pro tip

When analyzing efficiency, first identify the input size nn. Then count how many times the most-repeated operation executes as a function of nn (look for nested loops). Finally, express the growth rate using Big O, dropping constants and lower-order terms.

Section 5

How to Recognize It

Before reaching for Big-O efficiency analysis, check that you are being asked how an algorithm's cost grows with input size — not just what it does or how long one run takes.

  1. Is there an input whose size you can call nn — a list, an array, a string, a graph — and a question about how cost behaves as nn grows?

    A 'how does it scale with nn?' question is the efficiency signal. If the input size is fixed and nothing grows, you are just tracing the algorithm, not analyzing its complexity.

  2. Does the procedure contain loops or recursion that repeat based on nn?

    Counting how many times the repeated work runs as a function of nn is exactly the efficiency analysis — a single loop over the data is O(n)O(n), a loop inside a loop is usually O(n2)O(n^2).

  3. Is the answer you need a growth class like O(n)O(n), O(logn)O(\log n), or O(n2)O(n^2) rather than a specific number of milliseconds?

    Efficiency comes out as a Big-O class, not a stopwatch reading. If the answer should be an exact run time on one machine, that is benchmarking, not asymptotic complexity.

  4. Are you asked about memory used as the input grows rather than time?

    Then you are looking at Space Complexity — still an efficiency measure, but counting extra storage as a function of nn instead of operations.

  5. Did you keep a lower-order term or a constant factor in your answer, like O(2n+5)O(2n + 5)?

    Big-O drops constants and lower-order terms — O(2n+5)O(2n + 5) is just O(n)O(n). Keep only the dominant term that controls growth for large nn.

Section 6

Algorithm Efficiency vs Time Complexity vs Space Complexity vs Algorithm

Algorithm Efficiency, Time Complexity, Space Complexity, and Algorithm all describe how a procedure behaves, so they get mixed up. The deciding cue is whether you are measuring how a cost GROWS with input size nn, and whether that cost is time, memory, or just the steps themselves.

Algorithm Efficiency (Big-O)

Meaning
Use when you are asked how an algorithm's cost — time or memory — grows as the input size nn increases, expressed as a growth class.
Key test
Does the answer come out as a growth rate in nn rather than a fixed number?
Formula
O(f(n))O(f(n))
Example
Scanning a list once is O(n)O(n); comparing every pair of items is O(n2)O(n^2).

Time Complexity

Meaning
Use when you specifically count how the number of operations (running time) grows with nn — the time half of efficiency.
Key test
Are you counting operations as a function of nn, ignoring memory?
Formula
T(n)T(n)
Example
Binary search does about log2n\log_2 n comparisons, so its time complexity is O(logn)O(\log n).

Space Complexity

Meaning
Use when you count how much extra memory an algorithm needs as nn grows — the memory half of efficiency.
Key test
Is the question about storage used, not operations performed?
Formula
S(n)S(n)
Example
Copying an array into a new one uses O(n)O(n) extra space; swapping in place uses O(1)O(1).

Algorithm

Meaning
Use when you are describing the actual sequence of steps that solves a problem — the procedure itself, before any growth analysis.
Key test
Are you stating what the steps do, not how they scale?
Formula
step-by-step procedure
Example
Merge sort: split the list in half, sort each half, then merge the sorted halves.

Apply

Worked examples and the mistakes most students make.

Section 7

Formula & Notation

How to read it: Big O notation O(f(n))O(f(n)) describes the upper bound on growth rate. nn is the input size, and T(n)T(n) is the running time as a function of nn.

Section 8

Worked Examples

Example 1 — Recognize the model

Easy

Problem

A class sees this computing situation: students compare two ways to find a name in a list and explain which method uses fewer checks as the list grows. How should a student decide whether Algorithm Efficiency is the right model?

Solution

  1. Identify the target of the reasoning.

    The target might be a problem, data representation, code state, system component, user need, or stakeholder.

  2. List the process or relationship that matters.

    Algorithm Efficiency is useful when the problem asks for an algorithm explanation with input, output, invariant or rule, termination condition, and efficiency tradeoff stated.

  3. Apply the recognition test: Am I judging the steps of a method for correctness, termination, edge cases, and efficiency as inputs change?

    This separates algorithm efficiency from code implementation and one successful test.

  4. State the evidence that would prove the answer.

    A trace, test, diagram, input-output pair, or impact argument prevents a vague answer.

Answer

Use Algorithm Efficiency only if the task is asking for an algorithm explanation with input, output, invariant or rule, termination condition, and efficiency tradeoff stated and the situation passes the recognition test. Otherwise, choose the nearby model that better matches the computing structure.

Takeaway: Model choice comes before definitions. The same words can belong to different CS ideas depending on the problem structure.

Example 2 — Avoid the vocabulary trap

Standard

Problem

A student says, "This prompt contains the word algorithm, so I should use algorithm efficiency." Explain why that shortcut is risky.

Solution

  1. Treat the word as a clue, not proof.

    CS vocabulary overlaps across problem solving, programming, data, systems, design, and impact questions.

  2. Check whether the target and process match Algorithm Efficiency.

    The computing structure decides the model.

  3. Compare with Code implementation and One successful test.

    Code is one expression of an algorithm; the algorithm is the method and its behavior across inputs. Passing one test is not enough; an algorithm must work for all valid inputs and edge cases.

  4. State what the final result would mean.

    If the final result would not mean an algorithm explanation with input, output, invariant or rule, termination condition, and efficiency tradeoff stated, the model is probably wrong.

Answer

The shortcut is risky because algorithm can appear in several related CS models. The student must first show that the task answers "Am I judging the steps of a method for correctness, termination, edge cases, and efficiency as inputs change?" with yes.

Takeaway: A CS thinking concept is a reasoning tool, not just a vocabulary match.

Example 3 — Write the computing conclusion

Application

Problem

After solving a Algorithm Efficiency problem, a student writes only a definition. What should be added to make the answer useful?

Solution

  1. Name the specific case.

    The answer should identify the input, data, program state, system component, user, or stakeholder being described.

  2. Show the process or evidence.

    A trace, test, example, diagram, or tradeoff explains why the concept applies.

  3. Connect the result to the goal.

    The final sentence should say how the concept helps solve, test, design, represent, protect, or evaluate the computing situation.

  4. Mention limits or edge cases.

    Computing answers are stronger when they state where the method might fail, scale poorly, exclude users, or require a different design.

Answer

A complete answer should say what algorithm efficiency controls in the specific situation, include evidence such as a trace or test, and state any condition needed for the model to apply.

Takeaway: The final explanation is part of CS thinking, not an optional sentence after the term.

Section 9

Common Mistakes

Common slip-up

Confusing Big O (upper bound) with exact running time

The right idea

Fix this by naming the input, process, output, evidence, and checking "Am I judging the steps of a method for correctness, termination, edge cases, and efficiency as inputs change?" before using the concept.

Common slip-up

Ignoring nested loops when counting operations

The right idea

Fix this by naming the input, process, output, evidence, and checking "Am I judging the steps of a method for correctness, termination, edge cases, and efficiency as inputs change?" before using the concept.

Common slip-up

Assuming a faster algorithm is always better (ignoring constant factors for small inputs)

The right idea

Fix this by naming the input, process, output, evidence, and checking "Am I judging the steps of a method for correctness, termination, edge cases, and efficiency as inputs change?" before using the concept.

Common slip-up

Using algorithm efficiency from a keyword alone

The right idea

Signal words like algorithm, search, sort only point to a possible model; the computing structure must match too.

Practice

Try it, then see where this concept fits in the path.

Section 10

Mini Practice

Try these on your own. Tap Reveal when you want to check.

  1. What clue tells you this is an efficiency question? A function loops once through an array of nn numbers and adds them up.

    Hint: Count how many times the work runs as a function of nn.

  2. Why is this a contrast case for efficiency instead of efficiency itself? You are simply asked to describe the steps of merge sort.

    Hint: Are you stating what it does, or how it scales?

  3. What is the Big-O class? A function has a loop over nn items, and inside it another loop over the same nn items, comparing every pair.

    Hint: Multiply the work of the nested loops.

  4. Simplify the growth: an algorithm performs 3n+73n + 7 operations on an input of size nn. What is its Big-O class, and why?

    Hint: Drop constants and lower-order terms.

  5. Why is this a contrast case for time efficiency? An algorithm runs in O(logn)O(\log n) time but copies the whole input into a new array of size nn.

    Hint: Ask whether the cost in question is time or memory.

  6. Binary search repeatedly halves a sorted list of nn items until it finds the target. What is its efficiency, and why does it scale so well?

    Hint: How many times can you halve nn before reaching 1?

Want the full set?

50 practice questions for this concept — free to try, every one with a complete worked solution showing the why, not just the answer.

Section 11

Frequently Asked Questions

What is algorithm efficiency, in one sentence?

Algorithm efficiency, expressed in Big-O notation, describes how an algorithm's running time or memory grows as the input size nn increases — for example O(n)O(n) means doubling the data roughly doubles the work, while O(n2)O(n^2) means it roughly quadruples. It captures scaling behavior, not the speed of any single run.

How do I recognize an algorithm-efficiency question?

Look for an input whose size you can call nn and a question about how cost behaves as nn grows — usually with loops or recursion that repeat based on nn. The recognition test is 'how does the cost scale when nn doubles?' If the answer should be a growth class like O(n)O(n) or O(logn)O(\log n) rather than a fixed run time, it is an efficiency question.

Why does Big-O drop constants and lower-order terms?

Big-O describes behavior for large nn, where the fastest-growing term dominates everything else. So O(2n+5)O(2n + 5) simplifies to O(n)O(n) and O(n2+n)O(n^2 + n) to O(n2)O(n^2) — the constant 2, the +5, and the lower-order nn stop mattering as nn gets large. Formally an algorithm is O(f(n))O(f(n)) if T(n)cf(n)T(n) \leq c\cdot f(n) for some constant cc and all large nn.

How is efficiency different from just describing the algorithm?

Describing the algorithm tells you what steps it takes — split the list, sort each half, merge. Efficiency tells you how the cost of those steps grows with input size, like O(nlogn)O(n\log n) for merge sort. Two algorithms can solve the same problem yet have very different efficiency, which is why the Big-O class, not just the steps, decides whether code works at scale.

Is there a difference between time and space efficiency?

Yes. Time complexity counts how the number of operations grows with nn; space complexity counts how much extra memory grows with nn. They can differ: an algorithm might run in O(n)O(n) time but use only O(1)O(1) extra space (working in place), or save time by spending more memory. Both are forms of algorithm efficiency.

When should I reach for a neighbor instead of full Big-O analysis?

Reach for Time Complexity when you only care about how operations scale, Space Complexity when you only care about memory growth, and the Algorithm itself when you just need to state the steps without analyzing growth. Full efficiency analysis applies when the question is specifically how cost grows with input size nn.

Section 12

Learning Path

← Before

Algorithm
Algorithm Efficiency

You are here

Before this, students should be comfortable with Algorithm. This page focuses on the recognition cue: Am I judging the steps of a method for correctness, termination, edge cases, and efficiency as inputs change? That cue connects earlier computing descriptions to later problem solving because students first choose the model, then choose the representation, code, test, diagram, or explanation. After this, Searching and Sorting become easier to recognize.

Section 13

See Also