And the third thing I need to decide is how do I combine? You know, point out to you in the binary search case, combination was trivial. The answer to the final search was just the answer all the way up.
第三个问题是我需要决定如何进行合并?,就你们所知的,在二分查找中所打印出来的,合并的过程是非常简单的,最后查询的结果,就是一路上来所以的结果。
A patterned series of these tiny charged berries on the disk represents a single bit of data in the binary number system used by computers.
这些在磁盘上的有序的小粒子,代表这个当代计算机中,二进制中单独的一位。
Remember, we saw that last time looking at the binary numbers. 2 to the n is a big number.
还记得吗,我们上次看过的二进制数,从2到n是一个很大的数。
It is a declaration of absolute interdependency among the things that we understand in binary terms but that we take somehow one to be causative of the other when we think about them.
这是在宣布事物之间的绝对的相互性,我们能在二元关系上理解这些事,但是我们惯常于把一个是当成另一个的原因。
Because the two are not identical despite massive amounts of scholarship that confuses this issue: thinks holy means pure, thinks common means impure, and it just doesn't: these are different binary oppositions. The two are not identical.
因为这俩并不完全相同,还是会有很多学者会弄混它们:,认为神圣的就是纯洁的,普通的就是不纯洁的,实则不然:,它们是不同的相对关系,它们并不完全相同。
If I look in the binary case, takes a little longer.
这里的输出,告诉我们。
And it's called divide and conquer for the obvious reason. I'm going to divide it up into sub-problems with the hope that those sub-problems get easier. It's going to be easier to conquer if you like, and then I'm going to merge them back. Now, in the binary search case, in some sense, this is a little bit trivial.
因此被称为分治的原因就这么简单,将一个问题分解成一些子问题,并希望这些子问题解决起来比较方便,正如你希望的,求解的过程也会变得简单,下面就是把结果合并起来,现在,在二分搜索的例子里,从某些方面来说,这有点微不足道。
Right, in the binary case, bam.
所花费的步骤数是一样的。
Notice here that it's different than the binary search case. We're certainly dividing down, but the combination now actually takes some work. I'll have to actually figure out how to put them back together. And that's a general thing you want to keep in mind when you're thinking about designing a divide and conquer kind of algorithm.
一个分治的例子,注这里,与二分查找所不同的地方,我们肯定是分解了,但是合并的过程还是需要一些工作量的,我会详细说明怎样把它们合并在一起的,当你在考虑设计一个分治算法时,这是你要必须记住的最基本的东西。
Well, if we actually want to represent something like the number 7, well in binary, not actually in decimal like this.
如果你表达,类似于7的数字,在二进制中,它和十进制可不太一样。
So binary search, the phonebook example, binary search on the pieces of paper on the white board, why is that?
是二分查找,例如电话簿的例子,对其中的某一页进行二分查找,为什么呢?
OK. Binary search is perhaps the simplest of the divide and conquer algorithms, and what does that mean? It says, in order to solve a problem, cut it down to a smaller problem and try and solve that one.
好了,二分搜索也许是,最简单的分治算法,这意味着什么?,也就是说,为了解决一个问题,把它切割成小的问题,然后再来一个个解决。
All right? I don't care what's in there, but just assume that's my list. And just to remind you, on your handout, and there it is on the screen, I'm going to bring it back up, there's the little binary search algorithm.
好,我不管列表里是什么,就假定那是一个列表,要提醒你们的是,在你们的讲义上和屏幕上,有一个简单的二分查找算法。
Seventy-nine. In fact, if you add up each of these numbers, 9 you should get the decimal number 79 79 from this binary number here.
9,事实上,如果你把这些数字累加,你应该能从这些二进制中9,得到十进制数。
OK. At the end of the lecture last time, I also showed you an example of binary search.
好的,在上次课程的最后,我也给你们看了一个二分查找的例子。
Now, the decision tree, if I branch left, it's a binary tree.
现在,这个决策树,如果我走左边的分支,这是一棵二叉树。
In binary search-- ah, there's that wonderful phrase, this is called a version of binary search just like you saw bin-- or bi-section methods, - when we were doing numerical things- in binary search, I need to keep track of the starting point and the ending point of the list I'm looking at.
就是当我们处理数字的时候,所称的二分检索,在二分法搜索中,我需要记录区间的开始点和尾点,初始化的时候就是-,问题输入的开始点和尾点,当我开始做测试的时候,我想要做的就是去取中值点。
On the other hand, watch what happens with binary. Is the partway one there?
噢,它只比100万的情况下多用了一步,请注意这就是?
The way in which we put signs together is to take these bundles, these binary relationships between a concept and a sound image, and adjust them in an unfolding sequence.
我们随意地将能指和所指捆在一起,也就是构成了一个事物和声音形象的关系,而且他们能被排列成话语。
Voice and writing, by the way, are not a stable binary.
顺道说一句,声音和文字不是稳定的二元系统。
But at the end of the day, and here's why we just went with binary and not decimal years ago, when you have one implement a computer with a physical device, it's actually really easy to represent the notion of on or off.
但是最终,之前我们采用二进制,而不是十进制,主要是因为当我们用一台实体机器运行计算机时,这实际上很容易用开或者关的概念来表示。
We're going to call binary search, it's going to take the list to search and the element, but it's also going to say, here's the first part of the list, and there's the last part of the list, Well, it checks to see, is it bigger than two?
我们将要调用这个二分查找,它将会在列表里面搜索元素,假定这里是,列表的第一个元素,那里是列表的最后一个元素,代码内部到底做了什么?
The so called binary system, 1 these zeros and ones that you'd probably have some vague sense underlie all computers today actually reduced to the exact same grade school kind of math and system except with computers, 1 because it's a lot easier to use just two digits, zero and one.
所谓的二进制就是,你觉得模糊的0与,在电脑上计算,事实上可以简化为跟小学数学一样,只是在电脑上计算而已,因为它更容易,仅仅使用两个数字,0与。
But let's look a little more carefully at the code for binary search-- for search 1.
二分搜索算法的代码,那么search,1,这个方法的。
So what would be the letter A in binary inside of a computer's memory when you hit the letter A on the keyboard, for capital A?
当你敲击键盘上的字母A时,那么在计算机二进制的存储中,字母A是什么样的呢?
The instant unlike binary search, where each instance was separate, here the instances overlap.
这个例子不像搜索二进制数,每个例子是独立的,这里的例子是相互重叠的。
Now, one of the questions we could still ask is, right, we've got binary search, which has got this nice log behavior.
目前,还有一个问题我们仍然要问的是,对,我们已经学了二分查找,有着非常好的log级别的行为。
I'm narrowing it down. It's getting a little silly but you know I'm going to really be persistent and just follow the rules here of binary search, rather than jumping to conclusions.
按照二分法的规则来做的,而不是直接得出某种结论,很明显这儿我的目的是什么?,显示这两个相同的东西。
OK. That's the basic idea of binary search.
好了,这就是二分查找的基本思想。
to the n, every value in the 1 bit vector we looked at last time is either 0 or 1. So it's a binary n number of n bits, 2 to the n.
从2到n,我们上次看到的,位向量的每个值不是0就是,所以它是n,比特的二进制数,从2到。
应用推荐