We saw some quadratic algorithms, typically those are things with multiple nested loops, or iterative or recursive calls, where you're doing, say, a linear amount of time but you're doing it a linear number of times and so it becomes quadratic, and you'll see other polynomial kinds of algorithms.
我们看过一些平方算法,他们一般进行了多次嵌套循环,或者递归迭代调用,对一个线性操作调用线性次,这样就变成平方次了,以后你们能看到,一些多项式算法。
Seven comparisons, right?
是我花了多少次操作来完成这件事?
And in this case, we go from 8 to 4 to 2 to 1 three times and then on each iteration of this algorithm, each pass across the board I'm touching N numbers, so that means I'm doing N things, log N times.
在这个例子中,我们从8得到4,到2,再到1,是3次,在这个算法的每次迭代中,每一趟我都会操作N个数,也就是所我每次要做N步操作,一共要做,log,N,次。
I've got eight elements.
七次操作,对吗?总共有8个元素。
So I have n operations log n times, n log n there we go, n log n. Took us a long time to get there, but it's a nice algorithm to have.
所以我log,n遍的n次操作,就得到了,虽然花了不少时间得到了这个结论。
Because I keep counting down each time around-- mostly I've got to unload this candy which is driving me nuts, so-- thank you.
因为我每次循环b减了,我一共要执行这个循环b次,所以这里我们一共执行了3b次基本操作。
b times. So I've got to go 3 b steps. All right I've got to go through the loop b times I've got three steps each time, and then when I pop out of the loop, I've got two more steps. All right I've got the initiation of answer and the return of it.
好,我一共执行了b次循环,每次循环内部进行了三次基本操作,当跳出循环后还有两个基本操作,因此这个初始的答案就是,2+3b次基本操作,来完成这个循环。
应用推荐