OK. The next largest element has to end up in the second last spot. Et cetera. All right, so it's called bubble sort because it does this bubbling up until it gets there.
好的,下一个最大元素又,能跑到倒数第二的位置,等等如此,好的,这称为冒泡排序,因为这个泡泡一直冒到他自己的位置。
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.
因此,仔细想想,选择排序也许比,冒泡排序更简单,或者这两者都差不多,只是对同一问题的不同方法而已。
OK? Because what am I doing? It's called bubble sort because it's literally bubbling along, right?
明白了么?你要知道我在做什么,冒泡排序真的就像冒泡,对么?
- Well-- -- I'm-- maybe-- I'm sorry, maybe-- -- No, no, no, no. I-- I think-- -- That's not a-- I-- I think the Bubble Sort would be the wrong way to go.
笑声】,嗯-,我,很抱歉,可能是-,不,不……,我觉得-,那不是-,我觉得冒泡排序应该不是正确的方法。
And so you have to go back to the drawing board and realize Bubble Sort or whatever it is you're using just isn't enough to snuff, I need to come up with something more clever.
因此,你必须重新开始,而且会意识到冒泡排序,或你正在使用的方法并不理想,我需要提出一种更好的方法。
All right. Nonetheless, even with this change, what's the order growth for bubble sort?
好的,不管怎么样,尽管这发生了,冒泡排序的增长率是多少呢?
God bless. Oh, sorry, that wasn't a sneeze, it was a two? How many swaps do I do in bubble sort? A lot. Right. Potentially a lot because I'm constantly doing that, that says I'm running that inner loop a whole bunch of times.
上帝保佑,哦,抱歉,我没说清楚,这是两个问题,在冒泡排序中要做多少次排序?许多,正确的,可能要做很多次,因为在持续的干,这就意味着它要做很多次内部循环。
Let's try it again. Test bubble sort.
让我们再试一试吧,测试下冒泡排序。
Bubble sort recall is a comparison sort.
冒泡排序就是一种比较排序。
Insertion sort or bubble sort?
插入排序还是冒泡排序?
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.
我在左边选择冒泡排序,在中间选选择排序,在最右边选择归并排序,然后同时将它们启动,在那时,至少我是震惊了,天哪,它已经完成了。
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平方的排序方法。
应用推荐