I can only tell you a little about my thinking process when it comes to figuring out certain algorithms. Most specifically, let's talk about mathematical algorithms like finding Fibonacci numbers.

First, I go through the steps that I would take to solve the problem in my head or on a sheet of paper. In this case, say I want to find the fourth Fibonacci number. I think, well, I just add 1+1+2+3 = 8. Then, I generalize my solution. I just start with 1 and 1, and then add the two preceeding numbers. Next, I formalize this generalized solution. Fib(n) = Fib(n-1) + Fib(n-2). Now, before I think I have this thing finished, I think about extreme cases. I need a special condition for Fib(1) and Fib(2). Finally, I code out a solution:

Code:

int Fib(int n)
{
if(n < 3)
return 1;
return Fib(n-1) + Fib(n-2);
}

And there you have it. I did give you the solution to finding Fibbonacci numbers, but I hope what you gain from this is the thought process. Usually, if you can think of a problem in terms of variables, you can code it. I hope this has helped you