线性搜索算法如下: Linear Search(A,x) //数组A[1..n],待查找对象x 1.for i←1 to ndo 2.if A[i]=x then
线性搜索算法如下:
Linear Search(A,x) //数组A[1..n],待查找对象x
1.for i←1 to ndo
2.if A[i]=x then return i //查找成功
3.return "no" //查找失败
设A的n个元素都不相同,x已在A中的概率为p(0≤p≤1),并且当x在A中时,x等于A的每一个元素的可能性相等.试分析算法的平均时间复杂度.