The interview problem

Practice prompt

A sampling algorithm moves between states 0 and 1 with transition matrix P = [[0.7, 0.3], [0.2, 0.8]]. Find its stationary distribution and determine whether its distribution converges from a fixed initial state. Then analyze deterministic alternation, an absorbing state and a chain that changes only rarely. Is a small change between consecutive distributions enough to declare convergence?

Original fundamentals practice, not a reported company interview. Examples and calculations are original. Primary lecture references retrieved September 27, 2026; interview date not applicable.

1. State the conventions and assumptions

Work with a finite, discrete-time, time-homogeneous Markov chain. P(i,j) is the probability of moving from i to j in one step. Each row is nonnegative and sums to one. Represent a distribution as a row vector, so μ at the next step is μP.

A stationary distribution π satisfies πP = π, has nonnegative entries and sums to one. Starting with π preserves that marginal distribution at every step. This alone says neither that samples are independent nor that every other starting distribution converges to π.

For finite chains, irreducibility guarantees a unique stationary distribution; adding aperiodicity guarantees convergence to it from any initial distribution. These are sufficient conditions. Irreducibility is not necessary for uniqueness, as an absorbing example below shows. Do not transfer finite-state conclusions to an infinite state space without checking additional recurrence conditions.

2. Solve balance and normalization together

Write π = (a, 1 − a). For the stated matrix, the first coordinate of πP = π gives:

a = 0.7a + 0.2(1 − a)
a = 0.5a + 0.2
0.5a = 0.2
a = 0.4

π = (0.4, 0.6)
πP = (0.4 × 0.7 + 0.6 × 0.2,
      0.4 × 0.3 + 0.6 × 0.8)
   = (0.4, 0.6)

The off-diagonal flows also balance: 0.4 × 0.3 = 0.6 × 0.2 = 0.12. This pairwise balance holds for this example. General stationarity requires total incoming probability to match each state's mass; it does not require pairwise detailed balance for every chain.

An eigenvector calculation is incomplete until normalization, sign and orientation are checked. With row distributions, π is a left eigenvector. A right eigenvector corresponding to eigenvalue one can simply be the all-ones vector and is not generally the desired probability distribution.

3. Derive convergence from the initial state

Let aₙ be the probability of state 0 after n transitions, starting at state 0. Then a₀ = 1 and:

aₙ₊₁ = 0.7aₙ + 0.2(1 − aₙ) = 0.2 + 0.5aₙ
aₙ₊₁ − 0.4 = 0.5(aₙ − 0.4)
aₙ = 0.4 + 0.6(0.5)ⁿ

For two distributions on two states, total variation distance equals the absolute difference in their first coordinates: half the sum of the two absolute coordinate differences. Thus:

TV(μₙ, π) = 0.6(0.5)ⁿ
TV(μ₁₀, π) = 0.0005859375

The marginal distribution approaches π. An individual trajectory does not settle permanently into a fixed state: transitions keep occurring. Both states communicate, and self-transitions make this irreducible chain aperiodic. The explicit recurrence also proves convergence directly for the specified start.

4. A unique stationary distribution need not be a limit

Replace the matrix with Q = [[0, 1], [1, 0]]. Every step flips the state. The stationary equation swaps the coordinates, so the unique stationary distribution is (0.5, 0.5).

starting distribution μ₀ = (1, 0)
μ₁ = (0, 1)
μ₂ = (1, 0)
μ₃ = (0, 1)
...
TV(μₙ, π) = 0.5 for every n

The chain is irreducible but has period two. Return times to either state are even. Its one-time marginal does not converge from this fixed starting state, despite uniqueness of π.

If the initial state is instead drawn from π, every marginal remains π. The path still alternates perfectly: knowing one state determines the next. Stationary does not mean independent.

Along either alternating path, the fraction of visits to state 0 approaches one half. Over an even number of observations it is exactly one half; over an odd number the discrepancy is at most one divided by twice that number. This time-average result is compatible with nonconvergence of the distribution at an individual late time. These are different quantities.

5. Reducibility does not always destroy uniqueness

Consider R = [[1, 0], [0.25, 0.75]]. State 0 is absorbing, while state 1 can reach 0 and never return. The chain is reducible. Nevertheless, if b is stationary mass on state 1, its balance equation is b = 0.75b, so b = 0. The unique stationary distribution is (1, 0).

Starting at state 1, the probability of still being there after n transitions is 0.75ⁿ. Hence the distribution converges to (1, 0). The transient state does not carry stationary mass.

Contrast the identity matrix I = [[1, 0], [0, 1]]. Both states are absorbing, so every distribution is stationary. Starting at either state keeps the chain there. There is no single initial-state-independent limit.

ExampleUnique stationary law?Converges to that law from every start?
P: 0.3 and 0.2 cross-state probabilitiesYes, (0.4, 0.6)Yes
Q: deterministic flipYes, (0.5, 0.5)No
R: one absorbing stateYes, (1, 0)Yes
I: two absorbing statesNo; every distributionNo common limit

Inspect closed communicating classes rather than treating “reducible” as synonymous with “many stationary distributions.”

6. Add a self-loop without changing the invariant law

A lazy version of a transition matrix is L = (I + P)/2. It chooses an explicit stay-put action with probability one half and otherwise applies P, which may itself stay put. Thus its total self-transition probability is (1 + P(i,i))/2. If πP = π, then:

πL = (πI + πP)/2 = (π + π)/2 = π

The converse follows by rearranging πL = π, so this construction preserves the set of stationary distributions. For the deterministic flip Q, the lazy matrix has both rows equal to (0.5, 0.5); any starting distribution reaches that law in one step.

In a finite irreducible chain, the added self-loops remove periodicity. They do not connect disconnected classes. Nor do they guarantee fast mixing: a chain with a difficult bottleneck can remain slow, and adding waiting can slow movement in an already aperiodic chain. Preserving a target distribution and reaching it quickly are separate objectives.

7. A small residual can conceal a large error

Now use S = [[0.999, 0.001], [0.001, 0.999]]. Its stationary law is (0.5, 0.5). Starting at state 0, the same recurrence method gives:

aₙ₊₁ = 0.001 + 0.998aₙ
aₙ = 0.5 + 0.5(0.998)ⁿ
TV(μₙ, π) = 0.5(0.998)ⁿ

To reduce this distance to at most 0.01:

0.5(0.998)ⁿ ≤ 0.01
n ≥ log(0.02) / log(0.998)
minimum integer n = 1,955

At the very start, the total variation distance between μ₀S and μ₀ is only 0.001. But μ₀ is 0.5 away from π. A stopping rule that accepts a one-step change of 0.002 would stop immediately with a large distributional error.

For this example, the one-step residual at any n is 0.002 times the distance to π. The small transition probability creates the misleading residual. Residual size needs a conditioning or mixing argument before it can bound error. The factor 0.998 arises from this explicit two-state recurrence; it is not a universal eigenvalue-only mixing bound for arbitrary nonreversible chains.

8. Use a computation workflow that checks structure

validate stochastic matrix and row/column convention
                    ↓
identify communicating classes and closed classes
                    ↓
solve stationary equations + normalization
                    ↓
check nonnegativity and residual
                    ↓
analyze periodicity and convergence from relevant starts
                    ↓
assess mixing at the accuracy needed for the application

For a small matrix, solve the constrained linear system directly. For a large sparse matrix, iterative multiplication may be cheaper, but periodicity and slow mixing can defeat naive power iteration. A normalized numerical vector with a small residual is useful evidence, not a universal certificate of accuracy.

Starting multiple runs from different states can reveal a problem but does not prove its absence. An empirical transition matrix with tiny unobserved probabilities rounded to zero may appear to have disconnected classes. Conversely, adding smoothing creates transitions and can change the modeled stationary distribution. Document whether the matrix is a known algorithmic kernel or an estimate from finite data.

9. Connect the distinction to ML sampling

For a sampler, first establish that its transition rule preserves the intended target. Then check whether the chain can explore the target's support and whether it mixes sufficiently for the quantities being estimated. An invariant target is not enough when initialization confines the chain to a closed subset.

Even a chain initialized at stationarity can produce highly dependent samples. This guide concerns the marginal distribution and its limiting behavior; estimating uncertainty in an average also requires accounting for dependence. Discarding a universal fixed number of initial samples does not solve every chain's initialization problem.

If transitions adapt over time, a proof for one fixed P no longer directly describes the actual sequence of kernels. Similarly, a business transition model whose behavior changes seasonally may not have a useful single time-homogeneous stationary law. Check the modeling assumptions before interpreting a solved vector as a forecast.

Failure analysis and follow-ups

  • “I found an eigenvector, so the simulation converges.” Check normalization, class structure and periodicity; the flip chain disproves the conclusion.
  • “The chain is reducible, so the stationary law cannot be unique.” The one-absorbing-state example disproves this. Count the closed classes.
  • “The histogram is stable, so late-time marginals converge.” The alternating path separates time averages from single-time distributions.
  • “Adding self-loops solves mixing.” It addresses periodicity under the stated conditions, not disconnected support or every bottleneck.
  • “Consecutive iterates barely move, so we are close.” The slow chain starts with a small residual and a large error.
  • “Can these results be used on infinitely many states?” Only after checking the relevant additional assumptions; finite-state existence and recurrence shortcuts no longer suffice.

Self-review rubric

A strong answer defines its matrix convention, solves balance with normalization and separates invariance from convergence. It explains the periodic counterexample and does not mistake irreducibility for a necessary condition for uniqueness. An excellent answer derives a convergence rate, diagnoses a misleading residual, distinguishes time averages from marginals and states what lazification preserves.

Sources and attribution

Retrieved September 27, 2026. The worked matrices, calculations and interview framing are original practice. All convergence claims here use the stated finite-state setting unless explicitly qualified; no company interview attribution is claimed.

Continue your preparation

Choose a connected learning path or browse more ML fundamentals questions. Read our editorial method and attribution policy.