Skip to content
Official PYQ · 2017

GATE CS 2017 Set 1 Q46 — Relational Model: Relational Algebra

Explain with AI

Consider a database that has the relation schema CR(StudentName, CourseName). An instance of the schema CR is as given below.
StudentNameCourseNameSACASACBSACCSBCBSBCCSCCASCCBSCCCSDCASDCBSDCCSDCDSECDSECASECBSFCASFCB SFCC\begin{array}{|c|c|} \hline \textbf{StudentName} & \textbf{CourseName} \\ \hline \text{SA} & \text{CA} \\ \hline \text{SA} & \text{CB}\\ \hline \text{SA} & \text{CC} \\ \hline \text{SB} & \text{CB} \\ \hline \text{SB}& \text{CC} \\ \hline \text{SC} & \text{CA}\\ \hline \text{SC}&\text{CB} \\ \hline \text{SC} & \text{CC} \\ \hline \text{SD} & \text{CA} \\ \hline \text{SD} & \text{CB}\\ \hline \text{SD} & \text{CC} \\ \hline \text{SD} & \text{CD} \\ \hline \text{SE}& \text{CD} \\ \hline \text{SE} & \text{CA}\\ \hline \text{SE}&\text{CB} \\ \hline \text{SF}& \text{CA} \\ \hline \text{SF} & \text{CB }\\ \hline\text{SF} & \text{CC} \\ \hline \end{array}
The following query is made on the database.

  • T1←πCourseName(σStudentName=SA(CR))T1 \leftarrow \pi _{CourseName}\left ( \sigma _{StudentName=SA}\left ( CR \right ) \right )
  • T2←CR÷T1T2 \leftarrow CR\div T1

The number of rows in T2T2 is ______________ .

View worked solution

Answer: 4

To find the number of rows in T2T2, let us evaluate the relational algebra operations step-by-step.

Step 1: Evaluate T1T1

The query for T1T1 is:

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

This selects all courses taken by the student SA. Looking at the relation CRCR, the courses associated with SA are:

  • CA
  • CB
  • CC

Thus, T1={CA,CB,CC}T1 = \{\text{CA}, \text{CB}, \text{CC}\}.

Step 2: Evaluate T2T2

The query for T2T2 is:

T2←CR÷T1T2 \leftarrow CR \div T1

The division operator (CR÷T1CR \div T1) finds all StudentName values in CRCR that are associated with every CourseName present in T1T1. In other words, we need to find students who have registered for at least all three courses: CA, CB, and CC.

Let's list the set of courses taken by each student in CRCR:

  • SA: {CA,CB,CC}\{\text{CA}, \text{CB}, \text{CC}\} — Contains T1T1
  • SB: {CB,CC}\{\text{CB}, \text{CC}\} — Does not contain T1T1
  • SC: {CA,CB,CC}\{\text{CA}, \text{CB}, \text{CC}\} — Contains T1T1
  • SD: {CA,CB,CC,CD}\{\text{CA}, \text{CB}, \text{CC}, \text{CD}\} — Contains T1T1
  • SE: {CA,CB,CD}\{\text{CA}, \text{CB}, \text{CD}\} — Does not contain T1T1
  • SF: {CA,CB,CC}\{\text{CA}, \text{CB}, \text{CC}\} — Contains T1T1

The students who satisfy the condition are SA, SC, SD, and SF.

Therefore, the relation T2T2 is:

StudentNameSASCSDSF\begin{array}{|c|} \hline \textbf{StudentName} \\ \hline \text{SA} \\ \hline \text{SC} \\ \hline \text{SD} \\ \hline \text{SF} \\ \hline \end{array}

The number of rows in T2T2 is 4.

Free practice · Your answers on this page are not saved.

Published
Report a correction
Keep exploringMore Relational Model: Relational Algebra questions