How Many Samples Does a Monte Carlo Estimate of Pi Need

Last updated: November 29, 2026

Quick Overview

You estimate pi by drawing uniform points in the unit square and counting those inside the quarter circle. How many samples are needed for a 95% confidence interval of half-width 0.001, and how would you reduce that number?

MathWorks
Statistics & Math
Software Engineer
MathWorks
November 29, 2026
Software Engineer
Technical Screen
Statistics & Math
Medium

0

0

0 solved


You estimate pi by drawing uniform points in the unit square and counting those inside the quarter circle. How many samples are needed for a 95% confidence interval of half-width 0.001, and how would you reduce that number?

Monte Carlo is a staple in MATLAB examples and Statistics and Machine Learning Toolbox workflows, and MathWorks interviewers use this classic to see whether you can move from a simulation to a sample size calculation. They check the Bernoulli variance, the CLT interval, and awareness of variance reduction.

What the Interviewer Expects
  • Identifies the estimator as 4 times a Bernoulli proportion with p = pi/4
  • Derives its standard error correctly
  • Solves for n from the CI half-width
  • Explains the 1/sqrt(n) convergence and its practical cost
  • Proposes at least one variance reduction technique
Key Topics to Cover
Monte Carlo estimation
Bernoulli variance
central limit theorem
sample size
variance reduction
How to Approach This
  1. Define your hypotheses (H0 and H1) clearly before performing any test.
  2. Calculate required sample size BEFORE running an experiment, using power analysis.
  3. Remember the Central Limit Theorem: sample means become approximately normal with large n.
  4. Watch for Simpson's paradox. Always segment data by key dimensions.
  5. Distinguish between statistical significance and practical significance.
Possible Follow-up Questions
  • How much would antithetic or stratified sampling cut the required n in this problem?
  • How would you produce the estimate in MATLAB in a vectorized way without running out of memory at 10 million samples?
  • Quasi-Monte Carlo with a Sobol sequence converges faster. What rate, and how would you get an error bar for it?
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Browse Statistics Questions
Sample Answer
Clarify

Each sample (x,y)∼U[0,1]2(x, y) \sim U[0,1]^2 gives I=1I = 1 if x2+y2≤1x^2 + y^2 \le 1, so p=P(I=1)=π/4≈0.7854p = P(I = 1) = \pi/4 \approx 0.7854. The estimator is π^=4Iˉ\hat\pi = 4 \bar I. We want 1.96⋅SE(π^)≤0.0011.96 \cdot SE(\hat\pi) \le 0.001....

Approach

Compute the variance of one indicator, scale by 4 and by 1/n1/n, apply the normal approximation (valid here because n will be huge), and solve for n....


Submit Your Answer
Markdown supported

Related Questions