Interview Questions

Preparing sets from a given array with min complexity.........

Microsoft Interview Questions and Answers


(Continued from previous question...)

127. Preparing sets from a given array with min complexity.........

Question:
Preparing sets from a given array with min complexity.
S1=1,2,3,4,5
stes = {1},{2},{3},{4}..{1,2},{1,3}..{1,2,3,4,5}



maybe an answer:

complexity 2^n*(logn +1). 2^n we cant avoid but can we avoid additional logn factor???

int main ()
{
char set [] = {'a','b','c'};
int setSize = 3; /*As per above array*/
int totalSubset = 1<<3;
int i,j,k;
printf ("{{}");
for (i = 1; i < totalSubset; i++)
{
printf("{");
k=i;
j = 0;
while (k)
{
if (k&1)
{
printf ("%c", set[j]);
}
j ++;
k = k>>1;
}
printf ("}");
}
printf ("}\n");
}

(Continued on next question...)

Other Interview Questions