经典算法
Lucas__liu
这个作者很懒,什么都没留下…
展开
-
经典排序算法(三)--- 选择排序
选择排序选择排序(Selection Sort)是一种简单直观的排序算法,无论什么数据进去都是 O(n²) 的时间复杂度。所以用到它的时候,数据规模越小越好。唯一的好处可能就是不占用额外的内存空间了吧。算法原理它的工作原理如下,首先在未排序序列中找到最小(大)元素,存放到排序序列的起始位置,然后,再从剩余未排序元素中继续寻找最小(大)元素,然后放到已排序序列的末尾。以此类推,直到所有元素均排...原创 2019-11-25 16:01:05 · 288 阅读 · 0 评论 -
经典排序算法(二)--- 直接插入排序
arr = [5, 4, 3, 8, 7, 0, 6, 7]test = [1,2,3,4]def insert_sort(array): length = len(array) for i in range(1, length): current = i pre_index = i - 1 while pre_index &...原创 2019-10-22 14:21:32 · 399 阅读 · 0 评论 -
经典排序算法(一)--- 冒泡排序
参考https://zhuanlan.zhihu.com/p/49271189https://www.runoob.com/w3cnote/insertion-sort.htmlhttps://algorithm-visualizer.org/dynamic-programming/maximum-subarrayhttps://github.com/algorithm-visualiz...原创 2019-09-26 17:31:29 · 523 阅读 · 0 评论