1

Consider an array $ X $ of $ m $ numbers, where each number $ X_i $ is drawn independently and uniform at random from the interval (0, 1). Let $ X_{max} = -\infty $. When we scan the array, if $ X_i > X_{max} $ then $ X_{max} \leftarrow X_i $. Assume that $ \forall i,j: X_i \neq X_j $.

I read a claim that the update step is executed in expectation at most $ log(m) $ times, or using the big-oh notation $ O(log(m)) $ times. I considered permutations of $ X $ but that seems to lead nowhere near a $ log(m) $ result. What approach should I use to validate the claim?

1 Answers1

3

You get an update while scanning $X_i$ if and only if $X_i = \max{(X_j, j \leq i)}$.

Since your elements are taken uniformly at random, the probability of one given element of a list of size $i$ to be the maximum of this list being $\dfrac{1}{i}$, in average, you would get $H_n = 1+\dfrac{1}{2}+...+\dfrac{1}{n}$ updates for a list of size $n$.

It happens that $H_n \approx{} \ln n$, which makes the result given correct. For more info on this, see this question on Math.SE.

Traklon
  • 2,838