[英]Unrolling Method For: T(n) = 1 when n = 0 and 2T(n-1) + 1
For为了
I know we're supposed to look for patterns and understand the problem down till we start transforming the equations with different variables.我知道我们应该寻找模式并理解问题,直到我们开始用不同的变量转换方程。 However, once I get there, I don't understand how it is done and why certain things are done.
然而,一旦我到达那里,我不明白它是如何完成的以及为什么要完成某些事情。
My issue is specifically where we replace i with n at 2 i ·T(n-1).我的问题特别是我们在 2 i ·T(n-1) 处用n替换i 。 However, a full explanation would be useful as well!
但是,完整的解释也很有用!
It the same way that 99999 10 is 100000 10 - 1, 11111 2 is 100000 2 - 1.就像 99999 10是 100000 10 - 1, 11111 2是 100000 2 - 1 一样。
There are two ways to look at this problem.有两种方法可以看待这个问题。 One is from some arbitrary n working backwards, which your description already covers.
一个是从一些任意的n个工作倒退,这说明你已经盖。 Another way that I've found helpful is starting from zero and working up to n :
我发现有用的另一种方法是从零开始,直到n :
Here << is the "left shift" operator on binary numbers, which is equivalent to multiplication by 2. This operator is fairly common in many programming languages.这里 << 是二进制数上的“左移”运算符,相当于乘以 2。这个运算符在许多编程语言中相当常见。 It helps show that you are just adding a 1 bit at every step of the way.
它有助于表明您只是在每一步添加 1 位。 Going back to the first assertion, n consecutive one bits are equivalent to 2 n + 1 - 1.
回到第一个断言, n个连续的一位等价于 2 n + 1 - 1。
The explanation in your question just uses i as a counter that runs from 1 to n .您问题中的解释仅使用i作为从 1 到n运行的计数器。 It's not part of the equation except as the step counter.
除了作为计步器之外,它不是等式的一部分。 In the last step, i = n , hence the conversion you may be confused about.
在最后一步中, i = n ,因此您可能会对转换感到困惑。
When first seeing the formulas I had the same problem as you.当第一次看到公式时,我和你有同样的问题。 But let's start from the beginning.
但让我们从头开始。
At first you try to approach the final depth n
step by step through i
.首先,您尝试通过
i
逐步接近最终深度n
。 So for each number i
you resolve the Formula i
times (in the picture for i=1
, i=2
, i=3
, i=4
), but beware you can't resolve T(ni)
yet.因此,对于每个数字
i
您解析公式i
次(在图片中i=1
, i=2
, i=3
, i=4
),但要注意您还不能解析T(ni)
。 But you can derive the pattern for i=n
.但是您可以推导出
i=n
的模式。 This line actually starts with the error: the picture says i=ni
but it should be actually i=n
since you reached the bottom.这一行实际上是从错误开始的:图片上写着
i=ni
但实际上应该是i=n
因为你到达了底部。
And the rest is pretty straight forward: you write down the pattern you see and put it in a Sum Formula ( Sum_{j=0}^{i-1}2^j
).剩下的就很简单了:你写下你看到的模式并将它放在一个总和公式中(
Sum_{j=0}^{i-1}2^j
)。 You substitute i
with n
since this is the premise of the line.你用
n
代替i
,因为这是该行的前提。 You substitute T(nn)
with T(0)=1
.您将
T(nn)
替换为T(0)=1
。 Next you apply the Finite Geometric Series and therefore get rid of the sum symbol.接下来,您应用有限几何级数,从而摆脱求和符号。 The rest should be clear.
其余的应该是清楚的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.