Python 实现的Binary Search 算法以及效率的对比

最近用Python3.2,3实现了一下Binary Search算法,同时看到网上有关于程序执行时间统计的代码段,于是就加到了程序里

import random
import functools
import timeit

original=[]
target=0;

def binary_search(target,seq=[],lowerindex=0,upperindex=None):
  "for binary search"
  middleIndex=int((upperindex+lowerindex)/2)
  if middleIndex==lowerindex:
    print("not found",target)
  else:
    if seq[middleIndex]==target:
      print("binary search found",seq[middleIndex])
      print("binary search index is:", middleIndex+1)
    elif seq[middleIndex]


你可能感兴趣的:(python)