I've learnt about C++ algorithms before, but until now I still can't use most of them properly in my coding, and there are some topics that I just can't comprehend, such as recursion.
I've read Introduction to Algorithms, but it hasn't helped me at all. Is there a book that can help me?
If you don't understand recursion you'll have a hard time comprehending most data structures.
Any tree or graph, for instance, is a recursive structure by definition.
before buying an expensive book, use the internet a bit. See if you can get your head around recursion.
Most recursion is used to combine a loop with 'exploiting' the call stack as a 'free' data structure combined with a "base case" that can be solved without recursion.
Consider the silly factorial example. The base case is that fact(1) = 1.
The recursive definition of the function is that fact(n) = n*fact(n-1) unless n is 1, if n is 1 the answer is fact(1) = 1.
so for 3, it will compute 3*(fact(2)
for 2 it will compute 2 * fact (1)
for 1 it will compute 1 and return.
the return will multiply back in (continues where it left off in the previous call) and determine that 2*1 = 2. The 2 will return back and 3*2 = 6, and its all done. The intermediate results would be pushed onto the program call stack (but here, the compiler may just turn it into a loop for performance reasons). But conceptually they would be.
Start with that. See if you can understand it, code it, and get it working.
... learnt about C++ algorithms before, but until now I still can't use most of them properly in my coding ...
if its the C++ algorithms from the standard library that you're referring to then try 'The C++ Standard Library (2nd ed)' by N Josuttis, specifically Chapter 11 'STL Algorithms'
Link to his website: http://cppstdlib.com/
Thanks for all the suggestions! However, I'm currently searching for a book that teaches algorithms that appear in competitive programming in a foolproof way. Is there one like this?
@jonnin I can understand the factorial example and code it, but beyond that? No.