算法分析对比复发
答
使用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
答
解决方案应该与此类似,但您应该考虑地板和小区。
对于算法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
值。