The query asks for students who have enrolled in at least one course from *every* department. This is a classic 'division' problem in Relational Algebra.
Let's define the two relations needed for the division:
The set of all (student ID, department) pairs where the student has taken at least one course from that department. Let's call this
R_SD(Student-Department).R_SD = πsID, dept(Enrolled ⋋ Course)The natural join
Enrolled ⋋ Coursewill result in tuples(sID, cID, cName, dept). ProjectingsID, deptfrom this gives us exactly what we need forR_SD.The set of all distinct departments. Let's call this
R_D(Departments).R_D = πdept(Course)
Now, we want to find sIDs such that for every department in R_D, there is a corresponding (sID, dept) tuple in R_SD. This is equivalent to R_SD ÷ R_D.
The division operator R(A,B) ÷ S(B) can be simulated using other relational algebra operators as follows:
πA(R) - πA((πA(R) × S) - R)In our case, A = {sID}, R = R_SD, and S = R_D. Substituting these:
πsID(R_SD) - πsID((πsID(R_SD) × R_D) - R_SD)Let's expand R_SD and R_D back into their full expressions:
πsID( πsID, dept(Enrolled ⋋ Course) ) simplifies to πsID(Enrolled ⋋ Course). This represents all students who have enrolled in at least one course.
So the correct expression is:
πsID(Enrolled ⋋ Course) - πsID((πsID(Enrolled ⋋ Course) × πdept(Course)) - πsID, dept(Enrolled ⋋ Course))Let's analyze the options:
Option A: This perfectly matches our derived correct expression, implementing the division simulation correctly.
Option B: Uses
πsID(Student)instead ofπsID(Enrolled ⋋ Course)as the initial set of student IDs. This means it considers all students present in theStudentrelation, even those who haven't enrolled in any course. While the final subtraction might filter them out, the interpretation of "students who have enrolled" typically implies starting with the set of actually enrolled students. This makes Option A more precise for the given query.Option C: The Cartesian product part is
(πsID, dept(Enrolled ⋋ Course) × πdept(Course)). This product would result in a relation with attributes(sID, dept, dept), which is not compatible withπsID, dept(Enrolled ⋋ Course)for set difference. For the division simulation, the left part of the Cartesian product must project only the 'A' attributes (sIDin this case), making the intermediate relation(sID, dept)schema for the set difference operation.Option D: This expression
πsID(Enrolled) - πsID(Enrolled ⋋ σdept = 'Math'(Course))finds students who have enrolled in at least one course, but none of those courses are from the 'Math' department. This is a completely different query from the one asked.
Therefore, Option A is the correct Relational Algebra expression.