What Will Be The Time Complexity Of The Following Codep Pre #1178
What will be the time complexity of the following code?</p> <pre><code class="language-c"> #include <stdio.h> #include <math.h> void PowerSet(char *set, int set_size) { unsigned int pow_size = pow(2, set_size); int count, j; for(count = 0; count < pow_size; count++) { for(j = 0; j < set_size; j++) { if(count & (1<<j)) printf("%c", set[j]); } printf(","); } } int main() { char strset[] = {'a','b','c'}; PowerSet(strset, 3); return 0; } </code></pre>
This multiple choice question (MCQ) is related to the book/course gs gs122 Data Communication and Computer Network. It can also be found in gs gs122 Number Theory - Generating Subsets - Quiz No.1.
What will be the time complexity of the following code?
#include <stdio.h> #include <math.h> void PowerSet(char *set, int set_size) { unsigned int pow_size = pow(2, set_size); int count, j; for(count = 0; count < pow_size; count++) { for(j = 0; j < set_size; j++) { if(count & (1<<j)) printf("%c", set[j]); } printf(","); } } int main() { char strset[] = {'a','b','c'}; PowerSet(strset, 3); return 0; }
O(n 2n)
O(n2)
O(n log n)
O(2n) (n is the size of set)
Similar question(s) are as followings:
Online Quizzes of gs122 Data Communication and Computer Network
Sorting - Insertion Sort - Quiz No.1
gs gs122 Data Communication and Computer Network
Online Quizzes
Sorting - Insertion Sort - Quiz No.2
gs gs122 Data Communication and Computer Network
Online Quizzes
Sorting - Insertion Sort - Quiz No.3
gs gs122 Data Communication and Computer Network
Online Quizzes
Sorting - LSD Radix Sort - Quiz No.1
gs gs122 Data Communication and Computer Network
Online Quizzes
Sorting - MSD Radix Sort - Quiz No.1
gs gs122 Data Communication and Computer Network
Online Quizzes
Sorting - MSD Radix Sort - Quiz No.2
gs gs122 Data Communication and Computer Network
Online Quizzes