代码之家  ›  专栏  ›  技术社区  ›  Qasim Idrees

三个嵌套相关循环的算法时间复杂度分析

  •  0
  • Qasim Idrees  · 技术社区  · 7 年前

    嗨,我正试图分析这个算法的时间复杂度,但我很难解开并计算最终循环将执行多少次。

    for(int i =1; i<=n; i++){
        for (int j=i; j<=n; j++) {
            for (int k =1; k<=j; k++){
                // Any statment
            }
        }
    }
    
    1 回复  |  直到 7 年前
        1
  •  1
  •   A. Ada.    7 年前

    在时间复杂性分析中,每个循环语句都由一个和表示。因此,必须解决以下表示嵌套循环的计算:

    complexity calculation

    等于: Result