Search code examples
sqlfunctional-dependenciescandidate-key

finding largest number of candidate keys that a relation has?


I am trying to solve this question which has to do with candidate keys in a relation. This is the question:

    Consider table R with attributes A, B, C, D, and E. What is the largest number of
candidate keys that R could simultaneously have?

the answer is 10 but i have no clue how it was done, nor how does the word simultaneously plays into effect when calculating the answer.


Solution

  • Sets that are not subsets of other sets.
    For example {A-B} and {A,B,C} can't be candidates keys simultaneously, because {A,B} is a subset of {A,B,C}.
    Combinations of 2 attributes or 3 attributes generates the maximum number of simultaneous candidates keys.
    See how the 3 attributes sets are actually complements of the 2 attributes sets, e.g. {C,D,E} is the complement of {A,B}.

             2               3    
         attributes      attributes
           sets            sets
    
       1.  {A,B}    -     {C,D,E}
       2.  {A,C}    -     {B,D,E}
       3.  {A,D}    -     {B,C,E}
       4.  {A,E}    -     {B,C,D}
                    -     
       5.  {B,C}    -     {A,D,E}
       6.  {B,D}    -     {A,C,E}
       7.  {B,E}    -     {A,C,D}
                    -     
       8.  {C,D}    -     {A,B,E}
       9.  {C,E}    -     {A,B,D}
                    -     
       10. {D,E}    -     {A,B,C}
    

    If I would take sets of a single attribute I would have only 4 options

    {A},{B},{C},{D}
    

    Any set with more than 1 element will contain one of the above and therefore will not be qualified.

    If I would take sets of 4 attributes I would have only 4 options

    {A,B,C,D},{A,B,C,E},{A,B,D,E},{B,C,D,E}
    

    Any set with more than 4 element will contain one of the above and therefore will not be qualified. Any set with less than 4 element will be contained by one of the above and therefore will not be qualified.

    etc.