The question is related to databases:

There is a relation $R(A_1,A_2,...,A_n)$. Every $(n-2)$ attributes of $R$ forms candidate key. Number of superkeys of $R$ are?

I thought if any one of the $(n-2)$ attribute combinations is chosen then the number of superkeys that can be formed with it will be 4, as there will be $2^2$ combinations of remaining two attributes. So I gave answer $nC_{n-2}\times 2^2$.

But then the answer given was $nC_{n-2} + nC_{n-1}+ nC_{n}$ which is also quite obvious. But then I realized that my solution does not equate to this one and that my solution count certain superkeys more than once.

However I am not able to form an equation of the count of those duplicate superkeys so that I can subtract it from $nC_{n-2}\times 2^2$ in order to get another expression for the solution (somewhat inclusion-exclusion approach). What is that expression/equation which counts those duplicate superkeys?

  • 3
    $\begingroup$ Can you explain what is a superkey? I cannot follow your question. $\endgroup$ – Yuval Filmus Nov 5 '16 at 21:38
  • $\begingroup$ A superkey is a combination of columns that uniquely identifies any row within a relational database management system (RDBMS) table. A candidate key is a minimal superkey i.e. superkey reduced to the minimum number of columns required to uniquely identify each row. Thus adding any nonkey attribute to candidate key gives us superkey (as it looses its minimality). $\endgroup$ – anir Nov 6 '16 at 5:32
  • $\begingroup$ ohhh ohhh very sorry I miss-written $\times$ for $+$, now modified $\endgroup$ – anir Nov 6 '16 at 8:26
  • $\begingroup$ This is just basic combinatorics. Your question is only accidentally related to databases. I suggest that you adjust the tags accordingly. $\endgroup$ – André Souza Lemos Nov 6 '16 at 14:04
  • $\begingroup$ Rather than just leaving clarifications in the comments, please edit the question to include all relevant information in the question body itself. Comments exist only to help you improve the question and can disappear at any time. We want questions to be self-contained, so people don't have to read the comment thread to understand what you are asking. Thank you! $\endgroup$ – D.W. Nov 6 '16 at 18:28

The correct answer can be rewritten as $\frac{n(n-1)}{2} + n + 1$.

Let's call the two remaining attributes $A_k$and $A_l$.

You are counting each combination of $nC_{n-2}$ candidate keys four times: (1) when they are alone, (2) when they are with $A_k$, (3) when they are with $A_l$, (4) when they are with both $A_k$ and $A_l$.

Your formula then boils down to the following sum:

$nC_{n-2} + nC_{n-2} + nC_{n-2} + nC_{n-2}$

The problem is that you are counting each combination in case (2) an excessive number of times, because each $A_k$ appears in $n-2$ additional identical combinations, when it is taken as a part of the candidate key. The same is true for case (3).

There is just one singular combination in case (4), the one with all attributes.

The corrected version of you formula is then:

$nC_{n-2} + \frac{nC_{n-2}}{n-1} + \frac{nC_{n-2}}{n-1} + \frac{nC_{n-2}}{nC_{n-2}}=\frac{n(n-1)}{2} + \frac{n}{2} + \frac{n}{2} + 1=\frac{n(n-1)}{2} + n + 1$

  • $\begingroup$ damn this is so beautifully explained... $\endgroup$ – anir Nov 12 '16 at 19:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.