Created
July 11, 2018 05:41
-
-
Save utgwkk/41543ab519df0a9dfcc134f5d361bbdc to your computer and use it in GitHub Desktop.
Calculating closure of functional dependencies
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fds = { | |
('A', 'B'), | |
('A', 'G'), | |
('B', 'C'), | |
('C', 'D'), | |
('BC', 'E'), | |
('CG', 'A'), | |
} | |
start = 'B' | |
output = {start} | |
while True: | |
used = set() | |
for lhs, rhs in fds: | |
lhsset = set(lhs) | |
if lhsset <= output: | |
output.add(rhs) | |
used.add((lhs, rhs)) | |
fds -= used | |
if not (fds and used): | |
break | |
print(sorted(list(output))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment