What Makes a Good Algorithm? Characteristics and How to Judge One

A good algorithm is one that is correct for every valid input, uses as little time and memory as the problem allows, and can be read and maintained by someone else. Correctness comes first, because a fast wrong answer is worthless. Efficiency comes second and is measured with Big O notation. Readability comes third and decides whether the algorithm can be maintained in a real codebase. Everything else, such as robustness and generality, refines those three.

Characteristics of an Algorithm vs Characteristics of a Good One

Two different lists share these words, and exam questions mix them up. The characteristics of an algorithm are the five conditions any procedure must meet to count as an algorithm at all. The characteristics of a good algorithm are the quality criteria used to compare two algorithms that both qualify.

Characteristics of an algorithm (must have)Characteristics of a good algorithm (quality)
Input: zero or more valuesCorrectness on all valid inputs
Output: at least one valueLow time complexity
Definiteness: each step is exactLow space complexity
Finiteness: it stopsReadability and simplicity
Effectiveness: each step is basicRobustness on edge cases, and generality

If a question asks for "characteristics of algorithm in data structure", give the left column. If it asks "what makes a good algorithm", give the right column.

Correctness

Correct means the right output for every valid input, not only the usual input. The test cases that break algorithms are the edges: an empty list, one element, duplicates, negative numbers, the largest allowed size. A sorting algorithm that fails on an already sorted list is not correct. Correctness is checked by reasoning about the invariant, the fact that stays true on every pass of a loop, and then by tests that target the edges.

Time Complexity

Time complexity states how running time grows as the input grows. It is written in Big O notation, which keeps only the fastest-growing term. The table below is the scale a reviewer uses.

ComplexityNameExampleRough limit for n in one second
O(1)ConstantHash table lookupAny
O(log n)LogarithmicBinary searchAny
O(n)LinearOne pass over an arrayAbout 100 million
O(n log n)LinearithmicMerge sortAbout 10 million
O(n^2)QuadraticNested loop over pairsAbout 10,000
O(2^n)ExponentialTrying every subsetAbout 25

A good algorithm is the one lowest on this table that still solves the problem. Moving from O(n^2) to O(n log n) is what most interview follow-up questions are asking for.

Space Complexity

Space complexity states how much extra memory the algorithm uses beyond the input. Merge sort needs O(n) extra space for its temporary arrays. Heap sort sorts in place with O(1) extra space. Recursion counts too: a recursive depth-first search uses O(h) stack space for a tree of height h. When two algorithms have the same time complexity, the one with lower space complexity is usually the better one.

Readability

Readable means another engineer can follow it without asking you. Clear names, one job per function, and no clever tricks that save two lines. A slightly slower algorithm that everyone understands often beats a faster one nobody wants to change. In an interview, readability is also what lets the interviewer follow your reasoning.

Robustness and Generality

A robust algorithm handles bad input without crashing: it checks for null, empty, and out-of-range values and returns a defined result. A general algorithm solves a family of problems, not one instance. Binary search is general because it works on any sorted array with any comparable elements.

A Worked Comparison

The task: report whether a list of n integers contains a duplicate.

def has_duplicate_slow(values): for i in range(len(values)): for j in range(i + 1, len(values)): if values[i] == values[j]: return True return False def has_duplicate_fast(values): seen = set() for value in values: if value in seen: return True seen.add(value) return False

Both are correct. The first is O(n^2) time and O(1) space. The second is O(n) time and O(n) space. For 100,000 values the first does about 5 billion comparisons and the second about 100,000. The second is the good algorithm for any list larger than a few dozen items, and it is also easier to read. That is the usual outcome: the better structure gives both speed and clarity.

Key Takeaways

TAGS
Coding Interview
CONTRIBUTOR
Arslan Ahmad
Arslan Ahmad
ex-FAANG engineering manager and author or Grokking series.

GET YOUR FREE

Coding Questions Catalog

Design Gurus Newsletter - Latest from our Blog
Boost your coding skills with our essential coding questions catalog.
Take a step towards a better tech career now!
Explore Answers
Which type of interview is best?
Who is eligible for Pinterest?
Is it worth it to buy LeetCode Premium?
What does IDE stand for?
Can you use LeetCode on mobile?
What is portfolio and example?
Related Courses
New
Grokking the AI System Design Interview course cover
Grokking the AI System Design Interview
Learn to design AI systems the way interviewers expect: classic ML products, LLM and RAG architectures, and agentic systems, all through the lens of the system design interview.
4.6
(3,192 learners)
Discounted price for Your Region

$99

Grokking the Coding Interview: Patterns for Coding Questions course cover
Grokking the Coding Interview: Patterns for Coding Questions
The 24 essential patterns behind every coding interview question. Available in Java, Python, JavaScript, C++, C#, and Go. The most comprehensive coding interview course with 543 lessons. A smarter alternative to grinding LeetCode.
4.6
Discounted price for Your Region

$197

Grokking Modern AI Fundamentals course cover
Grokking Modern AI Fundamentals
Master the fundamentals of AI today to lead the tech revolution of tomorrow.
4.1
Discounted price for Your Region

$72

Design Gurus logo
One-Stop Portal For Tech Interviews.
Copyright © 2026 Design Gurus, LLC. All rights reserved.