The only answer that's actually likely to be 100% correct is that it depends on your contract and local laws, talk to an IP lawyer to be sure.
My personal experience in the field leads me to believe the following:
Many contracts have clauses that say any actual work you do (i.e. code, documentation) belongs to your employer, sometimes during work hours, sometimes ALL the work you do for the duration of the contract.
Algorithmic ideas may be patented by the company or someone else, in which ownership is always clear.
If the "general idea" of an algorithm is actually covered by a patent (and it usually will be if it's written by decent patent lawyers), then it belongs to the patent-owner.
The know-how for a useful purpose of an algorithm isn't really own-able, unless it significantly deviates from the purpose of the algorithm as described in any existing patent, in which case you could conceivably get a patent for the new use, or get a license for the patented algorithm and develop a business model around it.