简体   繁体   English

以下方法的时间复杂度

[英]Time complexity of the following method

I'm trying to determine the time complexity of the following method. 我正在尝试确定以下方法的时间复杂度。 At the beginning I have three for loops which would yield m^3. 在开始我有三个for循环,它将产生m ^ 3。 I don't know how to determine, what is the time complexity of the recursive call at the end of the method. 我不知道如何确定,在方法结束时递归调用的时间复杂度是多少。

Can someone help me with this? 有人可以帮我弄这个吗?

void p(int n, int m) {
    int i,j,k ;
    if (n > 0) {
        for (i=0 ; i < m ; i++)
            for (j=0 ; j < m ; j++)
                for (k=0 ; k < m ; k++)
                    System.out.println(i+j*k) ;  
        p(n/m, m) ;
    }
 }

O(m^3) is execution without aditional recusion, as you mentioned. 正如你所提到的,O(m ^ 3)是没有附加回忆的执行。

The total time is just multiply of time this single step. 总时间只是这一步的倍增时间。

For n = m^(k-1) is the step executed k times, thus it has O(k*m^3), which is O(ln(n)*m^3). 对于n = m ^(k-1)是执行k次的步骤,因此它具有O(k * m ^ 3),其为O(ln(n)* m ^ 3)。

Followinyg the steps below would allow you to deduce the time complexity in formal manner: 遵循以下步骤将允许您以正式方式推断时间复杂度:

在此输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM