And here I've got a choice. OK, one of the ways I could do would be the following.
在这种情况的数组下,我们需要考虑考虑读取时间了。
Or another way of saying it is, we're going to use as the basic steps, those operations that run in constant time, so arithmetic operations.
我们用可以在恒定时间内完成的操作,算法,比较,内存读取。
And as a consequence, access time in the list is constant, which is what I want.
这会占用一些额外的空间,回到问题本身,这么做的话,读取数组的时间就变成常量了。
With this, if I can assume that accessing the i'th element of a list is constant, then you can't see that the rest of that analysis looks just like the log analysis I did before, and each step, no matter which branch I'm taking, I'm cutting the problem down in half.
读取数组中的第i个元素,是个常量时间的操作的话,我也就能像以前那样得到,这个算法是对数级复杂度的分析,并且每一步不管我选择哪个区间,我都可以把问题的规模缩小一半。
应用推荐