My PhD thesis was on the numerical simulation of the formation of clusters of galaxies, but it's not easy to give a concise answer. A useful first approximation is the so-called Zel'dovich Pancake, where on very large scales corresponding to the size of clusters of galaxies or larger, such that pressure is negligible and the gas dynamics is (to a reasonable approximation) entirely gravitational, an ellipsoidal overdensity will collapse most rapidly along its shortest axis, to form a 'pancake'. This will then collapse further to form a filament which then itself fragments to clumps that form galaxies. So the distribution of galaxies will follow the pancake/filamentary structure of the initial collapse.
However, in reality the density field is a composite of random Gaussian fluctuations at many scales and not the simple overdensity considered in the Zel'dovich Pancake, so collapse is complex and is observed at a variety of stages on different scales. Also, as an overdense region collapses the gas shock-heats to millions of Kelvin and pressure ceases to be negligible (as an aside, strong thermal X-ray emission from this gas is observed by X-ray telescopes, and as it is in hydrostatic equilibrium in the cluster gravitational potential it can be used to derive the distribution of mass). The coupled gravitational/hydrodynamic collapse is highly non-linear, and needs to be followed numerically rather than analytically - my thesis was on N-body (i.e. gravity) + Smoothed-Particle Hydrodynamics (gas dynamics) simulations of this process.
Regarding star formation, this is another extremely complex process and there are both similarities (fundamentally they are both processes governed by a balance of gravitational and gas-dynamic forces) and profound differences. However, star formation tends to be triggered - i.e supernovae in one generation of stars triggers the collapse of molecular clouds and the formation of a new generation - and so is not directly analogous.