how can all possible combinations of a string or an array of three unique characters be printed.suppose we have to print all possible combinations of three character a,b,c.Here's how someone did itcreate an array with contents a,b,c,a,b,c ( repeating the characters again).now print the first three characters a, b,c . Then print three characters , leaving the first character from previous list. So we print b,c,a. Then we print c,a,b. We stop it here and move back from c (not from b).So we print c , b, a , then b, a ,c then a,c,b and stop. So here they are, the three factorial combinationsabc,bca,cab,bac,acb,cba.
This is a very specific case and I dont know why this doesn't work for cases with more than three unique characters
No comments:
Post a Comment