4
$\begingroup$

When I read introductory textbooks I get contradictory answers. In some cases efficiency and complexity are treated the same and the big-O notation is used to indicate that (for example) for an O(n) algorithm the time to execute is linearly proportional to the input dataset size.

From other sources I have read that efficiency is a measure of the computing resources required to execute an algorithm, but not the same as the complexity of the algorithm. So for example is it possible to have an algorithm (say to multiply two decimal numbers) that is efficient in terms of its resources (it does not need much to execute) but is complex in that as the input dataset increases in size the time to execute is O(n^2) ???

$\endgroup$
2
$\begingroup$

An algorithm is often called "efficient" if its runtime is short, compared to the inherent difficulty of the problem.

For example, you cannot sort arbitrary arrays by comparing keys in less than O (n log n). Once sorted you can lookup values in O (log n). Looking up a value in the sorted array by doing a linear search has lower complexity then sorting the array, but it is inefficient because linear search takes time O (n) and could be done in O (n log n).

$\endgroup$
1
$\begingroup$

In algorithms textbooks, efficiency and complexity are often used (loosely) as synonyms. Both are often used to refer to the running time of an algorithm. The computation time it takes to run an algorithm is a computing resource; it's often the primary resource that elementary algorithms textbooks focus on. The complexity of a problem is the minimum running time (or minimum amount of resources, more generally) needed to solve some particular problem -- so a very similar notion.

At this stage, don't get too caught up in trying to understand the precise definition of words like efficiency and complexity or trying to understand what the distinctions between them are. Odds are, the textbooks are using them in a loose sense and not trying to draw any particular distinctions between the two. Your time is probably better spent learning how to figure out the running time of an algorithm (such as the algorithm to multiply two numbers). The names you assign to concepts are often less important than understanding the concepts and techniques themselves. There are formal definitions of what is meant by "complexity" but sometimes people use complexity and efficiency in informal/imprecise ways, which might explain why what you read didn't seem 100% consistent.

See also What is the difference between an algorithm, a language and a problem?, Meaning of complexity of a computational problem, and https://en.wikipedia.org/wiki/Computational_complexity_theory.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.