If it was an unordered list, we were basically stuck with linear search. Got to walk through the whole list to see if the thing is there.
如果是一个未排序的列表,基本上我们就只能使用线性搜索了,通过遍历整个列表来查看。
We don't seem to be doing that just yet, certainly not as badly, alright, so at this point in the story I have a sorted list of size 4.
当然现在我们不需要那样做,此时此刻,我已对整个问题中大小为4的列表排好序了。
And we said that was log rhythmic, took log n time where n is the size of the list.
当列表的长度为n的时候,整个算法耗时log,n的时间。
It goes through and puts ones in the right place.
它遍历整个列表并提到正确的位置。
So to just preface what we're going to do next time, what would happen if I wanted to do sort, and rather than in sorting the entire list at once, I broke it into pieces, and sorted the pieces, and then just figured out a very efficient way to bring those two pieces and merge them back together again?
所以为了引导下一次,我们要讲的内容,如果我想做排序,而且不是一次吧整个列表排完,会发生什么,我把它拆成小的列表,然后把各个小列表排序,接着用高效的方法再把小的列表?
Alright, so the list is now hopefully sorted correctly and it is, in fact.
现在,整个列表已经正确地,排好序了。
So the first one here is something called insertion sort which amounts to going through the list, taking the first thing that you see and inserting that element into its correct place, - then moving on to the next one, dealing with what element-- whatever element you're given and putting it in its right place.
首先是插入排序,在此算法中,需要遍历整个列表,将你遇到的第一个元素放在其正确的位置,然后移动到下一个元素,继续处理-,不管是什么元素,都将其插入到合适的位置。
应用推荐