Computing Time T(n) and Big-O with an infinite loop

前端 未结 3 2005
半阙折子戏
半阙折子戏 2020-12-04 03:07

I\'m confused on how to create a function T(n) to measure computing time for a nested infinite loop. Here is the code:

x=1;
for(int i = 0;i

        
3条回答
  •  不知归路
    2020-12-04 03:46

    Algorithm complexity is only defined for algorithms, which by (the most often accepted) definition must terminate. This process doesn't terminate (except "in practice" as Marcelo notes; i.e. as a program on a real machine vs. in theory on a theoretical Turing machine with an infinite tape and all the time in the world) so is not an algorithm. So it has no "algorithmic time complexity".

    Trying to determine the algorithmic complexity for a non-algorithm is a futile exercise, as is trying to express its running time as a polynomial if it's an infinite process.

提交回复
热议问题