简体   繁体   中英

Solving recurrence for T(n-1) + sqrt(n)

I'm hoping that I'm going about this problem the correct way. It asks to solve the recurrence:

T(n) = T(n-1) + sqrt(n)

So far I have researched and been able to get to this point:

T(n) = T(n-2) + (n-1) + sqrt(n) T(n) = T(n-3) + (n-2) + (n-1) + sqrt(n) T(n) = T(0) + 1 + 2 + ... + (n-2) + (n-1) + sqrt(n)

I'm having trouble understanding what the pattern may be to solve for 1+2+...+sqrt(n)

You start with unrolling the recursion and you should receive a sum of square roots. The sum of square roots is a generalized harmonic number and yours one can be approximated with:

在此处输入图片说明

The second line is already wrong.

If T (n) = T (n - 1) + sqrt (n), then T (n - 1) = T (n - 2) + sqrt (n - 1), therefore

T (n) = T (n - 2) + sqrt (n - 1) + sqrt (n)

T (n) = T (n - 3) + sqrt (n - 2) + sqrt (n - 1) + sqrt (n)

T (n) = T (n - 4) + sqrt (n - 3) + sqrt (n - 2) + sqrt (n - 1) + sqrt (n)

and so on.

The sum of the square roots from 1 to n is about the same as the integral of sqrt (x) from 1 to n.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM