2
$\begingroup$

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.

$\endgroup$

1 Answer 1

2
$\begingroup$

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.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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