I have a Relational Schema with attributes (A B C D). I have a set of Functional Dependencies with me too.
Now I need to determine the closure for all the possible subsets of R's attributes. That's where I am stuck. I need to learn how to find subsets (non-repeating) in PHP.
My Array is stored like this.
$ATTRIBUTES = ('A', 'B', 'C', 'D').
so my subsets should be
$SUBSET = ('A', 'B', 'C', 'D', 'AB', 'AC', AD', 'BC', 'BD', 'CD', 'ABC', 'ABD', 'BCD', 'ABCD')
The code shouldn't be something big but for some reason I can't get my head around it.
You wish for the power set of
$attributes
? That is what your question implies.An example can be found here (quoted for completeness)
Using php array_merge we can have a nice short powerSet function
Here a backtracking solution.
given a function that returns all the L-lenght subsets of the input set, find all the L-lenght subsets from L = 2 to dataset input length