No idea on how the algorithm works.
But basically, when you delete something from the recycle bin, it is not permanently deleted yet. It is disassociated (your file explorer on the OS can't find it) but still written on the HDD platter or solid state storage cell. The recovery software scan the disk and find them again. And metadata helps in the discovery of the lost file as well (I don't know how). You cannot recover a deleted file if you overwrite. That is why we shout at people do not write on the disk if they want things recover.