Function MAX( n, x[] ) best := x_{1} for j := 2 to n do if x_{j} > best then best := x_{j} return best
How many times is the assignment "best := x_{j}" executed?
Let A_{n} = the number of new maxima encountered.
Consider the case of n distinct numbers
in which all n! possible relative orderings are equally likely.
H_{n} ≤ 1 + ∫_{1}^{n} dx / x = 1 + ln n
H_{n} ≥ ∫_{0}^{n} dx / (x+1) = ln (n+1)
H_{n} = ln n + γ + &Theta(1/n), where γ = Euler's constant ≈ 0.577