  We present a mathematical analysis of the Wang-Landau algorithm, prove its
convergence, identify sources of errors and strategies for optimization. In
particular, we found the histogram increases uniformly with small fluctuation
after a stage of initial accumulation, and the statistical error is found to
scale as $\sqrt{\ln f}$ with the modification factor $f$. This has implications
for strategies for obtaining fast convergence.
