How to obtain a minimal key from functional dependencies?

旧时模样 提交于 2019-12-04 07:23:01

There is a well known algorithm to do this. I don't remember it, but the excercise seems to be simple enough not to use it.

I think this is all about transitivity:

CurrentKey = {A, B, C, D, E, F}

You know D determines E and E determines F. Hence, D determines F by transitivity. As F doesn't determine anything, we can remove it and as E can be obtained from D we can remove it as well:

CurrentKey = {A, B, C, D}

As AB determines C and C doesn't determine anything we know it can't be part of the key, so we remove it:

CurrentKey = {A, B, D}

Finally we know A determines D so we can remove the latter from the key:

CurrentKey = {A, B}

If once you have this possible key, you can recreate all functional dependencies it is a possible key.

PS: If you happen to have the algorithm handy, please post it as I'd be glad to re-learn that :)

sfjaef

Algorithm: Key computation (call with x = ∅)

procedure key(x;A;F)
foreach  ! B 2 F do
if   x and B 2 x and B ̸2  then
return; /* x not minimal */
fi
od
if x+ = A then
print x; /* found a minimal key x */
else
X   any element of A 􀀀 x+;
key(x [ fXg;A;F);
foreach  ! X 2 F do
key(x [ ;A;F);
od
fi
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!