They take into account many factors, in order to decide which sites get ‘top billing’ and it is not easy to know how they make their decisions. SEO Book has produced an infographic explaining important things about how Google do their job.
It is to be noted that search engines frequently update their processes - but this gives a clear idea of important issues.
So here is an infograpic about how Google works:
Online Marketing Graphic by SEO Book