could (in principle) analyze the working of the algorithm in order to calculate the chance p of getting the identity permutation. Then we can say that the number of permutations equals 1/*p*.

But now suppose we have a hard counting problem for which we cannot find an explicit formula for |*S*|. The purpose of this chapter is to describe a remarkable technique for constructing randomized algorithms that count *S approximately*. This technique, developed in recent years, has two ingredients. The first idea is that in some settings, having an algorithm for generating an *approximately* uniform random element of *S* can be used re-cursively to estimate *approximately* the size |*S*|. We illustrate this with two examples in the next section. The second idea is that we can obtain an approximately uniform random element of *S* by running a suitable Markov chain on state-space *S* for sufficiently many steps. This idea and the particular chains used in the two examples are discussed in §3.3. The latter idea is fundamentally similar to the use of Markov chains in the Metropolis algorithm, which underlies the simulated annealing algorithm discussed in Chapter 2. The difference is that here we seek to simulate a *uniform* distribution rather than a distribution that is deliberately biased towards minima of a cost function. Our Markov chains are simpler to analyze and permit rigorous discussion of polynomial-time convergence issues that seem too hard for rigorous treatment in the context of simulated annealing.

**Example: Volume of a Convex Set (Dyer et ah, 1989, 1991).** Consider the problem of estimating the volume vol(*K*) of a convex set *K* in *n*-dimensional space, for large *n*. Suppose we are told that , where *B*(*r*) is the ball of radius *r* = *r*(*n*). It is believed that there is no polynomial-time deterministic algorithm to approximate vol(*K*). But suppose we have a means of simulating, at unit cost, a random point in *K* whose distribution is approximately uniform. Specify some subset *K*_{1} with and for which vol(*K*_{1})/vol(*K*) is not near 0 or 1. Then by simulating *m* random points in *K* and counting the proportion *p*(1) that fall within *K*_{1},

Now specify a decreasing sequence of such convex subsets