So you say it is purely a greedy algorithm?
Note that it's not that there's a certain algorithm which miners have to follow that.
Miners are free to include any transaction they want and there's nothing prevent them from including a transaction with zero fee, but they always try to maximize their profit with picking transactions with highest fee rates.