# Difference between time complexity and computational complexity

For measuring the complexity of an algorithm, is it time complexity, or computational complexity? What is the difference between them?

I used to calculate the maximum (worst) count of basic (most costing) operation in the algorithm.

• Not an answer to your question, but given your interest in this kind of thing, you might also be interested in cs.stackexchange.com/q/13669/755 – D.W. May 2 '15 at 1:28
• "complexity of an algorithm" when referring to asymptotic runime is a (frequently used) misnomer. You want to say "asymptotic runtime". – Raphael May 4 '15 at 18:20

Computational complexity is just a more general term, as time is not the only resource we might want to consider. The next most obvious is the space that an algorithm uses, and hence we can talk about space complexity, also as a part of computational complexity. Indeed we can do this for any measure you care you use, of course some measures are more useful than others.

So counting the number of steps that an algorithm takes in the worst case gives a time complexity bound for the problem it solves, counting how much memory/how many tape cells it uses gives a space complexity bound etc. etc.

Remember also that if you want to be strict, complexity refers to the problem, not the algorithm, so a problem has complexity bounds, an algorithm has resource bounds (running time, space use...). It's just a matter of definitional formality, complexity theory deals with problems. Yes, algorithms are a key tool for analysing problems and complexity and algorithmics are closely tied together, but formally we wouldn't say Merge-Sort (an algorithm) is in $P$, it's the problem $\mathsf{Sorting}$ which is in $P$. Merge-Sort uses certain resources ($O(n\log n)$ steps for example). The resource bound and correctness of the algorithm imply the complexity (upper) bound for the problem, but they're different things. $\mathsf{Sorting}$ is also $TC^{0}$-complete under $AC^{0}$-reductions, this complexity bound can only really be stated for a problem (but does have algorithmic implications).

• @shekharsuman By problem I mean the formal notion of a computational problem (e.g. k-Vertex Cover), not the general meaning. Computational complexity is the classification of computational problems, so in a formal sense, the complexity refers to what we can say about the problem. The results about algorithms tell us things about the complexity of problems, but are not in and of themselves complexity results (but informally we do talk about the complexity of an algorithm). – Luke Mathieson May 2 '15 at 7:55
• @shekharsuman the opening paragraph of the wikipedia page is a pretty good summary. – Luke Mathieson May 2 '15 at 8:21
• @Luke Thanks, this makes things clear. However, if I can use the idiom "most used type of complexity to formally evaluate algorithms" (Even though I know this is not precise). What would it be time vs. computational? What I think is that, in general, the most important thing is time, as resources are more extensible in some sense! – Median Hilal May 2 '15 at 9:45
• @MedianHilal time is indeed the most commonly considered measure for the complexity of a problem. Space is not too far behind (at least by complexity theorists, and people dealing with very large datasets, less so day-to-day). – Luke Mathieson May 2 '15 at 13:14

Cyclomatic complexity is often used as the measure of computational complexity a useful example is provided in https://stackoverflow.com/questions/9097987/calculation-of-cyclomatic-complexity

There may be many different (possibly nested) paths through an algorithm giving it a high cyclomatic complexity, but no loops giving it a low time complexity. A program with a single loop would have a low cyclomatic complexity but possibly a high time complexity.

Cyclomatic complexity is often used as a measure of the maintenance required for the code. A more detailed discussion is provided in http://docs.sonarqube.org/display/SONAR/Bad+Distribution+of+Complexity. This is different to time complexity that is run time measurement of the code and may be used to assess the users perception of the effectiveness of the system.