大O题-算法分析三

发布于 2024-11-01 02:34:32 字数 1092 浏览 2 评论 0原文

我有以下问题:

使用大“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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

有深☉意 2024-11-08 02:34:32

不用想太多,我会说 f(n + 1) 是 f(n) 的 6 倍,减去一个常数。因此 f(n) 肯定是 O(6^n)。尽管您可能会发现更严格的限制,但这就是我在实践中所能达到的极限!

为了好玩,我会尝试这个:

f(1) = 6f(0) - 5
     = 6^1.f(0)
f(2) = 6f(1) - 5
     = 6(6f(0) - 5) - 5
     = 6^2.f(0) - 6^1.5 - 5
f(3) = 6f(2) - 5
     = 6^3.f(0) - 6^2.5 - 6^1.5 - 5

我会冒险猜测一下,

f(n) = 6^n.f(0) - 5.(6^0 + 6^1 + ... + 6^(n-1))

并且我非常确定我可以通过几行归纳法来证明这一点(练习留给学生作为练习)。

现在,

sum (k in 0..n-1) 6^k  =  (1 - 6^n) / (1 - 6)

因此

f(n) = 6^n.f(0) - 5.(1 - 6^n) / (1 - 6)
     = 6^n.f(0) + (1 - 6^n)
     = 6^n.(2 - 1) + 1
     = 6^n + 1

证实了我之前的直觉。

让我们做一些快速检查计算:

f(0) = 2 = 6^0 + 1
f(1) = 6.2 - 5 = 7 = 6^1 + 1
f(2) = 6.7 - 5 = 37 = 6^2 + 1
f(3) = 6.37 - 5 = 237 = 6^3 + 1

这对我来说足够做家庭作业了:-)

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:

f(1) = 6f(0) - 5
     = 6^1.f(0)
f(2) = 6f(1) - 5
     = 6(6f(0) - 5) - 5
     = 6^2.f(0) - 6^1.5 - 5
f(3) = 6f(2) - 5
     = 6^3.f(0) - 6^2.5 - 6^1.5 - 5

I'll hazard a guess that

f(n) = 6^n.f(0) - 5.(6^0 + 6^1 + ... + 6^(n-1))

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,

sum (k in 0..n-1) 6^k  =  (1 - 6^n) / (1 - 6)

therefore

f(n) = 6^n.f(0) - 5.(1 - 6^n) / (1 - 6)
     = 6^n.f(0) + (1 - 6^n)
     = 6^n.(2 - 1) + 1
     = 6^n + 1

confirming my earlier intuition.

Let's just do a few quick check calculations:

f(0) = 2 = 6^0 + 1
f(1) = 6.2 - 5 = 7 = 6^1 + 1
f(2) = 6.7 - 5 = 37 = 6^2 + 1
f(3) = 6.37 - 5 = 237 = 6^3 + 1

That's enough for me for homework :-)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文