算法分析再现比较

时间:2014-03-26 04:50:23

标签: algorithm time analysis recurrence

让算法X: T(n) = 7T(n/2)+n^2, and Y: T’(n) = aT’(n/4)+n^2

我需要找到a的最大值,这样算法Y渐近比算法X快。

2 个答案:

答案 0 :(得分:1)

使用masters theorem: -

    X : T(n) = O(n^log2(7))

So to get an asymptotically faster algorithm using masters theorem   

    2 <= log4(a) < log2(7)

 Finding max value such that the condition is true :-

    log4(a) < log2(7)     
    log2(a)/log2(4) < log2(7)   
    log2(a)/2 < log2(7)
    log2(a) < 2*log2(7)
    a < 7^2   =  a < 49

 As a is no of subproblems it needs to be integer therefore :-

 a = 48 is max value that a can take so that Y is asymptotically faster than X 

答案 1 :(得分:0)

解决方案应该与此类似,但你应该考虑地板和电池。

对于算法X,我们有:

T(n)=7T(n/2)+n^2
=> O(n)=n^2 + 7(n/2)^2 + 49(n/2)^3 + ... + 7^log(n)(n/2)^(log(n)+1)
=> O(n)=n^2 . [7/(2^2) + 7^2/2^3 + ... + 7^log(n)/2^(log(n)+1)]
=> O(n)=n^2 . \sum_{i=1 to log(n)}{1/2x(7/2)^i}   <= geometrical series summation easy

并对Y进行相同操作直到您可以比较并找到a的值。