zh's answer is very good.

I just want to add, for completeness, that for molecular systems, as referenced several times on this forum already, the absolute zero energy is the vacuum level meaning the effective potential very far away from the molecule.

Moreover, referring to your question about the "algorithm", as zh so correctly points out, the Fermi level is determined in such a way, that when you use the corresponding Fermi-Dirac occupations for all the molecular levels, the total charge sums up to the total number of electrons in the system. The value of the Fermi level, thus determined is numerically unique for a given set of molecular levels. (Note, however, that we have a slightly different set of such levels in each iteration of the SCF cycle, and thus the Fermi level is one of those quantities that needs to be determined self-consistently.)

From a more physical point of view, the Fermi level can be seen as an energy that lies between the occupied and unoccupied states, and thus can lie anywhere in the HOMO-LUMO gap (this is the same for semiconductors, so it's not special for molecules).