What is the difference between backtracking and recursion? How is this program working?
void generate_all(int n)
{
if(n<1) printf("%s\\n", ar);
Recursion is like a bottom-up process. You can solve the problem just by using the result of the sub-problem.
For example, reverse LinkedList using recursion is just appending a head node on the already reversed sublist.https://leetcode.com/problems/reverse-linked-list/discuss/386764/Java-recursive
Backtracking is still like a top-down process. Sometimes you can't solve the problem just by using the result of the sub-problem, you need to pass the information you already got to the sub-problems. The answer(s) to this problem will be computed at the lowest level, and then these answer(s) will be passed back to the problem with the information you got along the way.