算法的运行时间由以下递推关系表示:
null
if n <= 3 then T(n) = n else T(n) = T(n/3) + cn
以下哪一项代表算法的时间复杂度? (A) (n) (B)
(n日志n) (C)
(n^2) (D)
(n^2log n) (A) A. (B) B (C) C (D) D 答复: (A) 说明:
T(n) = cn + T(n/3) = cn + cn/3 + T(n/9) = cn + cn/3 + cn/9 + T(n/27) Taking the sum of infinite GP series. The value of T(n) will be less than this sum. T(n) <= cn(1/(1-1/3)) <= 3cn/2 or we can say cn <= T(n) <= 3cn/2 Therefore T(n) =(n)
© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END