正在加载图片...
13 Recursive binary search int bsearch(int* al, int low, int high, int x) f (low>high) return -l; 0(1) e⊥se int mid=(lowthigh)/2 f (x=a [mid] return mid; 0(1) else if(a [mid]<x bsearch(a, mid+l high, x)i T(N/2) lse bsearch(a low, mid-1)i 7(N)=7(~)+13 O(1) T(N/2) int bsearch(int* a[],int low, int high, int x) { if (low>high) return -1; else int mid=(low+high)/2; if (x=a[mid]) return mid; else if(a[mid]<x) bsearch(a,mid+1,high,x); else bsearch(a,low,mid-1); } O(1) Recursive binary search: ) 1 2 ( ) ( (1) 1 = + = N T N T T
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有