Hi,
A common application for recursion is the problem of generating all possible permutations of a set of symbols. For the se consisting of symbols A,B and C there exists six permutations - namely, ABC, ACB, BAC, BCA, CBA and CAB. The set of permutations of N symbols is generated by taking each symbol in turn and prefixing it to all the permutations which result from the remaining N-1 symbols. It is therefore, possible to specify the permutations of a set of symbols in terms of permutations of a small set of symbols. How to write a recursive function program for generating all possible permutations of a set of symbols using C#.
This is very urgent, Plz help
shine

A common application for recursion
Sree2000
give him my name. . . I am always looking for work. . . I also know how to google
permutation +recursion +algorithm
Gary Eldridge
Hmm...looks a lot like an assignment I was given back when I was in College.
Perhaps if you can tell us more about the 'real world' problem that you are trying to apply this to, we can give you some help.
Mebbage
CharlesJ
Here is the class. A eral world example searcher for all records with the name "John Pat Doe" and you want to ensure that you get all of the records regardless how the name is in the record.
class Permutation : IDisposablepublic
{
private int[] data = null; private int order = 0; private Permutation(int y){
this.data = new int{
this.data[x] = x;}
this.order = y;}
public Permutation(){
}
public static object[] Permutate(string arg, string delimiter){
string result = string.Empty; string[] s; object[] res; string ss;System.Collections.
ArrayList list = new System.Collections.ArrayList();s = (arg).Split(delimiter.ToCharArray());
if (s.Length == 1){
list.Add(s[0]);
}
else{
res =
new object[s.Length]; Permutation perm = new Permutation(s.Length); while (perm != null){
res = perm.ApplyTo(s);
ss =
string.Empty; for (int x = 0; x < s.Length; x++){
ss += res[x].ToString() + delimiter;
}
list.Add(ss.TrimEnd(delimiter.ToCharArray()));
perm = perm.Successor();
}
}
return list.ToArray();}
private object[] ApplyTo(object[] arr){
if (arr.Length != this.order) return null; object[] result = new object[arr.Length]; for (int i = 0; i < result.Length; ++i){
result[x] = arr[
this.data[x]];}
return result;}
// ApplyTo() private Permutation Successor(){
Permutation result = new Permutation(this.order); int left, right; for (int k = 0; k < result.order; ++k) // Step #0 - copy current data into result{
result.data[k] =
this.data[k];}
left = result.order - 2;
// Step #1 - Find left value while ((result.data[left] > result.data[left+1]) && (left >= 1)){
--left;
}
if ((left == 0) && (this.data[left] > this.data[left+1])) return null;right = result.order - 1;
// Step #2 - find right; first value > left while (result.data[left] > result.data[right]){
--right;
}
int temp = result.data[left]; // Step #3 - swap [left] and [right]result.data[left] = result.data[right];
result.data[right] = temp;
int x = left + 1; // Step #4 - order the tail int j = result.order - 1; while (i < j){
temp = result.data[x];
result.data[x++] = result.data[j];
result.data[j--] = temp;
}
return result;}
// Successor()#region
IDisposable Members public void Dispose(){
// TODO: Add Permutation.Dispose implementation}
#endregion
}
// class PermutationAbhi Win
BrendanGrant
Sean Laberee