【发布时间】:2017-03-19 13:56:24
【问题描述】:
是否可以将任何嵌套循环的增长表示为指数?这是我和几个同学的讨论。我试图用指数定律证明:
If n = the size of the outer loop
If k = the size of the inner loop
Then, if we use n as our base and the value of n is n^1:
Then, if n^x = k, the total = n^(1+x) for any n and k.
这应该适用于我认为的任何基础。此外,只要您使用相同的底座,从技术上讲,外部循环可以提高到任何功率。
编辑:澄清代码示例:
for (int i =1; i <= n; i++){
for (int j = 1; j <= k; j++){
/// whatever
}
}
Let us say that:
n = 10
k = 5
We would expect that the total would be 10 * 5 = 50
50 maximum loops
I am saying that:
10 = 10^1 -> outer loop
5 = 10^.69897 -> inner loop
10^1.69897 = 50
这应该适用于任何基地。
【问题讨论】:
-
你对循环的growth和size的定义是什么? total 代表什么?
-
通过增长,我们谈论的是相对于内部循环大小的变化率。总数表示最里面的操作将运行的最大次数
-
所以 size 是指迭代次数? n 和 k 是常量吗?如果不是,它们是通过哪种算法改变的?
-
好吧,你总是可以写成 10 * 5 = 10^1 * 10^log10(5) = 10^(1 + log10(5)) ...如果这个表示对你有用,来吧,使用它。
-
我真的想知道这是否成立,或者它是否恰好在这里工作。我还是新手。