next up previous
Next: Medians and Order Statistics Up: l4 Previous: Analysis

Analysis

Thus, for all buckets,

\begin{displaymath}\sum_{i=0}^{n-1} O(E(n_i^2)) \;=\; O(\sum_{i=0}^{n-1} E(n_i^2)).\end{displaymath}



Given:



What is the probability that an element will be inserted into some bucket i?

Answer: p = 1/n.



Given n trials consisting of putting elements into buckets, how many elements will be inserted into bucket i?

$n_i$ = Binomial(n,p)
with mean $E(n_i)$ = np = 1
and variance $Var(n_i)$ = np(1-p) = 1 - 1/n
$E(n_i^2)$ = 1 - 1/n + $1^2$
= 2 - 1/n
= $\Theta(1)$



Therefore, $T_{IS}$ = $\Theta(1)$
and $T_{BS}$ = 4n + $\Theta(1)$n + 3 = O(n) for the average case. In the worst case, the run time is $n^2$.


next up previous
Next: Medians and Order Statistics Up: l4 Previous: Analysis