edited by
35,758 views
137 137 votes

Information about a collection of students is given by the relation $\text{studInfo(}\underline{\text{studId}},\text{ name, sex)}$. The relation $\text{enroll(}{\text{studId}},{\text{ courseId}})$ gives which student has enrolled for (or taken) what course(s). Assume that every course is taken by at least one male and at least one female student. What does the following relational algebra expression represent?

$\pi _{courceId}\left(\left(\pi_{\text{studId}}\left(\sigma_{sex='female'}\left(\text{studInfo}\right)\right) \times \pi_{courseId}\left(\text{enroll}\right)\right) -\text{enroll}\right)$

  1. Courses in which all the female students are enrolled.
  2. Courses in which a proper subset of female students are enrolled.
  3. Courses in which only male students are enrolled.
  4. None of the above

15 Answers

Best answer
122 122 votes

$$\overset{\underline{\text{STUDENTINFO}}}{\begin{array} {c c c } 1 & A & M \\ 2 & A & F \\ 3 & A & F \end{array}} \qquad \qquad \overset{\underline{\text{ENROLL}}} {\begin{array} {c c } 1 &  C1 \\ 1 & C2 \\ 2 & C1 \\ 2 & C2 \\ 3 & C2 \end{array}}$$

  • $\pi _{courceId}(\sigma_{sex=“female"}(\text{studInfo} ))\times \pi_{courseId}\left(\text{enroll}\right)$ $$\implies \begin{array} {c c } 2 &  & C1 &  \\  & \ast  &  \\ 3 &  & C2  \end{array} = \begin{array} {c c } 2 &  C1 \\ 2 & C2 \\ 3 & C1 \\ 3 & C2  \end{array}$$
  • $(\pi _{studId}(\sigma_{sex=“female"}(\text{studInfo})) \times \pi_{courseId}(\text{enroll})) -\text{enroll})$ $$\implies \begin{array} {c c } 3 &  C1 \end{array}$$
  • $\pi _{courceId}((\pi _{studId}(\sigma_{sex=“female"}(\text{studInfo})) \times \pi_{courseId}(\text{enroll})) -\text{enroll})$ $$\implies C1$$

$C1$ is a course id in which not all girl students enrolled.
i.e. a proper subset of girls students appeared.

Hence (B) is the correct answer.

edited by
35 35 votes

Ans is b, 

First it does a cross join between female students id and all course ids,  then subtract the entries which are already present in enroll table.

Remaining are the courseids which are NOT done by at least one female student

16 16 votes

Ans is B, 

1. (Female students id) Natural JOIN (All course ids in which at-least one student enroll i.e. taken from enroll),  

2. Subtract the entries which are already present in enroll table. ( which are nothing but in which female enrolls).

Remaining are the tupple in which female student are not enroll for every course (i.e. female students with atleast one course in which she not enroll actually) which is always proper subset of all enrolled course.

14 14 votes

@saket   you missed out something ..lets take an example...

studid name sex
1 a f
2 b f
3 c m
4 d m

here if apply inner most query which gives studid whichhave sex =female so we get id no {1,2).,now cross product between {1,2}and course id {c1,c2} which gives four tuple 

stuid course id
1 c1
1 c2
2 c1
2 c2

enroll table

stdid course id
1 c1
1 c2
3 c1
4 c2
2 c1

now we have to perform intermediate table which gives crosse product of female id and course id - enroll which gives {2,c2} so c2 is course id which is not enrolled by id no 2 female so we can se option b is correct... 

now c is wrong becoz each course should be enrolled by atleast one m and f. and option a will be correct if we get c1 course id which is enrolled by all female but we get course id c2 from above query so only option b is correct...

edited by
6 6 votes
The best approach is ..draw a table with 4-5 tuples and keep on doing what the query says ..at the end match the resultant table with the options i got option b
4 4 votes
What the cartesian product actually doing is, it taking the studentId of "female" student from studInfo relation, and performing the cartesian product with all courses that are available... so it will return the all possible combination of "female" student can enroll in various courses.. Now finally we are subtracting "enroll" from it.. "enroll" relation contain what actually enrollment has been done.. so the substraction will return the "courseId" a "female student has not been enrolled..!!

because, ( all possible enrollment in various course of female) - ( actual enrollment) = courses in which female enrollment has not happened!!...

Option (b) is saying "female student which are enrolled (proper Subset)".. No but it is returning  courses in which female student are NOT enrolled!!.. so option (D)
Answer:
Position:
Show:

Related questions

69 69 votes
9 answers 9 answers
37.7k
37.7k views
Kathleen asked Sep 21, 2014
37,661 views
The order of a leaf node in a $B^+$ - tree is the maximum number of (value, data record pointer) pairs it can hold. Given that the block size is $1K\;\text{bytes}$, data ...
41 41 votes
7 answers 7 answers
14.2k
14.2k views
Kathleen asked Sep 21, 2014
14,192 views
Consider the following schedules involving two transactions. Which one of the following statements is TRUE?$S_1 :r_1(X); r_1(Y); r_2(X); r_2(Y); w_2(Y); w_1(X)$$S_2 :r_1(...
122 122 votes
8 answers 8 answers
43.7k
43.7k views
Kathleen asked Sep 21, 2014
43,697 views
Which one of the following statements is $\text{FALSE}$?Any relation with two attributes is in $\text{BCNF}$A relation in which every key has only one attribute is in $\t...
109 109 votes
7 answers 7 answers
42.3k
42.3k views
Kathleen asked Sep 21, 2014
42,297 views
Consider the table employee(empId, name, department, salary) and the two queries $Q_1, \, Q_2$ below. Assuming that department $5$ has more than one employee, and we want...