  To perform efficient many-body calculations in the framework of the exact
diagonalization of the Hamiltonian one needs an appropriately tailored Fock
basis built from the single-particle orbitals. The simplest way to compose the
basis is to choose a finite set of single-particle wave functions and find all
possible distributions of a given number of particles in these states. It is
known, however, that this construction leads to very inaccurate results since
it does not take into account different many-body states having the same energy
on equal footing. Here we present a fast and surprisingly simple algorithm for
generating the many-body Fock basis build from many-body Fock states having the
lowest non-interacting energies. The algorithm is insensitive to details of the
distribution of single-particle energies and it can be used for an arbitrary
number of particles obeying bosonic or fermionic statistics. Moreover, it can
be easily generalized to a larger number of components. Taking as a simple
example the system of two ultra-cold bosons in an anharmonic trap, we show that
exact calculations in the basis generated with the algorithm are substantially
more accurate than calculations performed within the standard approach.
