
《算法(第4版)》源码Python版
Calm2049
Loading...
展开
-
二分查找(Python)
# 二分查找 O(㏒2n)class BinarySearch: @staticmethod def rank(key, a): lo, hi = 0, len(a)+1 while lo <= hi: mid = lo + (hi - lo) // 2 if key < a[mid]:...原创 2018-12-28 15:55:22 · 383 阅读 · 0 评论 -
选择排序(Python)
# 选择排序 O(n²)class Selection: @staticmethod def sort(a): length = len(a) for i in range(length): min_idx = i for j in range(i+1, length, 1): ...原创 2018-12-28 16:02:48 · 415 阅读 · 0 评论 -
插入排序(Python)
# 插入排序class Insertion: @staticmethod def sort(a): length = len(a) i = 1 while i < length: j = i while j > 0 and a[j] < a[j-1]: ...原创 2018-12-28 18:58:36 · 320 阅读 · 0 评论