python-算法基础

1.时间复杂度和空间复杂度

2.查找算法

2.1 二分查询法

2.1.1 非递归代码

def erfen(data,target):
    low = 0
    high = len(data) - 1
    while low < high:
        mid = (low + high) // 2
        if data[mid] == target:
            return mid
        elif data[mid] < target:
            low = mid + 1
        else:
            high = mid - 1
    return

2.1.2 递归代码

def diguierfen(data,target):
    low = 0
    high = len(data) - 1
    if low < high:
        mid = (low + high) // 2
        if data[mid] == target:
            return mid
        elif data[mid] < target:
            diguierfen(data[mid+1:high],target)
        else:
            diguierfen(data[0:mid-1],target)
    else:
        return

 

2.排序算法

3.二叉树遍历

猜你喜欢

转载自www.cnblogs.com/taomin/p/10374230.html
0条评论
添加一条新回复