From the content,
>Most countries don’t allow patent for a software[1]. Economic theories, methods of doing business, mathematical methods or computer programs as such are not patentable inventions in several countries.
The hyperlinked content from WIPO details about patentability of softwares/algorithm(Link doesn't seem to be working now, so including archive)
In short, in USA -
"According to the US Supreme Court , the Congress intended the statutory patentable subject matter to include anything under the sun made by man, but the laws of nature, natural phenomena and abstract ideas are three specific areas which are not patentable."
So, you can apply patent for the application of that algorithm.
[1]https://web.archive.org/web/20200213051434/https://www.wipo....
You can't do it afterwards: USA has now aligned with the rest of the World as a first-to-file patent system.
Your product, if available to the public, would be a prior art citation against your patent.
Isn't there another slight proviso, before the USPTO, that a third party disclosure is still a valid prior art citation, in the Grace Period if its source is not the applicant/inventor?
Also, outside USA (UK & Aus at least) there are specific international trade fairs that are recognised and disclosure at these gives a sort of grace period similarly to USC grace periods.
Like you say, there's account for abusive disclosure in various laws; also more countries accept grace periods for utility model patents than do for regular patents AIUI.
This is the problem with reducing complex laws to broad brush advice, lack of vital nuance; there's lots of geographic variation too.