Recurrence Relation T(n) = T(n^(1/2)) + T(n-n^(1/2)) + n

半城伤御伤魂 提交于 2019-12-24 00:54:48

问题


My friend and I have found this problem and we cannot figure out how to solve it. Its not trivial and standard substitution method does not really work(or we cannot apply it correctly) This should be quicksort with pivots at rank problem.

Here is the recurrence:

T(n) = T(n^(1/2)) + T(n-n^(1/2)) + n

Any help would be much appreciated. Thanks!


回答1:


First take it easy:

T(n) = T(n-n^(1/2)) + n, number of iteration is n^(1/2), in each iteration you'll have n-ksqrt(n) time complexity, so total time complexity is: &Sum;n-ksqrt(n) for 0<=k<=sqrt(n), which is n^(3/2).

Now solve your own problem:

T(n) = T(n^(1/2))+T(n-n^(1/2)) + n

again calculate number of steps till arriving to zero or 1: first part `T(n^(1/2)) takes O(log log n) time, and second part takes O(sqrt(n)) times to arriving to zero or 1 (See my answer to related question), So second part dominates first part, Also in each iteration time complexity of second part causes to sqrt(n) extra item, which doesn't effect to the first part time complexity (n-sqrt(n)), so your total runtime is n*sqrt(n).



来源:https://stackoverflow.com/questions/10544241/recurrence-relation-tn-tn1-2-tn-n1-2-n

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!