I want to calculate power set of string array (consider it as a set). When I am exceeding above 26 elements it is thowing out of memory exception.
List<int> ff = new List<int>();
double length = Math.Pow(2, 29);
for (int i = 0; i < length; i++)
{
ff.Add(1);
}
Above code will produce the that exception if you run it. The size of the set may go up to 1000. So the size of power set of that set will be 2^1000.
How can I deal with this?
EDIT:
I know that above code is not a function of power set. I was just checking how big array c# will be able to hold.
private static Dictionary<int, object> PowerSetB(string[] input)
{
int n = input.Length;
// Power set contains 2^N subsets.
int powerSetCount = 1 << n;
var ans = new Dictionary<int, object>();
for (int setMask = 0; setMask < powerSetCount; setMask++)
{
var s = new ArrayList();
for (int i = 0; i < n; i++)
{
// Checking whether i'th element of input collection should go to the current subset.
if ((setMask & (1 << i)) > 0)
s.Add(input[i]);
}
ans[setMask] = s;
}
return ans;
}
Above code is my function of power set.
Thank you in advance.