Complete the code to compute the closure of attribute set A under functional dependencies F.
closure = set(A) changed = True while changed: changed = False for (X, Y) in F: if set(X).issubset(closure) and not set(Y).issubset(closure): closure.update([1]) changed = True
The closure of A is expanded by adding attributes Y from functional dependencies X -> Y when X is a subset of the closure.
Complete the code to check if attribute set A is a candidate key by comparing its closure with all attributes R.
if closure == [1]: print("A is a candidate key") else: print("A is not a candidate key")
A candidate key's closure must include all attributes in the relation R.
Fix the error in the code that computes closure by replacing the incorrect operator.
closure = set(A) for (X, Y) in F: if set(X) [1] closure: closure.update(Y)
To check if X is a subset of closure, use the subset operator <=.
Fill both blanks to create a dictionary comprehension that maps attribute sets to their closures.
closures = { [1]: compute_closure([2], F) for [1] in subsets(R)}The comprehension iterates over subsets of R using variable X and computes closure for each X.
Fill all three blanks to filter candidate keys from all subsets by checking closure equality.
candidate_keys = [[1] for [2] in subsets(R) if compute_closure([2], F) == [3]]
We iterate over subsets named subset, check if their closure equals R, and collect those subsets as candidate keys.