complexity of code

前端 未结 6 1235
借酒劲吻你
借酒劲吻你 2021-01-14 07:33

what is the complexity of a program having only one loop, is it log n? can someone give me some ideas about estimating complexity of codes?

6条回答
  •  天涯浪人
    2021-01-14 08:12

    Software Complexity

    There is a field of study that attempts to quantify exactly that.

    It's called cyclomatic complexity.

    In this case, I believe your complexity rating would be p = 2, because the loop is conditional and that means there are two paths through the method.

    Time complexity

    If you are referring to time complexity, it's still just O(1) unless the loop iteration count is derived via a polynomial or exponential function, perhaps indirectly because the method is itself called in a higher loop, or because the loop counter is effectively multiplied by string operations or something at a lower level.

提交回复
热议问题