craftygrammarian asked: If I understand what you're saying, what if you took all of the operations done by each line, and made them into binary operations (i.e. x = 2y+3; ==> t=2*y;x=t+3, etc.), assigned each one relative weights, and then summed them? as in, for(i=0, i<n; i++){j++} is maybe weight(i=0)+weight(i<n)+weight(i++)+weight(j++). So your measure is somewhat absolute, irrespective of the value of n, but can be weighted to reflect that a[i] = $string.hash(); could be more complex of a call than i++;
Yes, that will work. However, even restricting yourself to basic imperative language structures that translate into binary commands, there is still more than one way to write an algorithm, and often they will result in different scores.
However, it should work for the purposes of the question. The basic point that I had in mind was that an algorithm would run faster if it has more specializations, heuristics and conditions in general that assume something (but still allow for the algorithm to run OK if the assumption is wrong).
In the end, it boils down to: whether general purpose algorithms are smaller in terms of their complexity (which I assume to be true, although am not familiar with any theory that states so (I’m still in high school and never studied CS)), and, whether more specialized algorithms are faster.
Good examples of what I think to be “general-purpose algorithms” are brute force and evolutionary algorithms. Both can be, in fairly unmodified form, applied to a problem, almost without any purpose-specific modifications. They’re usually slow and simple. However, if a human designs an algorithm specifically for the purpose, it would be more complex in terms of it’s instruction set and it would execute faster.
Evolutionary/natural algorithms might at first, seem like an exception, since I have read about them being applied to problems which are difficult to solve with a specifically designed algorithm.