So you say it is purely a greedy algorithm?
It's not that there's a certain algorithm which miners have to follow that.
Miners are free to include any valid transaction they want. They can even include a transaction with zero fee, but they include transactions with highest fee rates to maximize their profit.
So to be precise, I'm not saying what algorithm miners
should follow. Of course miners are free to choose any transaction they want (or even censor specific ones, despite if this means a lower reward for them).
What I am asking is what algorithm miners/mining pools
typically follow.