9

Is there a difference between the computational complexity and computational cost of an algorithm?

Raphael
  • 72,336
  • 29
  • 179
  • 389
Josh3248
  • 103
  • 1
  • 1
  • 5

2 Answers2

8

To answer your question as stated: "computational complexity" typically refers to the $\Theta$-class of a certain (often implicit) measure of computational cost.

That said, I prefer to use the terms like this:

  • Use "complexity" when talking about problems. For instance, you can say "sorting has $\Theta(n \log n)$ worst-case time complexity (in the comparison model)".

  • Use "costs" when talking about algorithms. You would say, "Mergesort has a worst-case running-time cost in $\Theta(n \log n)$ (under the RAM model)".

This is consistent with common use, that is every expert will understand what you're saying, but avoids using the term "complexity" for different things.

Rationale

  1. Complexity theory and analysis of algorithms (AofA) are distinct fields with different goals and techniques. It's not helpful to use terminology that muddles the two together.

    Side note: teaching only the complexity-theory side of things makes large parts of the AofA literature inaccessible to computer science graduate, which I think is a shame. See the work of Flajolet and Sedgewick if you're interested in these things.

  2. "Cost", other than "complexity", is used for precise measures like, say, "the number of comparisons" often analysed in sorting. Such a cost measure is (given an algorithm and a machine model) a well-defined function on the inputs (other than "time") and can be analysed rigorously.

  3. Every algorithm has many cost measures with different asymptotic behavious; in sorting, for instance, number of comparisons, swaps, and many more. Therefore, asking for "the complexity of the algorithm" is an oversimplification, and only meaningful under certain assumptions/conventions.

  4. The analysis of cost measures can yield testable hypotheses, if it's more precise than Landau bounds. "Complexity" results are not testable.

  5. "Complexity" of an algorithm can be rigorously defined in terms of cost measures, if one so desires. The other way around does not work.

    For instance, an algorithm's "(time) complexity" is usually taken to mean the $\Theta$-class of dominant, additive cost measure that is defined by a function on basic operations. However, I consider this practice confusing and thus harmful (cf. item 1), and prefer to say "[cost measure] is in $\Theta(\_)$".

Raphael
  • 72,336
  • 29
  • 179
  • 389
  • 2
    Are you sure you can set such a clear cut distinction? Don't get me wrong, I completely agree that highlighting the difference between problems and algorithms is important, especially for beginners, but in practice we also say things like "the time-complexity of mergesort" or "the cost of sorting" and I wouldn't say that either of them is wrong, as long as one makes clear what exactly is the object of the sentence. – quicksort Nov 04 '17 at 19:31
  • @quicksort Yes, I'm very aware that common use mixes the concepts. I'm taking my stand against it. I fully expect other answers to be posted. :) – Raphael Nov 04 '17 at 19:34
  • 4
    Can you provide some reference for your claim? I have never heard of this distinction. I have also never heard anyone say a phrase like "mergesort has worst-case running time cost of.." but I am pretty sure every textbook I have opened uses the phrase "worst-case time complexity" – Sasho Nikolov Nov 05 '17 at 02:17
  • I'd second problems to not have a cost and executions of algorithms/implementations to have no "complexity" - not sure about algorithms as such. – greybeard Nov 05 '17 at 08:26
  • @SashoNikolov "Cost" is used for algorithms in the AofA community (don't have a citeable book handy, sorry) where analysis often go beyond Landau notation. "Complexity" is used instead of "cost" only when Landau notation is used, afaik. – Raphael Nov 05 '17 at 08:42
  • @quicksort I have amended and expanded my answer to clarify my position. – Raphael Nov 05 '17 at 11:48
  • 2

    "Cost", other than "complexity", is used for precise measures like, say, "the number of comparisons" often analysed in sorting, I have already said that in my post. no need to repeat. you do not say anything different from what has already been said.

    – fade2black Nov 05 '17 at 12:55
  • 1
    Edit of your post does not add anything meaningful. A lot of words, but much more confusing. – fade2black Nov 05 '17 at 12:57
  • 1
    @fade2black Every answer should stand on its own. – Bergi Nov 05 '17 at 14:25
  • @Bergi Everyone on the forum should be aware of it, I hope that's addressed not only to me. – fade2black Nov 05 '17 at 14:32
  • @Raphael +1. I stand by my original point (it's a mess, therefore clarity and making sure people understand what you're talking about is the prime concern, even at the cost of slight abuses), but your rationale for using those terms seems very solid to me. Just to be a little nitpicky, could you elaborate your point 4? Specifically, why couldn't we, at least in principle, design an experiment to verify in the statistical sense a complexity result (assuming of course we aren't talking about "not real" objects such as NDTMs)? – quicksort Nov 05 '17 at 17:06
  • 1
    @quicksort Basically, you can not reject any Landau bound with finitely many measurements. See here for some thoughts. (Recall that falsifiability, not proof, is at the center of the scientific method. So, measurements apparently fitting a curve alone doesn't support a hypothesis -- it's about whether the measurements refute (all) other curves!) – Raphael Nov 05 '17 at 17:26
  • 2
    I work in algorithms, and I do not agree that "cost" is what's used by algorithms researchers, at least not in my experience. I agree that cost is often used with concrete measures like number of comparisons or queries. – Sasho Nikolov Nov 05 '17 at 17:58
  • The first sentence of the "time complexity" wikipedia page (https://en.wikipedia.org/wiki/Time_complexity): "In computer science, the time complexity is the computational complexity that describes the amount of time it takes to run an algorithm". Please feel free to correct it ! – Optidad Jan 20 '20 at 10:17
2

My approach is as following.

Computational complexity is an abstract notion having a precise mathematical definition and a field of a whole scientific research.

"Computational cost" is alternatively used for "computational complexity", though in my opinion I would not use the term "computational cost" in the formal meaning instead of "computational complexity".

The most significant difference between "complexity" and "cost" is that the "complexity" is precise mathematical measure measured using big-O notation, we usually say "space complexity" or "time complexity" where both terms "space" or "time" are abstract, i.e., by "space" we might mean RAM or HardDisk storage, while "time" might mean milliseconds, seconds, or even hours. "Cost", on the other hand, is real-life, physical, concrete measure. For example we say "it costs 2 Gigs" or "it costs 2 TB of disc space".

Let me support my point of by example. Suppose we have come up with two different algorithms solving the same problem and we have estimated exact number of operations for both algorithms, say, $n^2 + 100n$ and $0.2n^2$. We do not need to implement both algorithms in order to conclude that their complexity are equal and are $O(n^2)$. From point of view of computational complexity these algorithms have equal efficiency. However, to measure the cost of these algorithms we need to implement them, run on a computer, and measure how much time they take (in milliseconds, seconds, minutes...). This is cost and we'll obviously get different time measures for $n^2 + 100n$ and $0.2n^2$ algorithms. Thus comparing their costs we may choose a better algorithm for practical use.

fade2black
  • 9,827
  • 2
  • 24
  • 36
  • 1
    And "cost" might include other things than just the computation time, like memory usage, hard disk usage etc. – gnasher729 Nov 04 '17 at 22:24
  • @gnasher729 Agree. My point is that by "cost" we mean usage of concrete physical resource. – fade2black Nov 04 '17 at 22:30
  • "by "cost" we mean usage of concrete physical resource" -- that is certainly not how the term is used in the AofA literature. – Raphael Nov 05 '17 at 11:44
  • "Computational complexity is an abstract notion having a precise mathematical definition" -- while it is possible to do so, most authors don't bother to do so. "Time" and "complexity" remain vague notions. Relevant parameters like, for instance, the machine model routinely remain unspecified. We have hundreds of questions this site alone which are based on confusion about these things. – Raphael Nov 05 '17 at 11:46
  • Definitly the best answer, a concrete one, thanks. Unfortunately, upvotes favor an abstract philosophical thought based on a feeling on the community usage. – Optidad Jan 20 '20 at 10:10