If you have a android phone and wondering how ads are shown based on the google search or youtube videos that you watched previously. The main reason for this is google ads. Google records all the activity that you perform and use that to show you relevant ads. If you are very particular and do not want your activity to be tracked, then you need to change your ad settings.
Login to Google Ad settings link
turn off Ads based on your interest.
If you are really not particular on this then have this option “ON”. At times you will get to see ad’s and info that you are looking for.