大O题-算法分析三
我有以下问题:
使用大“O”符号解决递归关系简化答案:
f(0) = 2
f(n) = 6f(n-1)-5, n>0
我知道这是一阶非齐次递归关系并且已经尝试过这个问题,但我似乎无法获得基础的正确输出情况(f(0) = 2)。
该问题必须在证明中使用几何级数公式之和。
这是我的答案 - 注意 sum(x = y, z) 是大写 sigma 表示法的替代品,其中 x 是初始化为 y 的总和的下限,z 是总和的上限:
1. *change forumla:*
2. f(n) = 6^n.g(n)
3. => 6^n.g(n) = 6.6^(n-1) .g(n-1) -5
4. => g(n) = g(n-1)-5/6^n
5. => g(n) = sum(i=1, n)-5/6^i
6. => f(n) = 6^n.sum(i=1, n)-5/6^i
7. => *Evaluate the sum using geometric series forumla*
8. => sum(i = 1, n)-5/6^i = [sum(i = 1, n)a^i] -------> (a = -5/6)
9. => *sub a = -5/6 into geometric forumla [a(1-a^n)/(1-a)]*
10. => [(-5/6(1 - (-5/6)^n))/(1-(-5/6))]
11. => g(n) = [(-5/6(1 + (5/6)^n))/(1+5/6)]
12. => f(n) = 6^n . g(n) = 6^n[(-5/6(1 + (5/6)^n))/(1+5/6)]
13. => *sub in n = 0 to see if f(0) = 2*
首先,我确信第 11 行的方程可以进一步简化,其次,在 n = 0 中进行替换应该得到 2 作为结果。当到达第 13 行时我无法获得这个答案...
编辑:我需要知道的是为什么当将 n = 0 代入第 12 行的方程时我没有得到 f(0) = 2。另外我想知道如何简化第 12 行中 f(n) 的方程?
有人...?
I have the following question:
Solve the recurrence relation simplifying the answer using Big 'O' notation:
f(0) = 2
f(n) = 6f(n-1)-5, n>0
I know this is a first order inhomogenous recurrence relation and have had a go at the question but I cannot seem to get the right output for the base case (f(0) = 2).
The question MUST use the sum of geometric series forumla within the proof.
Here is my answer - Note sum(x = y, z) is a replacement for capital sigma notation, where x is the lower bound of the summation initialised to y and z is the upper bound of the summation:
1. *change forumla:*
2. f(n) = 6^n.g(n)
3. => 6^n.g(n) = 6.6^(n-1) .g(n-1) -5
4. => g(n) = g(n-1)-5/6^n
5. => g(n) = sum(i=1, n)-5/6^i
6. => f(n) = 6^n.sum(i=1, n)-5/6^i
7. => *Evaluate the sum using geometric series forumla*
8. => sum(i = 1, n)-5/6^i = [sum(i = 1, n)a^i] -------> (a = -5/6)
9. => *sub a = -5/6 into geometric forumla [a(1-a^n)/(1-a)]*
10. => [(-5/6(1 - (-5/6)^n))/(1-(-5/6))]
11. => g(n) = [(-5/6(1 + (5/6)^n))/(1+5/6)]
12. => f(n) = 6^n . g(n) = 6^n[(-5/6(1 + (5/6)^n))/(1+5/6)]
13. => *sub in n = 0 to see if f(0) = 2*
Firstly, I am sure the equation on line 11 can be simplified further and secondly subbing in n = 0 should yield 2 as the result. I cannot obtain this answer when reaching line 13...
EDIT: What I need to know is why I am not getting f(0) = 2 when subbing n = 0 into the equation in line 12. Also what I would like to know is how can I simplify the equation for f(n) in line 12?
Anyone...?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不用想太多,我会说 f(n + 1) 是 f(n) 的 6 倍,减去一个常数。因此 f(n) 肯定是 O(6^n)。尽管您可能会发现更严格的限制,但这就是我在实践中所能达到的极限!
为了好玩,我会尝试这个:
我会冒险猜测一下,
并且我非常确定我可以通过几行归纳法来证明这一点(练习留给学生作为练习)。
现在,
因此
证实了我之前的直觉。
让我们做一些快速检查计算:
这对我来说足够做家庭作业了:-)
Without thinking too hard about this, I'm going to say that f(n + 1) is 6 times larger than f(n), minus a constant. f(n) is therefore certainly O(6^n). Although you may find a tighter bound, that's about as far as I'd go in practice!
For the fun of it, I'll try this:
I'll hazard a guess that
and I'm pretty sure that I could prove this by induction in a few lines (exercise left as an exercise for the student).
Now,
therefore
confirming my earlier intuition.
Let's just do a few quick check calculations:
That's enough for me for homework :-)