It doesn’t even need to figure out what a search query is worth and price it accordingly. It simply holds an auction for every search query entered, at the moment the query occurs. The net result is that billions of times a day, Google runs an auction of keywords and accompanying bids. By looking at the bid, and estimating the likelihood of a click, Google takes the product of the two (which is how much it will make per query) and picks the highest. Then it displays the associated ad that the advertiser has created and uploaded to Google for that keyword.