0
0
DBMS Theoryknowledge~10 mins

Candidate key finding using closure in DBMS Theory - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to compute the closure of attribute set A under functional dependencies F.

DBMS Theory
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
Drag options to blanks, or click blank then click option'
AF
BX
Cclosure
DY
Attempts:
3 left
💡 Hint
Common Mistakes
Adding X instead of Y to the closure.
Updating closure with the whole FD instead of Y.
2fill in blank
medium

Complete the code to check if attribute set A is a candidate key by comparing its closure with all attributes R.

DBMS Theory
if closure == [1]:
    print("A is a candidate key")
else:
    print("A is not a candidate key")
Drag options to blanks, or click blank then click option'
AR
BA
CF
Dclosure
Attempts:
3 left
💡 Hint
Common Mistakes
Comparing closure with A or F instead of R.
Using assignment instead of equality check.
3fill in blank
hard

Fix the error in the code that computes closure by replacing the incorrect operator.

DBMS Theory
closure = set(A)
for (X, Y) in F:
    if set(X) [1] closure:
        closure.update(Y)
Drag options to blanks, or click blank then click option'
A==
B<=
C>
D!=
Attempts:
3 left
💡 Hint
Common Mistakes
Using equality or inequality instead of subset check.
Using greater than operator which is incorrect.
4fill in blank
hard

Fill both blanks to create a dictionary comprehension that maps attribute sets to their closures.

DBMS Theory
closures = { [1]: compute_closure([2], F) for [1] in subsets(R)}
Drag options to blanks, or click blank then click option'
AX
BF
CR
Dclosure
Attempts:
3 left
💡 Hint
Common Mistakes
Using different variables for key and argument.
Using F or R incorrectly in place of the variable.
5fill in blank
hard

Fill all three blanks to filter candidate keys from all subsets by checking closure equality.

DBMS Theory
candidate_keys = [[1] for [2] in subsets(R) if compute_closure([2], F) == [3]]
Drag options to blanks, or click blank then click option'
AX
Bsubset
CR
DF
Attempts:
3 left
💡 Hint
Common Mistakes
Using different variable names inconsistently.
Comparing closure with F instead of R.