This problem is from the book Data Structure and Algorithms Made Easy by Narasimha Karumanchi chapter Recursion and Backtracking. The algorithm which is given in the book is as follows:
Let us assume we keep current k-ary string in an array A[0...n-1]. Call function k-string(n, k)
void k-string(int n, int k) {
// process all k-ary strings of length m
if(n < 1)
printf("%s", A); // Assume array A is a global variable
else {
for(int j=0; j<k; j++){
A[n-1] = j;
k-string(n-1, k);
}
}
}
I couldn't understand the algorithm. Like why did they assigned an integer j
to a string element?