data-structures · beginner · ~15 min
Count subsets recursively (2^n).
Implement:
long long power_set_size(int n);
Return the number of subsets of an n-element set (2^n), computed recursively. 0 <= n <= 62.
n in [0,62].
2^n.
Use long long.
#include <stddef.h>
/* Size of the power set of an n-element set = 2^n, computed recursively. 0<=n<=62. */
long long power_set_size(int n){ (void)n; return 0; }
Wrong base case (2^0 is 1, not 0).
The empty set has exactly 1 subset (itself).
Solve this exercise in the browser editor — compile and run against the test harness, no setup required.