Difference between revisions of "TADM2E 2.45"
From Algorithm Wiki
Line 5: | Line 5: | ||
To compute expected value we sum this quantity for <math>n</math>: | To compute expected value we sum this quantity for <math>n</math>: | ||
− | <math>\sum_{i= | + | <math>\sum_{i=1}^{n} \frac{1}{i}</math> |
and recognize this as the definition of the <math>n^{th}</math> <i>Harmonic number</i> | and recognize this as the definition of the <math>n^{th}</math> <i>Harmonic number</i> |
Revision as of 13:11, 24 July 2020
The expected number of times the assignment to tmp is made is the sum of the probabilities that the $ n^{th} $ element is the minimum. If we assume the minimum is distributed uniformly in our sequence then the probability any given element is the minimum is $ 1/n $.
Expected time is E(n) = E(n-4) + 1/n, E[1] = 0
To compute expected value we sum this quantity for $ n $:
$ \sum_{i=1}^{n} \frac{1}{i} $
and recognize this as the definition of the $ n^{th} $ Harmonic number
$ H(n) = \sum_{i=1}^{n} \frac{1}{i} \sim \ln n $
so our expected value approaches $ \ln n $ as $ n $ grows large.
Return to Algo-analysis-TADM2E