決定論的線形探索アルゴリズムの平均ケース実行時間を導き出そうとしています。アルゴリズムは、ソートされていない配列Aの要素xをA [1]、A [2]、A [3] ...A[n]の順序で検索します。要素xが見つかると停止するか、配列の最後に到達するまで続行します。ウィキペディアで検索したところ、答えは(n + 1)/(k + 1)でした。ここで、kはxが配列に存在する回数です。私は別の方法でアプローチし、別の答えを得ています。誰かが私に正しい証拠を教えてくれ、また私の方法の何が悪いのか教えてもらえますか?
E(T)= 1*P(1) + 2*P(2) + 3*P(3) ....+ n*P(n) where P(i) is the probability that
the algorithm runs for 'i' time (i.e. compares 'i' elements).
P(i)= (n-i)C(k-1) * (n-k)! / n!
Here, (n-i)C(k-1) is (n-i) Choose (k-1). As the algorithm has reached the ith
step, the rest of k-1 x's must be in the last n-i elements. Hence (n-i)C(k-i).
(n-k)! is the total number of ways of arranging the rest non x numbers, and n!
is the total number of ways of arranging the n elements in the array.
単純化しても(n + 1)/(k + 1)が得られません。