Question

Consider a database that has the relation schema CR(StudentName,CourseName)\text{CR}(\text{StudentName}, \text{CourseName}). An instance of the schema CR is as given below.

StudentNameCourseName
SACA
SACB
SACC
SBCB
SBCC
SCCA
SCCB
SCCC
SDCA
SDCB
SDCC
SDCD
SECD
SECA
SECB
SFCA
SFCB
SFCC

The following query is made on the database:

T1←πCourseName(σStudentName=′SA′(CR))T1 \leftarrow \pi_{\text{CourseName}}(\sigma_{\text{StudentName} = '\text{SA}'}(\text{CR}))
T2←CR÷T1T2 \leftarrow \text{CR} \div T1

The number of rows in T2T2 is ______.

Official answer and solution
Official answer
4
From
Official GATE 2017 answer key

Solution

Evaluate the relational algebra expression by finding the projection of course names for student SA, then computing relational division CR÷T1CR \div T1.

The first operation finds the set of courses taken by student 'SA':

T1←πCourseName(σStudentName=′SA′(CR))T1 \leftarrow \pi_{\text{CourseName}}(\sigma_{\text{StudentName} = '\text{SA}'}(\text{CR}))

From the given table, student 'SA' is enrolled in courses: CA, CB, CC.
Thus, T1={CA,CB,CC}T1 = \{\text{CA}, \text{CB}, \text{CC}\}.

The second operation is relational division:

T2←CR÷T1T2 \leftarrow \text{CR} \div T1

By definition, CR÷T1\text{CR} \div T1 returns all students who are associated with every course in T1T1 (i.e., students who are enrolled in all three courses CA, CB, and CC).

Check each distinct student in relation CR:

  • SA: has {CA,CB,CC}  ⟹  \{\text{CA}, \text{CB}, \text{CC}\} \implies enrolled in all three   ⟹  \implies Included.
  • SB: has {CB,CC}  ⟹  \{\text{CB}, \text{CC}\} \implies missing CA   ⟹  \implies Not included.
  • SC: has {CA,CB,CC}  ⟹  \{\text{CA}, \text{CB}, \text{CC}\} \implies enrolled in all three   ⟹  \implies Included.
  • SD: has {CA,CB,CC,CD}  ⟹  \{\text{CA}, \text{CB}, \text{CC}, \text{CD}\} \implies contains all three   ⟹  \implies Included.
  • SE: has {CD,CA,CB}  ⟹  \{\text{CD}, \text{CA}, \text{CB}\} \implies missing CC   ⟹  \implies Not included.
  • SF: has {CA,CB,CC}  ⟹  \{\text{CA}, \text{CB}, \text{CC}\} \implies enrolled in all three   ⟹  \implies Included.

Therefore, T2T2 contains the 4 students: {SA,SC,SD,SF}\{\text{SA}, \text{SC}, \text{SD}, \text{SF}\}. The number of rows in T2T2 is 4.

Final answer

4.0

The answer is the one in the official GATE answer key. The solution is this site's own explanation.

Source

Paper
GATE 2017 Computer Science and Information Technology (CS) Session 1
Question
46 of 65, printed as CS Q.46
Section
Computer Science and Information Technology

Report an error in this question

GATE questions are the work of the organising institutes. This site is independent and is not affiliated with them.