設有演算法如下:
int Find(ElemType a[ ],int s,int t,ElemType x)
{ int m=(s+t)/2;
if (s<=t)
{ if (a[m]==x)
return m;
else if (x<a[m])
return Find(a,s,m-1,x);
else return Find(a,m+1,t,x);
}
return -1;
}
分析執行Find(a,0,n-1,x)的時間復雜度。
uj5u.com熱心網友回復:
有序列的折半查找演算法,O(ln(n))的時間復雜度轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/85332.html
標籤:數據結構與算法
上一篇:資料結構中的資料項為什么不可分
