2

Basically what the title says. take for example a simple function:

def swap(a,b)

temp = a a = b b = temp

This one is pretty easy to solve intuitively. if we consider an assignment as a single operation the time complexity T(n) = 3 for any n where n is the input size. But for more complex code e.g. one involving multiple nested loops/ different loop types it will be much harder using an informal approach.

1 Answers1

2

No, not necessarily. The undecidability of the halting problem proves there is no general algorithm that always works for all algorithms/programs.

But see Is there a system behind the magic of algorithm analysis? for a systematic approach that often works for real-world algorithms.

D.W.
  • 167,959
  • 22
  • 232
  • 500