title: Backtrack in any programming language
body: <p>I was given a task of writing a program for string permutation.  I understand the logic, but not the exact meaning of the <code>Backtrack</code> in this program.  Please explain the for-loop functionality, when <code>swap</code> will be called, when <code>permutate()</code> will be called, and the exact meaning of backtrack.</p>
  
  <pre><code># include &lt;stdio.h&gt;
  
  
  void swap (char *x, char *y)
  {
      char temp;
      temp = *x;
      *x = *y;
      *y = temp;
  }
  
  
  void permute(char *a, int i, int n) 
  {
     int j; 
     if (i == n)
       printf("%s\n", a);
     else
     {
          for (j = i; j &lt;= n; j++)
         {
            swap((a+i), (a+j));
            permute(a, i+1, n);
            swap((a+i), (a+j)); //backtrack
         }
     }
  } 
  
  
  int main()
  {
     char a[] = "ABC";  
     permute(a, 0, 2);
     getchar();
     return 0;
  }
  </code></pre>