My question is what is the algorithm that a miner picks a transaction from the mempool to include it to a block?
Miners prioritize transactions based on their fee rate. The more fee rate you use for your transaction, the faster it can be included in the blockchain.
Is it a greedy algorithm which just picks the ones with highest fees? Is the "age" of a transaction in the mempool also a factor? Or is it just a combination of fee and a random choice?
It doesn't matter when you have broadcasted your transaction. It all depends on the fee rate.