Quote:Now, I am wondering how it'll be for finding a palindrome of a number?

Finding palindrome in a number is a bad idea because you have no practical tool to work on digits in a number. Number are made to work on the whole thing, like adding 2 number or multiply them.

The only practical way is having the digits in a string.

Quote:How do I think about recursion.

Recursion is only 1 way to find an answer, there is other solutions, usually with loops.

Fibonacci: you think of recursion because the definition is very recursion friendly, but recursion is not the most efficient in this case.

Recursion: F(1) is 1 call to Fibonacci function. F(2) is 1 call to Fibonacci function. F(3) is 3 call to Fibonacci function. F(4) is 5 call to Fibonacci function. F(5) is 9 call to Fibonacci function. F(6) is 15 call to Fibonacci function. F(7) is 25 call to Fibonacci function.

The high cost is that to calculate any Fibonacci value, there is more calls to the function than the result itself.

You can also use a loop and go upward.

C++

int Fibonacci(int N) { int A=1, B=1; if (N < 3) return 1; for(int Cnt=1; Cnt < N; Cnt++) { Int Tmp= A+ B; A= B; B= Tmp; } return B; }

For Fibonacci(N), it loop N times.

Palindrome: The loop approach.

Any 1 letter substring is a palindrome, say Center.

For any Center, if the letter on right is same, it is a bigger palindrome.

If letter on left and letter on right of current palindrome are same, it is a bigger palindrome.

Any palindrome of size N can be the center part of a palindrome of size N+2.