And this is in contrast to Selection Sort where you're fishing again and again for the then smallest element.
这与选择排序是相反的,在选择排序中你需要一次又一次地,找出最小的元素。
Just contrast this for a brief moment to something like Selection Sort which from the get go had a ridiculous amount of redundancy comparing the same damn numbers again and again, and again.
这就与其他的排序算法形成了鲜明的对比,比如选择排序,它会一次又一次地做,多余的比较。
How many swaps do I do in selection sort?
那选择排序要做多少次交换呢?
So you could use sort of negative selection in order to find the ones that you want.
这样你就可以用某种负向选择,去找到你想要的细菌
And this was just a formal way of describing the best case running time and in the case of Selection Sort, what was the best case running time?
这是描述最好情况下运行时间的,一种正式的方式,在选择排序中,最理想的运行时间是多少呢?
We looked at something called Selection Sort and that too was pretty straightforward, at least conceptually.
例如选择排序,至少从概念上来说,它非常简单。
I just go down the list selecting the smallest person at a time and then I repeat, repeat, repeat but when we actually did out the math or kind of reason through it, the running time, the asymptotic running time of bub-- of Selection Sort was also what?
只需要遍历列表,每次找出最小的元素,然后重复上述步骤,但从数学角度看,选择排序的时间复杂度,又是多少呢?
N But it's definitely not one and in fact it wasn't N in the case of Selection Sort because remember the algorithm we implemented on stage last week had me going back and forth across the stage selecting on iteration, the smallest person I can find, the smallest number and then putting them into place.
但在选择排序中,肯定不会是1,也不是,注意,上周我们在这儿,实现的算法中,反复地,迭代进行选择,选出最小的数,然后将其放在合适的位置。
Selection Sort.
选择排序。
How many swaps do I do in general in bubble sort, compared to selection source?
在冒泡排序中,一般要做多少次交换,对比选择排序呢?
So Selection Sort, while it might be easier perhaps to think through than Bubble Sort, or maybe it's pretty much equivalent, it's just a different approach to the same problem.
因此,仔细想想,选择排序也许比,冒泡排序更简单,或者这两者都差不多,只是对同一问题的不同方法而已。
Selection sort too really reduces to a total number of comparisons because I'm again comparing the current smallest to the next thing I see, the next thing, so really a lot of these sorting algorithms boil down to comparisons and the numbers that you actually have to make.
选择排序也可归纳为总数的比较,因为要将当前最小者与下一个进行比较,接着再下一个,可见,很多排序算法都可归结为比较,以及需要比较的次数。
I chose Bubble Sort on the left Selection Sort on the right and then something called merge sort on the very right hand side and then I started this all off roughly at the same time and what was frankly striking at least to me at the time was, my God it's done.
我在左边选择冒泡排序,在中间选选择排序,在最右边选择归并排序,然后同时将它们启动,在那时,至少我是震惊了,天哪,它已经完成了。
I was just finding very tunnel vision-like, the smallest elements at that moment in time which means I don't know anything about the other elements other than they are not the smallest and so no matter what with Selection Sort I had to repeat this again and again and again and if you do out the math it's roughly N squared steps in the worst case as well.
我只有一个狭窄的视野,只知道某时刻的最小元素,就意味着我并不知道其他元素的任何情况,只知道它们不是最小的,所以不管怎样,在选择排序中,我就得一遍一遍地重复选择过程,在最坏情况下,大概需要N的平方次比较。
Like what the heck have we been spending our time for-- our time on with Bubble Sort and with Selection Sort and in fact there's plenty of other N squared sorts that we're not even gonna bother looking at.
真见鬼,我们竟然在-,冒泡排序和选择排序上花时间,而事实上,还有很多我们根本都不想考虑的,复杂度为N平方的排序方法。
Let's do selection and let's do merge sort here on the right just to see what actually happens.
中间进行选择排序,右边进行归并排序,看看会发生什么。
应用推荐