In class we discussed a recursive algorithm for generating t
Solution
//pseudocode to generate power set..
//non-recursive algorithm
void printPowerSet(char set[], int size)
{
unsigned int pow_set_size = pow(2, size);///calculating the power set size...
int counter, j;//setting counter variables to generate all possible values..
//counter variable runs from 000..0 to 111..1*/
for(counter = 0; counter < pow_set_size; counter++)
{
for(j = 0; j < size; j++)
{
if(counter & (1<<j))//checking whether the jth bit in the counter is if yes then print jth element from set..
printf(\"%c\", set[j]);//printing the subset string elements...
}
printf(\"\ \");//after printing one subset...printing line
}
}
Complexity of this algorithm is: O(n2^n)//n is set size which is given
explanation:-
the outerloop runs..upto 2^setsize, means 2^n,
and inner loop runs upto given set size which is n..
hence total : n*2^n
