基础算法之Python实现
MADA0
这个作者很懒,什么都没留下…
展开
-
binary_search算法之Python实现
def binary_search(list, item): low = 0 high = len(list) #list中元素的数目 while low <= high: mid = int((low + high) / 2) #取中间元素的 guess = list[mid] if guess == i...原创 2018-06-03 23:23:48 · 1514 阅读 · 0 评论 -
广度优先搜索
from collections import dequegraph = dict()graph['you'] = ['tom','alice', 'bob', 'claire']graph['bob'] = ['anuj','peggy']graph['alice'] = ['peggy']graph['claire'] = ['thom', 'jonny']graph['anuj'...转载 2018-07-03 21:44:29 · 135 阅读 · 0 评论 -
快速排序&选择排序
选择排序:#从下到大def find_smallest(arr): smallest = arr[0] smallest_index = 0 for i in range(1, len(arr)): if arr[i] < smallest: smallest = arr[i] smallest_index = i return smallest_indexde...原创 2018-07-03 21:47:49 · 500 阅读 · 0 评论