Theory of measurement-based quantum computing