SEQUENTIAL_SEARCH(A, k)
- i ← 0
- while i < A.size() and A[i] ≠ k do
- i ← i + 1
- if i = A.size()
- return -1
- else
- return i
Cavg = 1* p/n + 2* p/n + ...+ (n-1)* p/n +np/n + n(1-p) = p/n [1+2+...+n] + n(1-p) = p/n * (n)(n+1)/2 +n(1-p) = p(n+1)/2 + n(1-p) = pn/2 +p/2 +n -pn = n-pn/2 + p/2 = n(1-p/2) + p/2