Merging of galaxies in an expanding universe