i did a dry run on this code and didnt find the significance of mk array ...
so i did remove it from the code ..
and the code works fine ..
i more thing ... the code repeats same palindromes as in incase of ABA baa
is coming twice..
correct me if i am wrong ...
On Fri, Jul 29, 2011 at 10:47 AM,
void printPerm(char *s,int i ,int len){
if( i == len){
printf(%s\n,s);
return ;
}
int j ;
char t ;
char h[26] ;
memset(h,'0',26);
for(j = i ; j len ; j++ ){
if(h[s[j]-'a'] == '0'){
h[s[j]-'a'] = '1' ;
t = s[i] ; s[i] = s[j] ; s[j] =
i more thing ... the code repeats same palindromes as in incase of ABA baa
is coming twice..
Put back mk array in place and baa won't be repeated.
The idea is that out of all available options for filling a particular
position in our partial solution at each round of backtracking we
choose for
The seen array filters out the characters which are available for
filling a particular position.
The mk array makes sure that we choose only one of the repeated
characters.
for example,
if the array is aba
if mk array is there backtracking will try like
String : a _ _ or b _ _
there was an typo,
if mk array is *not* there backtracking will try like
On Jul 29, 7:13 pm, amit karmakar amit.codenam...@gmail.com wrote:
The seen array filters out the characters which are available for
filling a particular position.
The mk array makes sure that we choose only one of the
What my recursive solution does is that,
For all elements that can be used at position *k*, fix that element at
position *k* and then permute the rest of the elements.
So if are two same elements which can be used at position *k* we must
choose only one of it to avoid repeated permutations.
Array
@amit:i am not clear about the code.Maybe could you take your example string
aabc and explain a few steps that happen from your code??.The array mk is
locally created for each function call and so I do not get how it keeps
track of elements tried cos each time it is a new array.
On Fri, Jul 29,