And the basic idea was that we had some sort of a line and we knew the answer was somewhere between this point and this point.
去学习的二分搜索是有联系的,这种方法的基础思想,是我们有一个线性的序集,我们也明白答案在其中的某一段区间。
And the bond order you get out will either be, for example, zero, which would mean that you have no bond, 5 or you could have 1, a single bond, 1 . 5, a 1 and 1/2 bond, 2, a double bond, and so on.
你得到的键序要么是比如说是零,这意味着没有键,或者你会得到1,单键1。,1又二分之一键,2,一个双键,等等等等。
And that you might look at, for example, that first example, and say, man by this stage it was already sorted, yet it had to go through and check that the third element was in the right place, and then the fourth and then the fifth and then the six.
你可能会去看看例如第一个例子,然后要抱怨,到这里,它已经是排好序的了,但他还是得去遍历查看,第三个元素是不是在正确的位置,然后第四个,第五个,第六个。
And this is now consistent with my claim that I have sorted a list of size N equals 1.
这与我之前所说的是一致的,我已经将N为1的一个序列排好了序。
The breaking of so much as a single law constitutes the essence of anarchy, constitutes the essence of lawlessness, it is a far-reaching argument for obedience to the law.
只要违反一条法律,即可构成失序的本体,混乱的本体,这是一个深远的申论,关于服从法律。
Again. Basic premise of binary search, or at least we set it up was, imagine I have a sorted list of elements. We get, in a second, to how we're going to get them sorted, and I want to know, is a particular element in that list..
好,二分查找的基本前提,或者是我们建立二分查找的基础,我们已经有了一个排好序的元素列表,我们就需要知道如何来快速的排序,如何从列表中找到特定的元素。
I remind you, I know you're not really listening to me, but that's OK. I reminded you at the beginning of the lecture, I said, let's assume we have a sorted list, and then let's go search it.
没关系,我告诉过你在课程的开始,我们假设这是一个排好序的列表,然后才进行的搜索,那实际上有序列表从哪里来的呢?
If I look for, say, minus 1, you might go, gee, wait a minute, if I was just doing linear search, I would've known right away that minus one wasn't in this list, because it's sorted and it's smaller than the first elements.
如果我要查找-1,你可能要怒了,呵呵,等一等,如果我用的是线性查找,我不会知道-1不在这个列表中,但是列表是排好序的,1又比第一个元素小。
So let's look at that.
假设我想搜索一个已经排好序的数组。
Basic idea, before I even look at the code, is pretty simple. If I've got a list that is sorted, in let's call it, just in increasing order, and I haven't said what's in the list, could be numbers, could be other things, for now, we're going to just assume they're integers.
我们可以说基本的思想是很简单的,如果我有一个排好序的数组,让我们认为这个数组是递增的吧,我并没说数组里元素是什么,可能是数字,也可能是其他的东西,现在我们假设是integer类型的数字吧,最简单的方式就是这么做了:
应用推荐