GATE / CS ARCHIVE

SIMILAR QUESTIONS / DATABASE MANAGEMENT SYSTEMS

Find entities with no missing required association

7 questions solved the same way, newest first. Back to Database Management Systems

How these are solved

Translate every-required-item into division or candidate×required minus actual pairs; eliminate candidates with a missing pair. Pay attention to empty required sets and the specified candidate universe.

1 mark · MSQ
Report issue

Relational Algebra & Calculus

Question 25, GATE 2022: Given Employee(eId,Name), Brand(bId,bName), Own(eId,bId), select expressions returning owners of every brand. Define O=π_eId,bId(Own), E=π_eId(Own), B=π_bId(Brand), H=π_bId(Own). Options: A π_eId(O÷B); B E−π_eId((E×B)−O); C π_eId(O÷H); D π_eId((E×H)÷B).
Tap to enlarge
Select all that apply
Answer & solution

Official answer: A,B

Our answer: A,B under the standard division candidate universe

A divides the employee-brand pairs by all brand IDs. B starts with employee IDs occurring in Own and removes those with at least one missing pair from the Cartesian product with Brand. These are the standard equivalent formulations of relational division. C divides only by brands that someone owns, potentially omitting unowned brands; D manufactures ownership pairs by a Cartesian product. Thus A, B. Boundary qualification: both A and B use π_eId(Own), not all rows of Employee, as their candidate universe. If Brand is empty and “all brands” is interpreted vacuously for every Employee, employees absent from Own are omitted. The intended nonempty-brand/owner-universe reading should be kept explicit.

For B, E×B enumerates every required owner-brand pair, and subtracting O finds missing ownerships. Projecting to eId identifies failures, which are subtracted from E. For C, one brand absent from all Own tuples is a counterexample: division by H ignores it. D can claim someone owns a brand merely because another employee owns it.

Original paper, page 20 · Answer key

2 marks · NAT
Report issue

Relational Algebra & Calculus

Question 46, GATE 2017: CR(StudentName,CourseName) contains course sets SA:{CA,CB,CC}, SB:{CB,CC}, SC:{CA,CB,CC}, SD:{CA,CB,CC,CD}, SE:{CD,CA,CB}, SF:{CA,CB,CC}. T1=πCourseName(σStudentName=SA(CR)); T2=CR÷T1. Find rows in T2.
Tap to enlarge
Answer & solution

Official answer: 4.0

Our answer: 4

1. Selection finds the rows for SA, then projection removes the student column. Thus T1 is the three-course set {CA,CB,CC}.

2. Relational division returns each student who is paired with every course in T1. Extra courses do not disqualify a student.

3. SA,SC,SD,SF contain all three. SB lacks CA; SE lacks CC. Thus T2 consists of four student names, so the answer is 4. The number of qualifying enrolment rows is not what division returns.

Original paper, page 21 · Answer key

2 marks · MCQ
Report issue

Relational division formulations

Relational Algebra & Calculus

Question 45, GATE 2009: Relations r on R={a, b, c}, s on S={c}. I=π_ab(r)−π_ab((π_ab(r)×s)−r). II={t∈π_ab(r):∀u∈s ∃v∈r(u=v[c]∧t=v[ab])}. III replaces that quantification by∀v∈r ∃u∈s with the same equality predicates. IV SELECT R.a, R.b FROM R, S WHERE R.c=S.c. Which pair is equivalent? A I/II; B I/III; C II/IV; D III/IV.
Tap to enlarge
Your answer
Answer & solution

Answer: A (no official key was published)

I begins with candidate(a, b) pairs from r and removes those for which some c in s is missing from r, exactly relational division r÷s. II expresses the same condition: for every tuple u in s there exists a tuple v in r matching both u’s c and the candidate(a, b). Thus I and II are equivalent, A, including empty s because both restrict candidates to the projection of r. III reverses the quantifiers and requires all r tuples to share the candidate pair; IV is only an existential matching join, not universal division.

Division asks for candidates paired with every c in s. Expression I constructs all required candidate/c combinations, subtracts actual tuples to find missing combinations, then removes the candidates with any missing one. II directly quantifies the same every-c requirement. A join only requires at least one matching c, so IV cannot replace division. Empty s is handled consistently because both I and II retain candidates only fromπ_ab(r), rather than introducing an infinite domain.

Original paper, page 10

2 marks · MCQ
Report issue

Relational difference detects missing female enrollments

Relational Algebra & Calculus

Question 59, GATE 2007: Relations are studInfo(studId,name,sex), keyed by studId, and enroll(studId,courseId), keyed by the pair. Every course has at least one male and one female enrollee. What does π_courseId(((π_studId(σ_sex="female"(studInfo))) × π_courseId(enroll)) − enroll) return?
Options:
(A) Courses taken by all female students
(B) Courses taken by a proper subset of female students
(C) Courses taken only by male students
(D) None of these
Tap to enlarge
Your answer
Answer & solution

Answer: B (no official key was published)

1. Approach. The Cartesian product enumerates required pairs for every female student to take every course. Subtraction identifies missing pairs, and projection asks which courses have at least one such missing pair.

2. Derivation and interpretation. Let F be the set of female student IDs and C the set of course IDs occurring in enroll. The Cartesian product F×C contains every possible female-student/course pair. Subtracting enroll leaves exactly pairs (f,c) for which female f is not enrolled in c. Projecting on courseId therefore returns courses missing at least one female student. Since the premise says every course has at least one female enrollee, these are courses whose female enrollee set is a nonempty proper subset of all female students. This is B, not courses taken by every female student.

Original paper, page 15

Report issue

Offers from every interviewed company

Relational Algebra & Calculus

Question 15(a)(ii), GATE 2002: Placement schema COMPANY(cname,clocation), STUDENT(srollno,sname,sdegree), INTERVIEW(cname,srollno,idate), OFFER(cname,srollno,osalary). Keys: cname; srollno; (cname,srollno) for each remaining relation. cname and clocation are company name and location; srollno, sname and sdegree are student roll number, name and degree program. Interviews record company/student/date; offers record salary for successful interviews. Original15(a)(ii): Using only join, selection, projection, union and difference, list roll numbers and names of interviewed students receiving an offer from every company that interviewed them.
Question 15(a)(ii), GATE 2002: Placement schema COMPANY(cname,clocation), STUDENT(srollno,sname,sdegree), INTERVIEW(cname,srollno,idate), OFFER(cname,srollno,osalary). Keys: cname; srollno; (cname,srollno) for each remaining relation. cname and clocation are company name and location; srollno, sname and sdegree are student roll number, name and degree program. Interviews record company/student/date; offers record salary for successful interviews. Original15(a)(ii): Using only join, selection, projection, union and difference, list roll numbers and names of interviewed students receiving an offer from every company that interviewed them.
Question 15(a)(ii), GATE 2002: Placement schema COMPANY(cname,clocation), STUDENT(srollno,sname,sdegree), INTERVIEW(cname,srollno,idate), OFFER(cname,srollno,osalary). Keys: cname; srollno; (cname,srollno) for each remaining relation. cname and clocation are company name and location; srollno, sname and sdegree are student roll number, name and degree program. Interviews record company/student/date; offers record salary for successful interviews. Original15(a)(ii): Using only join, selection, projection, union and difference, list roll numbers and names of interviewed students receiving an offer from every company that interviewed them.
Question 15(a)(ii), GATE 2002: Placement schema COMPANY(cname,clocation), STUDENT(srollno,sname,sdegree), INTERVIEW(cname,srollno,idate), OFFER(cname,srollno,osalary). Keys: cname; srollno; (cname,srollno) for each remaining relation. cname and clocation are company name and location; srollno, sname and sdegree are student roll number, name and degree program. Interviews record company/student/date; offers record salary for successful interviews. Original15(a)(ii): Using only join, selection, projection, union and difference, list roll numbers and names of interviewed students receiving an offer from every company that interviewed them.
Tap to enlarge
Answer & solution

Answer: π_{srollno,sname}(STUDENT ⋈ (π_{srollno}(INTERVIEW) − π_{srollno}(π_{cname,srollno}(INTERVIEW) − π_{cname,srollno}(OFFER)))) (no official key was published)

First form the interviewed company–student pairs I=π_{cname,srollno}(INTERVIEW) and offered pairs O=π_{cname,srollno}(OFFER). The difference I−O contains precisely the interviews not followed by an offer from that same company. Its student projection is the disqualified set. Therefore:
π_{srollno,sname}(STUDENT ⋈ (π_{srollno}(INTERVIEW) − π_{srollno}(I−O))).
Expanding the abbreviations gives the expression in the derived answer, using only join, projection and difference. Starting with students who appear in INTERVIEW excludes students with no interviews, rather than admitting them by vacuous truth. Receiving some offer is insufficient: every interviewed company must be covered.

Original paper, page 8

5 marks · Descriptive
Report issue

Courses with all prerequisites completed

Relational Algebra & Calculus

Question 27, GATE 1998: COURSES(Cno,name), PRE-REQ(Cno,pre-Cno), COMPLETED(student-no,Cno). Use relational algebra to list courses for which student 2310 has completed every prerequisite.
Tap to enlarge
Answer & solution

Answer: Return courses minus those with a missing prerequisite, including courses having no prerequisites. (no official key was published)

First collect completed course numbers for the selected student and rename the attribute to match the prerequisite column:
D=ρ_(pre-Cno←Cno)(π_Cno(σ_(student-no=2310)(COMPLETED))).
Let P=PRE-REQ. A natural join P⋈D contains exactly those prerequisite pairs whose prerequisite was completed. Hence Missing=P−(P⋈D) contains pairs identifying at least one uncompleted prerequisite. Project these to obtain Bad=π_Cno(Missing).

Let All=π_Cno(COURSES). Then Eligible=All−Bad, and the requested full course listing is COURSES⋈Eligible. The join uses Cno and returns each eligible course's number and name.

This construction implements 'all' by excluding counterexamples. If a course has three prerequisites and one is missing, that missing pair places it in Bad and removes it. A course with no prerequisites has no missing pair, so it remains eligible by vacuous truth. A naive division over only existing prerequisite pairs can accidentally omit such courses. Nothing in the question excludes courses already completed by the student; add that exclusion only if explicitly requested. The expression uses set relational algebra, so duplicate completion records have no effect.

Original paper, page 8

Report issue

Universal project participation by set difference

Relational Algebra & Calculus

Question 76(b)(i), GATE 1997: Relations are EMP(eno,name,age), PROJ(pno,name), and INVOLVED(eno,pno). The underlined primary keys are EMP.eno, PROJ.pno, and the composite key (eno,pno) of INVOLVED. EMP describes employees, PROJ projects, and INVOLVED employee–project participation. Use ordinary set relational algebra unless a different model is explicitly stated. In at most 15 words state what this relational-algebra expression determines:
π_eno(INVOLVED) − π_eno((π_eno(INVOLVED) × π_pno(PROJ)) − INVOLVED).
The two b-subparts together carry 4 marks; their individual marks are not printed.
Question 76(b)(i), GATE 1997: Relations are EMP(eno,name,age), PROJ(pno,name), and INVOLVED(eno,pno). The underlined primary keys are EMP.eno, PROJ.pno, and the composite key (eno,pno) of INVOLVED. EMP describes employees, PROJ projects, and INVOLVED employee–project participation. Use ordinary set relational algebra unless a different model is explicitly stated. In at most 15 words state what this relational-algebra expression determines:
π_eno(INVOLVED) − π_eno((π_eno(INVOLVED) × π_pno(PROJ)) − INVOLVED).
The two b-subparts together carry 4 marks; their individual marks are not printed.
Question 76(b)(i), GATE 1997: Relations are EMP(eno,name,age), PROJ(pno,name), and INVOLVED(eno,pno). The underlined primary keys are EMP.eno, PROJ.pno, and the composite key (eno,pno) of INVOLVED. EMP describes employees, PROJ projects, and INVOLVED employee–project participation. Use ordinary set relational algebra unless a different model is explicitly stated. In at most 15 words state what this relational-algebra expression determines:
π_eno(INVOLVED) − π_eno((π_eno(INVOLVED) × π_pno(PROJ)) − INVOLVED).
The two b-subparts together carry 4 marks; their individual marks are not printed.
Tap to enlarge
Answer & solution

Answer: Employee numbers of involved employees who participate in every project. (no official key was published)

Requested short answer: Employee numbers of involved employees who participate in every project.

This is 10 words, within the requested limit. The wording involved employees preserves the candidate domain actually used by the expression. For the derivation, let C=π_eno(INVOLVED) be the employee numbers appearing in at least one involvement row, let P=π_pno(PROJ) be all project numbers, and let R=INVOLVED.

The product C×P enumerates every employee–project pair that would be required if each candidate participated in every project. Subtracting R leaves missing pairs: a pair (e,p) remains exactly when e is a candidate, p is a project, and the participation (e,p) is absent. Projecting those missing pairs onto eno produces the candidates who fail to participate in at least one project. Finally, subtracting that set from C leaves the candidates with no missing project.

Formally, the result is {e∈C: for every p∈P, (e,p)∈R}. This is the usual division construction R÷P with its candidate universe drawn from R. For example, if P={1,2}, candidate 7 appears with both projects and candidate 8 only with project 1, the missing-pair set contains (8,2), so only 7 remains.

Two boundary details matter. EMP is not referenced, so the expression does not independently check that every eno is a valid employee if referential integrity is absent. If PROJ is empty, C×P is empty, the missing-candidate set is empty, and the result is C by vacuous truth. It is not automatically all rows of EMP; employees absent from INVOLVED are outside the candidate universe even in that empty-project case. The short answer is therefore narrower and more faithful than an unconditional claim that all employees participating in every project are returned.

Original paper, page 12