1. This problem can be easily resolved with a recursive function:
Set combination(Sequence s) {
Set result = empty set;
if( ! s.isEmpty()) {
Char c = s.head;
Sequence tail = s.tail;
Set temp = combination(tail);
retult = c union temp;
}
return result;
}
2. Let S be the sentence stored in an array of words;
Let W be the additional variable that can hold a word;
Let i = 1; and j = S.length; // we do not count i and j for they are scale variables
while( i < j ) {
W = S[i];
S[i] = S[j];
S[j] = W;
i = i+1;
j = j - 1;
}
Set combination(Sequence s) {
Set result = empty set;
if( ! s.isEmpty()) {
Char c = s.head;
Sequence tail = s.tail;
Set temp = combination(tail);
retult = c union temp;
}
return result;
}
2. Let S be the sentence stored in an array of words;
Let W be the additional variable that can hold a word;
Let i = 1; and j = S.length; // we do not count i and j for they are scale variables
while( i < j ) {
W = S[i];
S[i] = S[j];
S[j] = W;
i = i+1;
j = j - 1;
}