广度优化搜索python实现

摘要: from collections import dequegraph={}graph['you']=["alice", "bob", "claire"]graph["bob"] = ["anuj", "peggy"]graph["alice"] = ["peggy"]graph["claire"] 阅读全文
posted @ 2018-09-11 20:46 master~hu 阅读(96) 评论(0) 推荐(0)

归并排序python实现

摘要: def merge(a,b): c=[] h=j=0 while (h<len(a))and(j<len(b)): if a[h] < b[j]: c.append(a[h]) h+=1 else: c.append(b[j]) j+=1 if h==len(a): ... 阅读全文
posted @ 2018-09-10 22:13 master~hu 阅读(130) 评论(0) 推荐(0)

二分法递归实现

摘要: #arr 有序数组#m 需要比较的值#left 左边最小值索引#right 右边最大值索引def bin(arr,m,left,right): # left=0 # right=len(arr)-1 try: midian=(left+right+1)//2 #python取整 #midian=in 阅读全文
posted @ 2018-09-10 12:16 master~hu 阅读(526) 评论(0) 推荐(0)

快速排序python实现

摘要: def quicksort(arr): if len(arr)<2: return arr #基线条件 else: base=arr[0] #递归条件 less=[i for i in arr[1:] if i<=base] greater=[i for i in arr[1:] if i>base 阅读全文
posted @ 2018-09-10 10:20 master~hu 阅读(141) 评论(0) 推荐(0)

选择排序python实现

摘要: def findsmallest(arr): smallest=arr[0] smallest_index=0 for i in range(1,len(arr)): #smallest_index+=1 if arr[i]<=smallest: smallest=arr[i] smallest_i 阅读全文
posted @ 2018-09-09 20:10 master~hu 阅读(204) 评论(0) 推荐(0)

二分法python实现

摘要: def bin_search(list,item): low=0 high=len(list)-1 while low<=high: #4 mid = round(((low + high) / 2)+0.1,0) #1 #mid=(low + high) / 2 guess=list[int(mi 阅读全文
posted @ 2018-09-09 16:40 master~hu 阅读(1662) 评论(0) 推荐(0)