C++ Power Set
###### Posted by Samath
Last Updated: January 05, 2017

A Power Set is a set of all the subsets of a set.

For Example:

For the set {a,b,c}:
- These are subsets: {a}, {b} and {c}
- And these are subsets: {a,b}, {a,c} and {b,c}
- And {a,b,c} is also a subset of {a,b,c}
- And the empty set {} is a subset of {a,b,c}

```#include <iostream>
#include <string>
#include <set>
using namespace std;

#define ARRAY_SIZE(array) (sizeof((array))/sizeof((array[0])))

set<string> Pend(set<string>  s, string ss)
{
set<string>:: iterator it = s.begin();
set<string> res;
res.insert(ss);
for(it ; it != s.end(); it++)
{
string temp = *it;
res.insert(temp);
temp+= ss;
res.insert(temp);
}

return res;
}

set<string> PowerSet(set<string> s)
{
if(s.empty() || s.size() == 1)
{
return s;
}
set<string>::iterator it = s.begin();
string temp = *it;
s.erase(it);
s = PowerSet(s);
s = Pend(s,temp);
return s;
}

int main ()
{

string s[] = {"a","b","c","d","e","f"};

set<string> strs;
strs.insert(s,s+ARRAY_SIZE(s));

strs = PowerSet(strs);
set<string>::iterator it = strs.begin();
cout << "PowerSet size: " << strs.size() <<endl;
for(it; it != strs.end() ; it++)
{
cout << *it << " ";
}

return 0;
}```

###### Power Function in Python
Samath | Mar 02, 2015
###### How do you use the POWER function to raise a number to a specified power?
FrankMl | Jul 17, 2024
###### C program that determine if a number is a power of 2
Samath | Jun 03, 2015
###### C Program to find exponent Power Series
Samath | Jan 02, 2017
###### Java program that calculates the square, cube, and fourth power of a number
Samath | Feb 08, 2021
###### How do you use the FIRST_VALUE function to return the first value in an ordered set of values?
SamPetr | Jul 21, 2024
###### How do you use the LAST_VALUE function to return the last value in an ordered set of values?
OliviaWm | Jun 27, 2024
###### How do you set up Git to use SSH instead of HTTPS?
TinaGrn | Jul 17, 2024
###### How do you open a cursor to begin processing its result set?
GraceDv | Jul 22, 2024
###### How do you use the SET operators (UNION, INTERSECT, EXCEPT) in SQL?
CarolTh | Jun 18, 2024
###### How do you use the FIRST_VALUE and LAST_VALUE functions to return the first and last values in an ordered set?
MaryJns | Jun 28, 2024
###### What command lists all commits that are reachable from a set of commits, but exclude any reachable from another set?
IreneSm | Jun 24, 2024
###### How do you use the SET STATISTICS IO ON statement to display the I/O statistics for a query?
CarolTh | Jul 11, 2024
###### How do you create a table with an identity column and set the starting value?
DavidLee | Jul 16, 2024