【问题标题】:Stumped on solving a recurrence equation [closed]难以解决递归方程[关闭]
【发布时间】:2013-12-18 04:04:54
【问题描述】:

这是我正在使用的等式(它来自过去的考试问题,我弄错了):

void foo(float[] array, int start, int end){
    if((end-start) <= 1) return;

    int x = (end-start) / 5;
    int y = 2*x;
    int z = 4*x;

    foo(array,start,start+y);
    for(index = y; index <z; index++){
            array[index]++;
    }
    foo(array,start+z,end);
}

我将如何为此提出一个递归方程? 我不确定我应该使用的符号,因为函数#recurrences 取决于 end-start 的值......

T(1) = 1
T(N) = ____ + ____ + _____

【问题讨论】:

    标签: c++ algorithm recursion recurrence


    【解决方案1】:
    for notation simplicity, lets call N = end-start
    then:
     foo(array,start,start+y);  // T(2/5 * N)
     for(index = y; index <z; index++)  // 2/5 * N
     foo(array,start+z,end);  // T(N/5)
    
    T(N) = T(2/5 * N) + 2/5 * N + T(N/5)
    

    够近了吗?

    【讨论】:

    • 我猜第一部分应该是T(N/5)。否则,它很棒。确实应该将end-start 表示为N。 =D
    猜你喜欢
    • 2018-12-30
    • 2021-03-02
    • 2020-08-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-09-20
    相关资源
    最近更新 更多