According to the official United States copyright website:
Copyright does not protect facts, ideas, systems, or methods of operation, although it may protect the way these things are expressed.
An algorithm falls under this statement. It may protect the way the algorithm is expressed, the main example being code, but it cannot protect the algorithm itself, as an algorithm falls under being an idea, fact, system, or method of operation.
For more elaboration, according to the BBC:
Copyright covering algorithms can only be applied once the programmer converts the algorithm into source code. The copyright of the source code can be used to protect that code from being copied, but will not prevent others from independently creating their own source code which does the same thing.
Based on what this says, you can definitely use any algorithm, but the code can't be a direct copy of the original source code if such code exists. It must be made by you, but it can still legally use the same basic algorithm.