Beyond It Works
An algorithm is a finite, well-defined sequence of steps solving a problem. Correctness and efficiency decide its true worth.
| Quality | Definition | Why It Matters |
|---|---|---|
| Correctness | Right output for every valid input | Essential; wrong answers are useless |
| Efficiency | Growth of time/space via Big-O | Determines scale limits |
| Clarity | Readability and simplicity | Prevents implementation bugs |
An algorithm must be finite (it terminates) and definite (unambiguous steps).
We write in pseudocode to reason precisely without language syntax distractions.
Correctness First
A common pitfall is optimizing for speed before establishing correctness. A fast algorithm giving wrong answers is worthless; a correct-but-slow one at least works.
The Golden Rule: Get it right first, argue or prove why every edge case is handled, and only then make it efficient.
Premature optimization of an incorrect method wastes effort on the wrong thing. Always prioritize a verifiable solution over a clever, obscure one.