GATE / CS ARCHIVE

SUBJECT COLLECTION

Database Management Systems · Relational Algebra & Calculus

52 questions, newest first

GATE CSE has asked 52 questions on Relational Algebra & Calculus (Database Management Systems) from 1991 to 2026, in 30 of the 46 papers; the most recent is in GATE CSE 2026 Set 1. In the last five years it carried 1 marks per 100-mark paper on average, against 1.2 since 2003. Since 2014 the questions have been 9 MCQ, 3 NAT and 1 MSQ. 2 groups of questions here are solved the same way; “One per method” keeps the newest of each.

Browse topics
Show
2 marks · MCQ
Report issue

Translating existential joins into relational algebra

Relational Algebra & Calculus

Question 43, GATE 2026: Relations are R(P,Q) and S(X,Y). The query returns u whenever there exist v,w with (u,v) in R and (v,w) in S. Select the equivalent projection/join expression. The alternatives join P to X, Q to X, P to Y, or Q to Y, and all project P.
Tap to enlarge
Your answer
Answer & solution

Official answer: B

Givens and goal

Relations are R(P,Q) and S(X,Y). The query returns u whenever there exist v,w with (u,v) in R and (v,w) in S. Select the equivalent projection/join expression. The alternatives join P to X, Q to X, P to Y, or Q to Y, and all project P.

Approach

Map each quantified variable to its relation attribute, use the repeated variable as the join equality, and project the requested output coordinate.

Step-by-step solution

1. Membership (u,v)∈R means u=R.P and v=R.Q. Membership (v,w)∈S means v=S.X and w=S.Y.
2. The same variable v occurs in both tuples, so qualifying tuple pairs must satisfy R.Q=S.X. This is the equijoin condition; neither R.P nor S.Y is the repeated coordinate.
3. After joining, the query asks only for u. Since u is R.P, project attribute P from the join. Thus the expression is π_P(R ⋈_(R.Q=S.X) S).
4. Option B writes the operands in the reverse order, π_P(S ⋈_(S.X=R.Q) R), which is equivalent for this inner equijoin and projection. Therefore select B.
5. For example, R containing (a,7) and S containing (7,b) must produce a. The two 7 values are the ones that need to match. Joins equating P with X, P with Y, or Q with Y would impose a different condition. The existential variables v and w disappear from the output through projection; ordinary relational algebra uses set semantics here.

Original paper, page 32 · Answer key

2 marks · MCQ
Report issue

Building a relational-calculus join

Relational Algebra & Calculus

Question 39, GATE 2025: Relations are teams(tid,tname) and players(pid,pname,tid). Return names of players on a team named MI. A {p.pname | p∈players ∧ ∃t(t∈teams ∧ p.tid=t.tid ∧ t.tname='MI')}; B the same expression but p∈teams and t∈players; C the expression in A without p.tid=t.tid; D the expression in B without p.tid=t.tid. Which is correct?
Tap to enlarge
Your answer
Answer & solution

Official answer: A

Approach: Translate the desired result into tuple bindings, a join predicate, a selection predicate and a projected attribute.
A returned name must come from a player tuple, so bind p to players. There must exist a team tuple t whose id equals the player’s team id, giving t∈teams and p.tid=t.tid. The selected team must have t.tname='MI'. Project p.pname from precisely those player tuples. These requirements combine exactly as A.
B and D bind p to teams even though teams has no pname attribute, and bind t to players even though players has no tname attribute. They are not correctly typed for the supplied schemas.
C has the right bindings but omits the join. If any team is called MI, its existential condition becomes true for every player, including players on other teams. That illustrates why a selection on team name does not replace the relationship connecting a player to that team.

Original paper, page 39 · Answer key

1 mark · NAT
Report issue

Enumerate an equijoin before selection

Relational Algebra & Calculus

Question 35, GATE 2024: R(A,B) has rows (10,20),(20,30),(30,40),(30,50),(50,95). S(A,C) has rows (10,90),(30,45),(40,80). Join R and S on equal A values, then keep rows with B<C. How many tuples remain?
Tap to enlarge
Answer & solution

Official answer: 2

Approach: First match rows using the join condition, then test the selection condition for each resulting pair.
1. At A=10, R's B=20 matches S's C=90. The equijoin row is (R.A,B,S.A,C)=(10,20,10,90), and 20<90 is true. Below, write the equal A columns once as shorthand (A,B,C).
2. At A=30, there are two R rows and one S row. They produce (30,40,45) and (30,50,45). The first passes 40<45; the second fails 50<45.
3. R's A=20 and A=50 rows find no matching S row. S's A=40 row finds no R partner. An ordinary inner equijoin does not retain these unmatched rows.
4. The join therefore creates three tuples, of which exactly two survive the B<C filter.
Answer: 2. Repeated A values in R must not be collapsed: each matching row contributes its own joined tuple before selection.

Original paper, page 21 · Answer key

2 marks · MCQ
Report issue

Witness three distinct residents with two products

Relational Algebra & Calculus

Question 45, GATE 2024: Person(pid,city) has a unique pid per person. Using only selection, projection, cross product and rename, how many cross-product operations are minimally required to find cities with at least three residents? A 1; B 2; C 3; D 4.
Tap to enlarge
Your answer
Answer & solution

Official answer: B

Approach: Introduce one independently chosen tuple for each person that must be witnessed.

1. Derivation. Rename three copies P1, P2, P3 of Person and take their product using two binary cross products. Select equal cities and pairwise distinct pids, then project the city. This identifies exactly cities with at least three residents. With only one cross product, selection/projection/rename can expose at most two independently chosen source tuples, which cannot witness a third distinct person. Thus the minimum is 2, option B, in the stated algebra without aggregation or other operators.

2. Explanation and checks. Write P1×P2×P3 as (P1×P2)×P3. Select P1.city=P2.city=P3.city and P1.pid≠P2.pid, P1.pid≠P3.pid, P2.pid≠P3.pid, then project P1.city. All three inequalities are necessary to prevent a two-person city from reusing one person. Rename, selection and projection do not introduce an additional independently chosen resident. This lower-bound argument assumes the stated relational algebra expression model, not a materialized intermediate relation supplied from outside the expression.

Original paper, page 31 · Answer key

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 · MCQ
Report issue

Relational Algebra & Calculus

Question 27, GATE 2021: empAge(empNo,age) stores ages of 500 employees, with empNo a key. Evaluate π_empNo(empAge ⋈_[age>age1] ρ_[empNo1,age1](empAge)). A employee numbers with maximum age only; B those older than exactly one other employee; C all those whose age is not minimum; D all those with minimum age.
Tap to enlarge
Your answer
Answer & solution

Official answer: C

The renamed second copy supplies another employee’s age. The theta join retains a first-copy employee whenever some other row has a strictly smaller age. Projecting empNo therefore returns exactly employees whose age is not the minimum. Minimum-age ties are all excluded. Thus C.

The join is existential after projection: an employee appears if there exists any employee of smaller age. An employee of minimum age has no such witness and is excluded, even if multiple employees tie for minimum. For ages 20,20,30,40 the output contains the 30- and 40-year-old employee numbers. The 40-year-old has several witnesses, but set projection removes duplicates; it is not restricted to 'exactly one' younger employee.

Original paper, page 24 · Answer key

2 marks · NAT
Report issue

Projecting and subtracting joined relations

Relational Algebra & Calculus

Question 55, GATE 2019: Relations: P(X,Y,Z)={(X1,Y1,Z1),(X1,Y1,Z2),(X2,Y2,Z2),(X2,Y4,Z4)}; Q(X,Y,T)={(X2,Y1,2),(X1,Y2,5),(X1,Y1,6),(X3,Y3,1)}; R(Y,V)={(Y1,V1),(Y3,V2),(Y2,V3),(Y2,V2)}. Count tuples in π_X(σ_{P.Y=R.Y and R.V=V2}(P×R)) − π_X(σ_{Q.Y=R.Y and Q.T>2}(Q×R)).
Tap to enlarge
Answer & solution

Official answer: 1

1. Evaluate the two projected sets separately before subtracting them. The left selection is an equality join on Y with the additional restriction R.V=V2.
2. Restricting R to V2 leaves (Y3,V2) and (Y2,V2). P has no Y3 tuple and has exactly one Y2 tuple, (X2,Y2,Z2). Thus the left join contributes X2 and its projection is {X2}. P's Y1 and Y4 rows fail the selection.
3. On the right, first keep Q rows with T>2: (X1,Y2,5) and (X1,Y1,6). The rows with T=2 and T=1 are excluded by the strict inequality.
4. The surviving Y2 row matches two R rows, with V3 and V2; the Y1 row matches (Y1,V1). These three join tuples all carry X1. Relational-algebra projection removes duplicates, so the right projected set is {X1}, not three copies of X1.
5. Set difference keeps left-side tuples absent from the right side: {X2}−{X1}={X2}. The result contains exactly 1 tuple.
6. Difference is directional and is not subtraction of the two row counts. Also, relational algebra uses set projection here; SQL without DISTINCT would require separate attention to bag semantics.

Original paper, page 16 · Answer key

2 marks · MCQ
Report issue

Selection and left outer join

Relational Algebra & Calculus

Question 41, GATE 2018: Relations r(A,B),s(B,C) have no nulls; s.B is primary and r.B foreign key to s.B. Q=r⋈σ_(B<5)(s). Which differs? A σ_(B<5)(r⋈s); B σ_(B<5)(r LOJ s); C r LOJ σ_(B<5)(s); D σ_(B<5)(r) LOJ s.
Tap to enlarge
Your answer
Answer & solution

Official answer: C

Method

An enforced non-null foreign key means each r tuple initially has exactly one matching s tuple. Consequently an unfiltered left outer join has no unmatched left tuples and behaves like an inner join. Applying the filter on r first also guarantees all its retained tuples match. Filtering only the right input before an outer join changes this: left tuples whose matches were filtered out still survive with null extension. This is why moving a predicate across an outer join requires more care than across an inner join.

Solution

Every r tuple has a matching s tuple by the non-null foreign key. Thus the unfiltered natural left join equals the inner join, and filtering B<5 before or after it gives the same matched rows. In C, filtering s first removes matches for r rows with B≥5, but the left join preserves those r rows with null-extended C. Q discards them instead. For example r={(a, 6)}, s={(6, c)} makes Q empty while option C retains(a, 6, NULL). Hence C alone is not equivalent.

Original paper, page 17 · Answer key

2 marks · MCQ
Report issue

Relational Algebra & Calculus

Question 41, GATE 2017: EMP(EmpId,EmpName,DeptId), DEPT(DeptName,DeptId); EMP.DeptId may be NULL. Which tuple-calculus queries are safe?
I {t | ∃u∈EMP (t[EmpName]=u[EmpName] ∧ ∀v∈DEPT (t[DeptId]≠v[DeptId]))}
II {t | ∃u∈EMP (t[EmpName]=u[EmpName] ∧ ∃v∈DEPT (t[DeptId]≠v[DeptId]))}
III {t | ∃u∈EMP (t[EmpName]=u[EmpName] ∧ ∃v∈DEPT (t[DeptId]=v[DeptId]))}
A I and II; B I and III; C II and III; D all three. No range restriction t∈EMP is printed.
Tap to enlarge
Your answer
Answer & solution

Official answer: D

Our answer: Only III under unrestricted-domain TRC; official D under active-domain restriction

1. Safety requires finite results independent of arbitrary values outside the database. The free result tuple t is not explicitly restricted to EMP; only t.EmpName is equated to an employee name in I and II.

2. Use one employee Alice with DeptId 1 and one department with DeptId 1. For every value z outside the database, t=(Alice,z) satisfies I: z differs from every department ID. It also satisfies II because the existing department ID 1 differs from z. Infinitely many z are possible in an unrestricted domain.

3. III instead equates t.EmpName to an EMP name and t.DeptId to a DEPT ID, bounding both fields by finite stored values. Therefore only III is classically safe, but that option is missing. Official D requires an unstated finite active-domain interpretation. Allowing NULL in EMP neither binds t nor removes the counterexample.

Original paper, page 18 · 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 Algebra & Calculus

Question 40, GATE 2015: R1(A, B)={(1, 5), (3, 7)}, R2(A, C)={(1, 7), (4, 9)}. Full natural outer join candidates a(1, 5, NULL), b(1, NULL, 7), c(3, NULL, 9), d(4, 7, NULL), e(1, 5, 7), f(3, 7, NULL), g(4, NULL, 9). A a, b, e, f, g not c, d; B all seven; C e, f, g not a, b; D e but not f, g.
Tap to enlarge
Your answer
Answer & solution

Official answer: C

Matching A=1 yields(1, 5, 7). Unmatched left row gives(3, 7, NULL); unmatched right row gives(4, NULL, 9). Only e, f, g occur, C. Matched rows do not additionally produce null-padded variants.

Join on the common attribute A. The A=1 rows match and produce one combined row(1, 5, 7), without extra null-padded versions. The A=3 left row has no right match, so retain it as(3, 7, NULL). The A=4 right row has no left match, so retain it as(4, NULL, 9). Values from different unmatched keys cannot be combined into(3, NULL, 9)or(4, 7, NULL). Thus e, f, g are the complete result.

Original paper, page 40 · Answer key

1 mark · MCQ
Report issue

Relational Algebra & Calculus

Question 21, GATE 2014: Simplify π_A1(π_A2(σ_F1(σ_F2(r)))), where A1⊂A2 are attribute sets of r and F1,F2 are predicates on r. A π_A1(σ_(F1∧F2)(r)); B π_A1(σ_(F1∨F2)(r)); C π_A2(σ_(F1∧F2)(r)); D π_A2(σ_(F1∨F2)(r)).
Tap to enlarge
Your answer
Answer & solution

Official answer: A

Step 1: A row survives the two selections only if it satisfies both predicates, so σ_F1(σ_F2(r))=σ_(F1∧F2)(r). An OR would admit rows discarded by one selection. Step 2: Projecting onto A2 and then its subset A1 is equivalent to projecting directly onto A1, because the intermediate projection retains every finally requested attribute. Step 3: Combining these rules gives π_A1(σ_(F1∧F2)(r)), A. Keep the final output attributes A1; replacing them with A2 changes the query.

Original paper, page 57 · Answer key

2 marks · MCQ
Report issue

Relational Algebra & Calculus

Question 30, GATE 2014: Schemas: employee(empId,empName,empAge) and dependent(depId,eId,depName,depAge), with eId referencing employee.empId. Every employee has at least one dependent. Interpret π_empId(employee)−π_empId(employee ⋈_(empId=eId ∧ empAge≤depAge) dependent). It returns employees older than A some dependent; B all dependents; C some of their own dependents; D all of their own dependents.
Tap to enlarge
Your answer
Answer & solution

Official answer: D

Step 1: The join condition first pairs each employee only with that employee's own dependents. Its age condition selects counterexamples to “employee is older”: a dependent whose age is at least the employee's age. Step 2: Projecting empId collects employees with at least one such counterexample. Subtracting this set from all empIds keeps employees with none. Step 3: No own dependent is as old or older means the employee is strictly older than every own dependent, D. The nonempty-dependent premise prevents vacuous cases; ordinary relational algebra here assumes comparable, non-NULL ages.

Original paper, page 59 · Answer key

2 marks · MCQ
Report issue

Equivalent SQL and relational-calculus queries

Relational Algebra & Calculus

Question 35, GATE 2013: Schemas: Students(rollno, sname), Courses(courseno, cname), Registration(rollno, courseno, percent). Desired result is distinct student names scoring>90 in course 107. I SQL SELECT DISTINCT S.sname FROM Students S, Registration R WHERE R.rollno=S.rollno AND R.courseno=107 AND R.percent>90. II relational projection sname after selecting courseno107 and percent>90 from Registration natural-join Students. III tuple calculus {T:∃S∈Students,∃R∈Registration(S.rollno=R.rollno∧R.courseno=107∧R.percent>90∧T.sname=S.sname)}. IV domain calculus {<SN>:∃SR∃RP(<SR, SN>∈Students∧<SR, 107, RP>∈Registration∧RP>90)}. Which equivalent queries? A all four; B I, II, III; C I, II, IV; D II, III, IV.
Tap to enlarge
Your answer
Answer & solution

Official answer: A

Each expression joins a student to a registration on roll number, requires course 107 and percent>90, and returns the student name. SQL DISTINCT and set-valued relational algebra/calculi remove duplicate names. Hence all four are equivalent, A, with the tuple-calculus output T understood to have the displayed single sname attribute.

All four forms bind the same join witness: a student row and a registration row with equal rollno, course 107 and percent greater than 90. SQL DISTINCT removes duplicate names; relational projection and calculus use set semantics. The Courses table is not needed because filtering uses its numeric course identifier, not its name. In IV, SR is the shared roll number, SN is the returned name, and RP is the qualifying percentage. In III, the result tuple is understood to have just the sname attribute, matching the projected result schema.

Original paper, page 8 · Answer key

2 marks · MCQ
Report issue

Foreign-key inclusion constraint

Relational Algebra & Calculus

Question 43, GATE 2012: Let r1 and r2 be instances of R1(A,B) and R2(C,D). B is a foreign key referencing C, and referential integrity holds. Which is always true? π denotes projection.
(A) π_B(r1)−π_C(r2)=∅ (B) π_C(r2)−π_B(r1)=∅ (C) π_B(r1)=π_C(r2) (D) π_B(r1)−π_C(r2)≠∅.
Tap to enlarge
Your answer
Answer & solution

Official answer: A

In the classical relational model used by the relational-algebra expression, every B value in r1 must occur as a C value in r2. Thus π_B(r1) is a subset of π_C(r2), and π_B(r1)−π_C(r2)=∅, A. Referenced C values need not all occur in B, so equality and reverse containment are not guaranteed. This is the textbook non-null relational interpretation; SQL nullable foreign keys require separate treatment of NULL.

Check: For a concrete permitted instance, r1 may reference only C=1 while r2 contains C=1 and C=2. Then the forward difference is empty but the reverse difference contains 2. Referenced rows may exist even when no row currently references them.

Original paper, page 10 · Answer key

2 marks · MCQ
Report issue

Set union followed by disjunctive theta join

Relational Algebra & Calculus

Question 50, GATE 2012: Relations: A(Id,Name,Age)={(12,Arun,60),(15,Shreya,24),(99,Rohit,11)}; B(Id,Name,Age)={(15,Shreya,24),(25,Hari,40),(98,Rohit,20),(99,Rohit,11)}; C(Id,Phone,Area)={(10,2200,02),(99,2100,01)}.
How many tuples result from (A∪B) ⋈_{A.Id>40 OR C.Id<15} C? The union has the schema of A.
(A) 7 (B) 4 (C) 5 (D) 9.
Question 50, GATE 2012: Relations: A(Id,Name,Age)={(12,Arun,60),(15,Shreya,24),(99,Rohit,11)}; B(Id,Name,Age)={(15,Shreya,24),(25,Hari,40),(98,Rohit,20),(99,Rohit,11)}; C(Id,Phone,Area)={(10,2200,02),(99,2100,01)}.
How many tuples result from (A∪B) ⋈_{A.Id>40 OR C.Id<15} C? The union has the schema of A.
(A) 7 (B) 4 (C) 5 (D) 9.
Tap to enlarge
Your answer
Answer & solution

Official answer: A

Relational union eliminates the two shared tuples (15, Shreya, 24) and (99, Rohit, 11), leaving five distinct tuples with Id values 12, 15, 25, 98, 99. For C.Id=10, the condition C.Id<15 is true, so all five join. For C.Id=99, only the two union tuples with Id>40 join. There are 5+2=7 result tuples, A. This is a theta join, so each qualifying pair contributes its combined tuple.

Check: The pair count can also be checked from the union side: Ids 12,15,25 each match only C.Id=10, contributing three; Ids 98,99 each match both C rows, contributing four. The total 3+4=7 agrees with counting from the C side.

Original paper, page 14 · Answer key

2 marks · MCQ
Report issue

Maximum natural-join cardinality

Relational Algebra & Calculus

Question 43, GATE 2010: Relations R(A,B,C) and S(B,D,E) obey B→A and A→C in R. R contains 200 tuples and S contains 100 tuples. What is the maximum possible cardinality of their natural join R⋈S?
Options: (A) 100; (B) 200; (C) 300; (D) 2000.
Tap to enlarge
Your answer
Answer & solution

Answer: A (no official key was published)

Within R(A,B,C), B→A and A→C imply B→ABC, so B is a key under relational set semantics. In the natural join on common attribute B, each of the 100 tuples of S(B,D,E) matches at most one R tuple. Therefore the join has at most 100 tuples. This bound is attainable by choosing all S.B values among the 200 R.B values, so A. The cardinality of R does not multiply each S row because B is unique in R.

The bound is attained, for example, by choosing 100 S rows whose B values all occur in R, with distinct D,E as needed. Every S row then contributes exactly one join row. Different S rows may share a B value without violating any stated dependency, but none can match two R rows because B determines every attribute of R. This is a many-to-one join from S to R.

Original paper, page 10

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

1 mark · MCQ
Report issue

Universal relational-calculus condition

Relational Algebra & Calculus

Question 15, GATE 2008: Which tuple-calculus expressions equal ∀t∈r P(t)? I: ¬∃t∈r P(t). II: ∃t∉r P(t). III: ¬∃t∈r ¬P(t). IV: ∃t∉r ¬P(t).

(A) I only
(B) II only
(C) III only
(D) III and IV only
Tap to enlarge
Your answer
Answer & solution

Answer: C (no official key was published)

1. A universal statement fails exactly when there is a counterexample. Here a counterexample is a tuple t in r for which P(t) is false.
2. Excluding every such counterexample gives ¬∃t∈r ¬P(t), which is III.
3. I instead says no tuple satisfies P; II and IV discuss tuples outside r. Therefore III only, C.

Original paper, page 4

2 marks · MCQ
Report issue

Equivalent relational-algebra projections

Relational Algebra & Calculus

Question 68, GATE 2008: R(P,Q,R1,R2,R3) and S(P,Q,S1,S2) each have key {P,Q}. Which relational-algebra queries are equivalent? ⋈ denotes natural join. I: πP(R⋈S). II: πP(R)⋈πP(S). III: πP(πP,Q(R)∩πP,Q(S)). IV: πP(πP,Q(R)−(πP,Q(R)−πP,Q(S))).

(A) I and II only
(B) I and III only
(C) I,II,III only
(D) I,III,IV only
Tap to enlarge
Your answer
Answer & solution

Answer: D (no official key was published)

1. The natural join matches both common attributes P and Q. Consequently I returns P values of pairs (P,Q) appearing in both relations, exactly III.
2. Since A−(A−B)=A∩B, IV is also equivalent. II only matches P after discarding Q: R containing (p,q1) and S containing (p,q2), q1≠q2, makes II nonempty but I empty.
3. Thus only I, III and IV are equivalent, option D.

Original paper, page 14

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

2 marks · MCQ
Report issue

Universal condition on immediate subordinates

Relational Algebra & Calculus

Question 60, GATE 2007: employee(name,sex,supervisorName) has key name. supervisorName names an employee’s supervisor. Interpret the tuple-calculus query {e.name | employee(e) ∧ ∀x[¬employee(x) ∨ x.supervisorName≠e.name ∨ x.sex="male"]}.
Options:
(A) Employees with a male supervisor
(B) Employees with no immediate male subordinates
(C) Employees with no immediate female subordinates
(D) Employees with a female supervisor
Tap to enlarge
Your answer
Answer & solution

Answer: C (no official key was published)

1. Approach. Rewrite the disjunction as an implication about x: if x is an employee supervised by e, x must be male. Universal conditions are true even when e has no subordinates.

2. Derivation and interpretation. The universal disjunction ¬employee(x) ∨ x.supervisorName≠e.name ∨ x.sex=male is the implication: if x is an employee supervised by e, then x is male. Consequently the result includes employees all of whose immediate subordinates are male, including employees with no subordinates by vacuous truth. Under the male/female domain convention used by the options, this is exactly employees with no immediate female subordinates (C). It says nothing about the sex of e's own supervisor.

Original paper, page 15

1 mark · MCQ
Report issue

Foreign-key inclusion in relational algebra

Relational Algebra & Calculus

Question 13, GATE 2004: Relations R1(A,B,C) and R2(D,E) have keys A and D respectively. C is a foreign key in R1 referencing D in R2. Instances r1,r2 satisfy referential integrity. Which expression must be empty? Projection outputs in set differences are identified by their compatible single domains.
Options:
(A) π_D(r2) − π_C(r1)
(B) π_C(r1) − π_D(r2)
(C) π_D(r1 ⋈_(C≠D) r2)
(D) π_C(r1 ⋈_(C=D) r2)
Tap to enlarge
Your answer
Answer & solution

Answer: B (no official key was published)

1. Referential integrity requires every C value in r1 to occur as a referenced D value in r2. Hence π_C(r1)⊆π_D(r2), and π_C(r1)−π_D(r2) is empty, B, under classical relational algebra without SQL nulls.

2. The reverse difference can contain unreferenced parent keys.

3. Teaching check: Think of C values as child references and D values as parent keys. A dangling reference would be a value in the child projection absent from the parent projection. Referential integrity forbids precisely that difference, while allowing parent rows with no children.

Original paper, page 2

1 mark · MCQ
Report issue

Natural-join cardinality and an unstated foreign key

Relational Algebra & Calculus

Question 14, GATE 2004: Student(rollno,name,address) has key rollno; Enroll(rollno,courseno,coursename) has composite key (rollno,courseno). They have 120 and 8 tuples respectively. What are the maximum and minimum sizes of Student ⋈ Enroll (natural join)? No foreign-key constraint is stated.
Options:
(A) 8,8
(B) 120,8
(C) 960,8
(D) 960,120
Tap to enlarge
Your answer
Answer & solution

Answer: Maximum8, minimum 0; A only with referential integrity (no official key was published)

1. Student.rollno is the underlined key, while Enroll has the composite key(rollno,courseno). Each of the 8 enrollment tuples can match at most one Student tuple, so the maximum join size is 8.

2. With only the stated keys, all enrollment roll numbers may be absent from Student, giving minimum 0; no listed pair is then correct. If the intended additional constraint is Enroll.rollno referencing Student.rollno, every enrollment matches exactly once and both maximum/minimum are 8, A.

3. This foreign-key constraint is not stated and is not inferred from matching attribute names alone.

4. Teaching check: The maximum is attained when all eight enrollments use existing student roll numbers, possibly different courses for the same student. The minimum zero is attained by eight enrollments with roll numbers absent from Student. Primary-key uniqueness alone rules out duplicate student matches, not missing matches.

Original paper, page 2

2 marks · MCQ
Report issue

Universal comparison through relational difference

Relational Algebra & Calculus

Question 51, GATE 2004: Student(name,sex,marks), key name, contains at least one boy and one girl. Let ρ_(n,x,m)(Student) rename the three attributes. Interpret π_name(σ_(sex=female)(Student)) − π_name(Student ⋈_(sex=female ∧ x=male ∧ marks≤m) ρ_(n,x,m)(Student)).
Options:
(A) Names of girls with the highest marks
(B) Names of girls with more marks than some boy
(C) Names of girls with marks not less than some boy
(D) Names of girls with more marks than every boy
Tap to enlarge
Your answer
Answer & solution

Answer: D (no official key was published)

1. The left expression selects all female names. The right expression finds a female student paired with a male student whose marks m satisfy female marks≤m, and projects that female name.

2. Subtracting these removes every girl for whom at least one boy has marks greater than or equal to hers. Remaining girls therefore have marks greater than EVERY boy.

3. The primary-key name makes the projected subtraction unambiguous, and the stated existence of boys avoids a vacuous comparison.

4. Teaching check: The joined part is an existential counterexample set: it contains a girl if there exists a boy with marks at least hers. Subtracting all such counterexamples converts “there exists a violating boy” into “every boy has fewer marks.” Equality is removed because the join uses ≤.

Original paper, page 7

1 mark · MCQ
Report issue

Relational algebra for select distinct

Relational Algebra & Calculus

Question 30, GATE 2003: Translate SELECT DISTINCT a₁,a₂,...,aₙ FROM r₁,r₂,...,rₘ WHERE P into classical relational algebra. Every option first applies selection σ_P and then projection π_(a₁,...,aₙ). Their innermost operation is: A. r₁×r₂×...×rₘ; B. r₁⋈r₂⋈...⋈rₘ; C. r₁∪r₂∪...∪rₘ; D. r₁∩r₂∩...∩rₘ.
Tap to enlarge
Your answer
Answer & solution

Answer: A (no official key was published)

1. FROM first chooses every combination of one tuple from each relation. WHERE then keeps only combinations satisfying P. Finally SELECT chooses attributes, and DISTINCT removes repeated projected tuples. A natural join would additionally impose equality on common-named columns, which this arbitrary SQL query does not necessarily request.

2. The comma-separated FROM clause forms the Cartesian product of all relations, WHERE applies selection σ_P, and SELECT DISTINCT applies set projection onto the listed attributes. Thus π_attributes(σ_P(r 1×...×rm)), A, with attribute renaming/qualification as required and the classical relational-algebra interpretation.

Original paper, page 4

1 mark · MCQ
Report issue

Relational algebra and safe calculus

Relational Algebra & Calculus

Question 1.20, GATE 2002: Which comparison of expressive power is true for formal relational query languages?
(A) Relational algebra is more powerful than relational calculus.
(B) Relational algebra and relational calculus have equal power.
(C) Relational algebra and safe relational calculus have equal power.
(D) None of these.
Tap to enlarge
Your answer
Answer & solution

Answer: C (no official key was published)

Step 1: Check the safety restriction in the equivalence statement.

Step 2: A safe query restricts its results to values justified by the finite database and query constants. An unrestricted formula such as “x is not in R” over an infinite ambient domain can return infinitely many values. Relational algebra cannot produce that infinite result from finite input relations, explaining why the safe-calculus qualifier selects C over the unrestricted claim.

Conclusion: The expressive-equivalence theorem relates relational algebra to safe/domain-independent relational calculus, C. An unrestricted calculus expression can describe an infinite or domain-dependent result, which ordinary relational algebra over finite input relations cannot produce.

Original paper, page 3

Report issue

Interviewed students receiving no offer

Relational Algebra & Calculus

Question 15(a)(i), 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)(i): Using only relational algebra join, selection, projection, union and difference, list roll numbers and names of students interviewed at least once but receiving no offer.
Question 15(a)(i), 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)(i): Using only relational algebra join, selection, projection, union and difference, list roll numbers and names of students interviewed at least once but receiving no offer.
Question 15(a)(i), 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)(i): Using only relational algebra join, selection, projection, union and difference, list roll numbers and names of students interviewed at least once but receiving no offer.
Question 15(a)(i), 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)(i): Using only relational algebra join, selection, projection, union and difference, list roll numbers and names of students interviewed at least once but receiving no offer.
Tap to enlarge
Answer & solution

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

Let I=π_{srollno}(INTERVIEW) and O=π_{srollno}(OFFER). I−O contains exactly the students with at least one interview and no offer at all. Join this one-column relation to STUDENT on srollno and project srollno,sname:
π_{srollno,sname}(STUDENT ⋈ (π_{srollno}(INTERVIEW) − π_{srollno}(OFFER))).
Only the permitted join, projection and difference operators are needed. Relational-algebra projection removes duplicates, so repeated interviews do not repeat students.

Original paper, page 8

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

1 mark · MCQ
Report issue

Reachability beyond fixed relational algebra

Relational Algebra & Calculus

Question 1.24, GATE 2001: Given an adjacency relation Adj(X,Y), which query cannot be expressed by a fixed-length ordinary relational-algebra expression: neighbors of a vertex, vertices with self-loops, vertices in cycles with fewer than three vertices, or all vertices reachable from a vertex?
Tap to enlarge
Your answer
Answer & solution

Answer: D (no official key was published)

Step 1: Adjacency and self-loops require selection/projection on Adj. A cycle of a fixed bounded length can be described by a fixed number of renamed joins and equality tests.

Step 2: Reachability permits paths of arbitrarily large length as the graph grows. Ordinary nonrecursive relational algebra has no transitive-closure operation; one fixed expression cannot supply an unbounded chain of joins.

Thus D cannot be expressed by a constant-length ordinary relational-algebra expression over all finite input graphs. Recursive query extensions or a fixed maximum graph size change that setting.

Original paper, page 3

1 mark · MCQ
Report issue

Pushing a selection through a join

Relational Algebra & Calculus

Question 1.25, GATE 2001: For relations r and s with A an attribute of r, simplify σ_(A=a)(r⋈s). Choices are σ_(A=a)(r), r, σ_(A=a)(r)⋈s, or none.
Tap to enlarge
Your answer
Answer & solution

Answer: C (no official key was published)

Step 1: The predicate A=a refers only to an attribute of r. A joined tuple survives the selection exactly when its r component has that value.

Step 2: Rejecting the failing r tuples before joining therefore removes exactly the same joined tuples: σ_(A=a)(r⋈s)=σ_(A=a)(r)⋈s. This is C.

Dropping s altogether can lose its attributes and its filtering effect, so neither r nor its selected subset alone is generally equal to the joined result.

Original paper, page 3

2 marks · MCQ
Report issue

Safety of relational-calculus expressions

Relational Algebra & Calculus

Question 2.24, GATE 2001: Which tuple-calculus expression is unsafe? A binds t[A] to an R1 value absent from R2. B says for every u∈R1, u[A]=constant x implies some s∈R2 has t[A]=s[A] and s[A]=u[A]. C is {t:¬(t∈R1)}. D binds t[A] to values present in both relations. Examine empty/unguarded cases as well as the obvious complement; exact formulas remain linked.
Tap to enlarge
Your answer
Answer & solution

Answer: C is unsafe; B is also unsafe as literally printed (no official key was published)

Step 1: C returns all tuples outside R1. Over an unrestricted infinite domain and finite R1, this produces an unbounded complement, so it is unsafe. A and D bind the returned A-value to existing relation values, under the intended one-attribute result interpretation.

Step 2: B universally quantifies u in R1 and guards the existential restriction on t with u[A]=the constant x. If R1 is empty, or contains no tuple with that A-value, every implication is vacuously true. Then t is unconstrained and arbitrary outside-domain values satisfy the expression. Thus B is also not domain-independent.

This is a literal second-unsafe-option issue confirmed in the paper, not an official-key correction. Adding an existence requirement for the guarded R1 value would change the question.

Original paper, page 7

Descriptive
Report issue

Find duplicate examinee names

Relational Algebra & Calculus

Question 21(a), GATE 2001: examinee(regno,name,score), with primary key regno. Use projection, selection, renaming and Cartesian product to find names appearing in multiple tuples.
Question 21(a), GATE 2001: examinee(regno,name,score), with primary key regno. Use projection, selection, renaming and Cartesian product to find names appearing in multiple tuples.
Tap to enlarge
Answer & solution

Answer: π_X.name σ_(X.name=Y.name ∧ X.regno≠Y.regno)(ρ_X(examinee) × ρ_Y(examinee)). (no official key was published)

Rename the relation twice so the two tuple occurrences are distinguishable: X=ρ_X(examinee), Y=ρ_Y(examinee). Form X×Y, retain equal names but different registration numbers, then project the name.

π_X.name(σ_(X.name=Y.name AND X.regno≠Y.regno)(X×Y)).

The equal-name condition identifies candidates; the unequal-key condition ensures two different examinees rather than pairing a row with itself. Because regno is a key, different regno values mean different rows. Standard relational algebra has set semantics, so projection returns each repeated name once even if it has many matching pairs. Example: (1,Asha,70),(2,Asha,80),(3,Bela,90) returns only Asha. Without the unequal-key predicate every name would incorrectly qualify.

Original paper, page 10

1 mark · MCQ
Report issue

Aggregation outside basic relational algebra

Relational Algebra & Calculus

Question 1.23, GATE 2000: Given employee(name,salary,deptno) and department(deptno,deptname,address), which cannot be expressed with basic selection,projection,product,join,union,intersection,difference: department addresses, matching employee/department names, total salaries, or employees of a department?
Tap to enlarge
Your answer
Answer & solution

Answer: C (no official key was published)

Step 1: Joining on deptno and projecting yields each employee’s department address. Selection can compare name with deptname or filter a particular department.

Step 2: Summing salaries across arbitrarily many tuples requires aggregation and produces a new arithmetic value. The listed basic relational-algebra operators select/combine existing tuple values but contain no aggregate-sum operation.

Therefore total salaries, C, needs an extended algebra or SQL aggregation.

Original paper, page 3

1 mark · MCQ
Report issue

Bounds on join cardinality

Relational Algebra & Calculus

Question 1.18, GATE 1999: Relations R,S have m,n tuples. What are the maximum and minimum possible sizes of their join?
Tap to enlarge
Your answer
Answer & solution

Answer: B: mn and 0 (no official key was published)

A join selects qualifying pairs from R×S, which contains mn pairs. Therefore it cannot exceed mn. This upper bound occurs when every pair satisfies the join predicate. The minimum zero occurs when no pair satisfies it. Hence B gives the general possible extremes. This reasoning assumes an ordinary inner join with a condition that can permit or reject pairs. A fixed natural join on disjoint schemas is always the Cartesian product, so its minimum would not be zero for positive m,n; the question is the usual unrestricted join-bound comparison.

Original paper, page 2

1 mark · MCQ
Report issue

Conjunction in tuple calculus

Relational Algebra & Calculus

Question 1.19, GATE 1999: Translate {t | t∈r and t[A]=10 and t[B]=20}. Options combine the two selections by OR/union, intersection, or difference.
Tap to enlarge
Your answer
Answer & solution

Answer: C (no official key was published)

The tuple must satisfy both tests simultaneously. Selection on A=10 retains the first qualifying subset, and selection on B=20 retains the second. Their intersection contains exactly tuples passing both, so σ(A=10)(r)∩σ(B=20)(r) is equivalent, C. Union or a disjunctive predicate would admit a tuple satisfying only one test. Difference would keep the first test while rejecting the second, which reverses the required conjunction.

Original paper, page 2

1 mark · MCQ
Report issue

Equijoin and intersection

Relational Algebra & Calculus

Question 1.33, GATE 1998: For union-compatible R1(A, B), R2(C, D), interpret R1 join on A=C and B=D R2. Choices include union, product, difference, intersection.
Tap to enlarge
Your answer
Answer & solution

Answer: D after projecting duplicate columns; raw theta join has four attributes (no official key was published)

A qualifying pair contains the same two values in both input relations. Thus each output is (a, b, a, b), one for each common tuple (a, b). Projecting onto A, B gives the intersection R1∩R2 after renaming, explaining D. But an ordinary theta join retains all four attributes A, B, C, D, whereas intersection has only two. They are not literally equal schemas without projection or a duplicate-column-eliminating join convention. This arity distinction is recorded rather than silently identifying the raw four-column relation with the two-column intersection.

Original paper, page 3

2 marks · MCQ
Report issue

Moving selections across projections

Relational Algebra & Calculus

Question 2.19, GATE 1998: Which rewrite is not generally valid? A commuting selections; B moving a well-defined selection before projection; C distributing selection over union; D moving selection after projection without retaining predicate attributes.
Tap to enlarge
Your answer
Answer & solution

Answer: D (no official key was published)

Selections commute because both predicates must hold, and selection distributes over union tuple by tuple. If selection after projection is already well typed, all predicate attributes survived, so pushing it down is safe. In the reverse direction, projecting first may delete an attribute needed by the predicate. For R(A, B), πA(σB=1(R)) is defined, but σB=1(πA(R)) is not. Thus D is not an unrestricted rule. Enlarged the paper B shows its right outer operator as σ with attribute subscript A 1 rather than a projection π, another literal typing defect; the coherent projection rule analyzed above is an explicitly stated reconstruction, not a silent transcription.

Original paper, page 5

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

1 mark · Descriptive
Report issue

Relational algebra for project participation SQL

Relational Algebra & Calculus

Question 76(a), 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. Translate the supplied SQL using relational-algebra operators:
SELECT eno
FROM EMP, INVOLVED
WHERE EMP.eno = INVOLVED.eno AND INVOLVED.pno = 3;
The SELECT column is unqualified in the reproduction.
Question 76(a), 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. Translate the supplied SQL using relational-algebra operators:
SELECT eno
FROM EMP, INVOLVED
WHERE EMP.eno = INVOLVED.eno AND INVOLVED.pno = 3;
The SELECT column is unqualified in the reproduction.
Tap to enlarge
Answer & solution

Answer: After qualifying SELECT EMP.eno, the set-algebra answer is π_EMP.eno(σ_EMP.eno=INVOLVED.eno ∧ INVOLVED.pno=3(EMP×INVOLVED)). Literal SQL has an ambiguous column reference. (no official key was published)

First distinguish the printed query from its evident intention. Both EMP and INVOLVED have a column named eno, and an explicit FROM EMP,INVOLVED cross join retains both column names. The equality in WHERE does not make the unqualified SELECT eno syntactically unambiguous in standard SQL. The literal query therefore requires qualification. Taking the intended target as EMP.eno gives:

π_EMP.eno(σ_EMP.eno=INVOLVED.eno ∧ INVOLVED.pno=3(EMP × INVOLVED)).

The Cartesian product produces all employee/participation row pairs. Selection keeps only pairs referring to the same employee and project number 3. Projection then retains the requested employee number. One may push the project filter down before the product, obtaining π_EMP.eno(σ_EMP.eno=INVOLVED.eno(EMP × σ_pno=3(INVOLVED))), which is set-equivalent and usually more efficient.

Attribute qualification in the first formula prevents confusion between the two eno fields and the two relations. A natural join EMP ⋈ INVOLVED followed by σ_pno=3 and π_eno is also valid here because eno is their only shared attribute name. PROJ is not used: the SQL never checks whether project 3 exists in PROJ, and adding that join would impose an extra condition not present in the query.

The displayed composite primary key (eno,pno) of INVOLVED rules out duplicate employee–project pairs, and EMP.eno is also a primary key. After restricting INVOLVED.pno to 3, there is at most one qualifying involvement row for each employee, and the join matches at most one EMP row. Therefore the qualified SELECT returns each selected employee number at most once. Although SQL SELECT normally uses bag semantics and ordinary relational algebra uses sets, that difference does not change this query’s result under the stated keys. No added DISTINCT or extra uniqueness assumption is needed. The printed unqualified SELECT eno still requires the column-name repair explained above.

Original paper, page 12

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

Report issue

Relational algebra query on ages

Relational Algebra & Calculus

Question 76(b)(ii), 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 explain the second expression in GFG76(b). The available reproduction visibly reads approximately
π_age(EMP) − π_{E.age<EMP.age}(ρ_E(EMP) × EMP).
The second operator is printed as a projection symbol whose subscript is a comparison, rather than a projection of an attribute followed by a selection. A note describes ρ as renaming a copy of EMP, but uses an inconsistent alias in its prose. State the literal defect, and separately explain the likely intended well-typed maximum-age query. The two b-subparts jointly carry 4 marks; individual allocations are unavailable.
Question 76(b)(ii), 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 explain the second expression in GFG76(b). The available reproduction visibly reads approximately
π_age(EMP) − π_{E.age<EMP.age}(ρ_E(EMP) × EMP).
The second operator is printed as a projection symbol whose subscript is a comparison, rather than a projection of an attribute followed by a selection. A note describes ρ as renaming a copy of EMP, but uses an inconsistent alias in its prose. State the literal defect, and separately explain the likely intended well-typed maximum-age query. The two b-subparts jointly carry 4 marks; individual allocations are unavailable.
Question 76(b)(ii), 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 explain the second expression in GFG76(b). The available reproduction visibly reads approximately
π_age(EMP) − π_{E.age<EMP.age}(ρ_E(EMP) × EMP).
The second operator is printed as a projection symbol whose subscript is a comparison, rather than a projection of an attribute followed by a selection. A note describes ρ as renaming a copy of EMP, but uses an inconsistent alias in its prose. State the literal defect, and separately explain the likely intended well-typed maximum-age query. The two b-subparts jointly carry 4 marks; individual allocations are unavailable.
Tap to enlarge
Answer & solution

Answer: Literal expression: not well-typed standard relational algebra. Under the separately stated repair: “Ages of the oldest employees.” (no official key was published)

Literal reading first: in standard relational algebra, π takes an attribute list, not a Boolean comparison predicate. The printed subscript E.age<EMP.age therefore does not define an ordinary projection. Simply changing that π into σ is insufficient: it would produce tuples of the two-relation product, which cannot be subtracted from the unary relation π_age(EMP). Set difference requires compatible schemas. Consequently the paper, as read, does not have a defined standard relational-algebra result. No verified original or alternate complete tail is available to establish the missing symbols.

A plausible intended repair is
π_age(EMP) − ρ_age←E.age(π_E.age(σ_E.age<EMP.age(ρ_E(EMP) × EMP))).
Here ρ_E(EMP) is a distinct copy whose attributes are qualified E. The inner selection finds each pair where the copied employee is younger than the other employee. Projecting E.age collects ages that have a strictly greater age somewhere in EMP. The explicit attribute rename makes the right-hand unary age relation union-compatible with the left-hand one. Subtract those nonmaximum ages from all ages and only the maximum age remains.

Under this repair, the requested short English answer is: Ages of the oldest employees. This is five words. For ages {25,40,40}, the Cartesian comparison finds that 25 has an older witness, while 40 does not. Set projection removes duplicate 40s, and the final result is {40}, an age value rather than employee names or employee records. With an empty EMP, the result is empty. Equal ages do not eliminate each other because the comparison is strict.

This maximum-age interpretation is conditional on projecting the younger copy's age. Projecting EMP.age instead would remove ages that have a smaller witness and leave the minimum, a different query. Thus the damaged expression cannot safely be repaired silently. The literal defect and the proposed older-witness interpretation must remain separate until a better source establishes the exact original notation.

Original paper, page 12

Descriptive
Report issue

Interpreting a user-specific library query

Relational Algebra & Calculus

Question 27(a), GATE 1996: Relations are USERS(User#,UserName,HomeTown), BOOKS(Book#,BookTitle,AuthorName), and ISSUED(Book#,User#,Date). Natural joins match the identically named key attributes. Explain in one English sentence the query σ_User#=6(π_User#,BookTitle((USERS ⋈ ISSUED) ⋈ BOOKS)). This paraphrase uses GFG's legible relational operators; GateForum's reproduction drops join symbols and degrades projection typography.
Question 27(a), GATE 1996: Relations are USERS(User#,UserName,HomeTown), BOOKS(Book#,BookTitle,AuthorName), and ISSUED(Book#,User#,Date). Natural joins match the identically named key attributes. Explain in one English sentence the query σ_User#=6(π_User#,BookTitle((USERS ⋈ ISSUED) ⋈ BOOKS)). This paraphrase uses GFG's legible relational operators; GateForum's reproduction drops join symbols and degrades projection typography.
Tap to enlarge
Answer & solution

Answer: Returns (6, title) pairs for books recorded as issued to user 6. (no official key was published)

One-sentence answer: It returns user number 6 together with the titles of books recorded as issued to that user.

To see why, USERS ⋈ ISSUED first connects each issue record with the user whose User# matches. Joining this result with BOOKS on Book# adds the associated BookTitle and AuthorName. The projection π_User#,BookTitle retains just the user identifier and title, discarding names, dates, book identifiers and author names. Finally σ_User#=6 keeps only rows whose user identifier is 6.

Selection occurs after projection here without losing its input attribute, because User# is explicitly retained. It could equivalently be pushed earlier to restrict the user or issue records before the joins. Under ordinary set-based relational algebra, projection removes duplicate pairs: borrowing the same titled book more than once does not produce multiple identical (6,title) rows, and distinct books with the same title also collapse at this projection. No return-date or current-loan condition exists in the schema, so “recorded as issued” is more precise than claiming these are necessarily the user's currently unreturned books. The query yields titles with the fixed identifier 6, not a count of loans, author names, or all users who borrowed the same books.

Original paper, page 10

Descriptive
Report issue

Interpreting authors read by a hometown group

Relational Algebra & Calculus

Question 27(b), GATE 1996: Relations are USERS(User#,UserName,HomeTown), BOOKS(Book#,BookTitle,AuthorName), and ISSUED(Book#,User#,Date). Natural joins match the identically named key attributes. Explain in one English sentence the query π_AuthorName(BOOKS ⋈ σ_HomeTown='Delhi'(USERS ⋈ ISSUED)). Use the projection and natural-join symbols visible in GFG; GateForum misprints/degrades these operators.
Question 27(b), GATE 1996: Relations are USERS(User#,UserName,HomeTown), BOOKS(Book#,BookTitle,AuthorName), and ISSUED(Book#,User#,Date). Natural joins match the identically named key attributes. Explain in one English sentence the query π_AuthorName(BOOKS ⋈ σ_HomeTown='Delhi'(USERS ⋈ ISSUED)). Use the projection and natural-join symbols visible in GFG; GateForum misprints/degrades these operators.
Tap to enlarge
Answer & solution

Answer: Names of authors with at least one book issued to a Delhi-hometown user. (no official key was published)

One-sentence answer: It returns the names of authors having at least one book recorded as issued to a user whose hometown is Delhi.

The inner natural join USERS ⋈ ISSUED matches each issue to its borrower through User#. Selecting HomeTown='Delhi' retains issue records belonging to Delhi users; the condition describes the borrower's hometown, not the author's residence or the book's publication place. The join with BOOKS matches Book# and adds the author of each surviving issued book. Projection onto AuthorName then discards every other attribute.

Under set semantics each distinct author name appears once, even if several Delhi users borrowed that author's books or one user borrowed several such books. The condition is existential: one qualifying issue suffices. It does not require that all books by the author have been issued, that every Delhi user has read the author, or that the author is popular by any numerical threshold. Likewise nothing in the given schema tests whether a book has since been returned. If no Delhi user has any issue record, the result is empty. Two different people who happen to share AuthorName are not distinguished by this schema and projection; the result is a set of names rather than necessarily unique real-world author identities.

Original paper, page 10

Descriptive
Report issue

Projecting publisher names

Relational Algebra & Calculus

Question 27(a), GATE 1995: AUTHOR(ANAME,INSTITUTION,ACITY,AGE), PUBLISHER(PNAME,PCITY), BOOK(TITLE,ANAME,PNAME). Use relational algebra SELECT, PROJECT, JOIN and/or DIVIDE. Obtain the names of all publishers.
Question 27(a), GATE 1995: AUTHOR(ANAME,INSTITUTION,ACITY,AGE), PUBLISHER(PNAME,PCITY), BOOK(TITLE,ANAME,PNAME). Use relational algebra SELECT, PROJECT, JOIN and/or DIVIDE. Obtain the names of all publishers.
Tap to enlarge
Answer & solution

Answer: π_PNAME(PUBLISHER). (no official key was published)

The requested output is a single attribute, PNAME, from every tuple of PUBLISHER. Projection selects columns, so the expression is π_PNAME(PUBLISHER). No selection predicate is needed because no publisher is to be filtered out, and no join is needed because the required data already reside in one relation.

Under classical relational algebra, relations are sets, so projection returns each distinct publisher name once. If two stored tuples happen to share a name, the output still contains that value once. The result schema consists only of PNAME, not PCITY.

It would be incorrect to obtain these names by projecting BOOK: that would return only publishers represented by at least one recorded book, whereas the query asks for all publishers. Similarly, joining PUBLISHER with BOOK first could incorrectly lose a publisher with no matching book. DIVIDE is also unnecessary: there is no requirement involving all members of another relation. This simple query tests matching the requested output columns and population directly to the base relation.

Original paper, page 8

Descriptive
Report issue

Selecting authors of a named publisher

Relational Algebra & Calculus

Question 27(b), GATE 1995: AUTHOR(ANAME,INSTITUTION,ACITY,AGE), PUBLISHER(PNAME,PCITY), BOOK(TITLE,ANAME,PNAME). Use relational algebra SELECT, PROJECT, JOIN and/or DIVIDE. Obtain all AUTHOR attributes of authors who have published a book with PNAME='TECHNICAL PUBLISHERS'.
Question 27(b), GATE 1995: AUTHOR(ANAME,INSTITUTION,ACITY,AGE), PUBLISHER(PNAME,PCITY), BOOK(TITLE,ANAME,PNAME). Use relational algebra SELECT, PROJECT, JOIN and/or DIVIDE. Obtain all AUTHOR attributes of authors who have published a book with PNAME='TECHNICAL PUBLISHERS'.
Tap to enlarge
Answer & solution

Answer: π_ANAME,INSTITUTION,ACITY,AGE(AUTHOR ⋈ σ_PNAME='TECHNICAL PUBLISHERS'(BOOK)). (no official key was published)

First identify the relevant books using selection: T=σ_PNAME='TECHNICAL PUBLISHERS'(BOOK). This keeps tuples whose publisher name matches the specified literal, while retaining TITLE and ANAME so that authors can be linked. Next compute AUTHOR⋈T. The only shared attribute name is ANAME, so this natural join matches each qualifying book to its author record. Finally project ANAME,INSTITUTION,ACITY,AGE to return exactly the attributes requested from AUTHOR.

Thus the complete expression is π_ANAME,INSTITUTION,ACITY,AGE(AUTHOR⋈σ_PNAME='TECHNICAL PUBLISHERS'(BOOK)). Equivalently, first project ANAME from the selected books, then join that name relation to AUTHOR; the result already has exactly the AUTHOR schema.

An author with several matching books still appears only once in classical set relational algebra after projection. An author with no such book is excluded because there is no matching join tuple. Joining PUBLISHER is not needed: the condition is already expressible using BOOK.PNAME. The expression uses the association specified by the schema, namely ANAME as the author link; it does not infer that names uniquely identify people outside this database model. DIVIDE would express a universal requirement and would be inappropriate for the existential condition 'has published a book'.

Original paper, page 8

Descriptive
Report issue

Authors with a publisher in Madras

Relational Algebra & Calculus

Question 27(c), GATE 1995: AUTHOR(ANAME,INSTITUTION,ACITY,AGE), PUBLISHER(PNAME,PCITY), BOOK(TITLE,ANAME,PNAME). Use relational algebra SELECT, PROJECT, JOIN and/or DIVIDE. Obtain the names of all authors who have published a book for any publisher located in Madras.
Question 27(c), GATE 1995: AUTHOR(ANAME,INSTITUTION,ACITY,AGE), PUBLISHER(PNAME,PCITY), BOOK(TITLE,ANAME,PNAME). Use relational algebra SELECT, PROJECT, JOIN and/or DIVIDE. Obtain the names of all authors who have published a book for any publisher located in Madras.
Tap to enlarge
Answer & solution

Answer: π_ANAME(AUTHOR ⋈ BOOK ⋈ σ_PCITY='Madras'(PUBLISHER)). (no official key was published)

Select publishers by their city: M=σ_PCITY='Madras'(PUBLISHER). Join BOOK to M on the common attribute PNAME. This keeps exactly books whose publisher is among the Madras publishers. Join the result to AUTHOR on ANAME, and finally project ANAME. A full expression is π_ANAME(AUTHOR⋈BOOK⋈σ_PCITY='Madras'(PUBLISHER)). Natural joins are unambiguous here: BOOK and PUBLISHER share PNAME, while AUTHOR and BOOK share ANAME. ACITY and PCITY are different attributes.

The test is on the publisher's city PCITY, not the author's city ACITY. An author outside Madras qualifies if at least one book has a Madras publisher. Conversely an author living in Madras does not qualify solely because of that residence. The word 'any' here is existential: one matching publisher is enough, so use selection and join rather than division.

Under an assumed foreign-key constraint BOOK.ANAME references AUTHOR.ANAME, the AUTHOR join can be omitted and π_ANAME(BOOK⋈M) is equivalent. Since that referential constraint is not explicitly stated, retaining AUTHOR is the safer literal expression for names of stored authors. Projection removes repetitions caused by multiple qualifying books or publishers under set semantics. Exact comparison uses the displayed city value 'Madras', not a silently substituted modern place-name string.

Original paper, page 8

Descriptive
Report issue

Intersection using union and difference only

Relational Algebra & Calculus

Question 3.8, GATE 1994: Give an expression equivalent to R∩S using the minimum number of operators from {∪,−}.
Tap to enlarge
Answer & solution

Answer: R−(R−S), using two differences (no official key was published)

The inner R−S contains exactly the R tuples absent from S. Removing those from R leaves the tuples present in both, namely R∩S. This uses two operators. One operator cannot work for arbitrary R,S: R∪S includes exclusive tuples, R−S and S−R keep exclusives rather than common tuples, and applying an operator to a relation twice yields either that relation or the empty relation. Thus two is minimal under set semantics with only R,S and the listed binary operators, assuming union-compatible schemas.

Original paper, page 4

Descriptive
Report issue

Relational algebra selection and difference

Relational Algebra & Calculus

Question 13(a), GATE 1994: COURSES(cno,cname), primary key cno; STUDENTS(rollno,sname,age,year), primary key rollno; REGISTERED_FOR(cno,rollno), composite primary key (cno,rollno). year denotes the student’s current year of study. GateForum asks for a relational algebra query printing roll numbers of students who HAVE registered for cno 322. GFG instead asks for those who HAVE NOT registered.
Question 13(a), GATE 1994: COURSES(cno,cname), primary key cno; STUDENTS(rollno,sname,age,year), primary key rollno; REGISTERED_FOR(cno,rollno), composite primary key (cno,rollno). year denotes the student’s current year of study. GateForum asks for a relational algebra query printing roll numbers of students who HAVE registered for cno 322. GFG instead asks for those who HAVE NOT registered.
Tap to enlarge
Answer & solution

Answer: Registered: π_rollno(σ_cno=322(REGISTERED_FOR)). Not registered: π_rollno(STUDENTS) − π_rollno(σ_cno=322(REGISTERED_FOR)). (no official key was published)

1. Select registrations for course 322 before projecting rollno, so registrations in other courses do not count.

2. For the registered variant, projection directly returns the wanted roll numbers under the usual valid student-reference assumption. Without that assumption, intersect with π_rollno(STUDENTS).

3. For the not-registered variant, subtract the selected roll-number set from all student roll numbers. Selecting registrations where cno≠322 would be wrong because a student may register for both 322 and another course, or for no course.

  • No single query answers both variants.

Original paper, page 6

Descriptive
Report issue

Hotels serving a snack Rama likes

Relational Algebra & Calculus

Question 13(b), GATE 1992: Relations are FREQUENTS(CUSTOMER,HOTEL), SERVES(HOTEL,SNACKS), LIKES(CUSTOMER,SNACKS). They record visits, available snacks, and preferences respectively. Express in relational algebra the query: list hotels that serve a snack customer Rama likes.
Tap to enlarge
Answer & solution

Answer: π_HOTEL(SERVES ⋈ σ_CUSTOMER='Rama'(LIKES)). (no official key was published)

First select Rama's preferences: R = σ_CUSTOMER='Rama'(LIKES). Next match those snack names with served snacks by a natural join on their common attribute SNACKS. Finally discard the customer and snack columns, retaining only hotels:

π_HOTEL(SERVES ⋈ σ_CUSTOMER='Rama'(LIKES)).

An equivalent expression first projects preferences to snack names:
π_HOTEL(SERVES ⋈ π_SNACKS(σ_CUSTOMER='Rama'(LIKES))).

For any hotel h in this result, the join supplies some snack s with SERVES(h,s) and LIKES('Rama',s), exactly the requested existential condition. Conversely, every such pair joins and projects to h, so no qualifying hotel is omitted. Under ordinary set relational algebra projection removes duplicates when a hotel serves several liked snacks.

FREQUENTS is deliberately unused: the query does not require Rama to visit the hotel. Joining it and filtering Rama would incorrectly exclude unvisited hotels. Nor is division appropriate: division would express serving every liked snack, whereas the wording asks for at least one. If Rama likes no snacks, the result is empty.

Original paper, page 9

Report issue

Suppliers serving both named projects

Relational Algebra & Calculus

Question 12(b.i), GATE 1991: SUPPLIER(SCODE,SNAME,CITY), PART(PCODE,PNAME,PDESC,CITY), PROJECTS(PRCODE,PRNAME,CITY), SPPR(SCODE,PCODE,PRCODE,QTY). SPPR records shipments of parts by suppliers to projects. Give relational algebra for supplier codes supplying both projects PR1 and PR2.
Question 12(b.i), GATE 1991: SUPPLIER(SCODE,SNAME,CITY), PART(PCODE,PNAME,PDESC,CITY), PROJECTS(PRCODE,PRNAME,CITY), SPPR(SCODE,PCODE,PRCODE,QTY). SPPR records shipments of parts by suppliers to projects. Give relational algebra for supplier codes supplying both projects PR1 and PR2.
Question 12(b.i), GATE 1991: SUPPLIER(SCODE,SNAME,CITY), PART(PCODE,PNAME,PDESC,CITY), PROJECTS(PRCODE,PRNAME,CITY), SPPR(SCODE,PCODE,PRCODE,QTY). SPPR records shipments of parts by suppliers to projects. Give relational algebra for supplier codes supplying both projects PR1 and PR2.
Tap to enlarge
Answer & solution

Answer: π_SCODE(σ_PRCODE='PR1'(SPPR)) ∩ π_SCODE(σ_PRCODE='PR2'(SPPR)). (no official key was published)

First select shipments to PR1 and project their supplier codes: A=π_SCODE(σ_PRCODE='PR1'(SPPR)). Separately form B=π_SCODE(σ_PRCODE='PR2'(SPPR)). Both expressions have the same one-attribute schema, so set intersection is defined. The answer is A∩B.

Membership in the intersection requires a shipment witness to each project. The witnesses need not have the same part, quantity or shipment record. Selecting PRCODE='PR1' AND PRCODE='PR2' on a single tuple would be wrong because one shipment tuple cannot have two different project codes. Selecting with OR and projecting without intersection would also be wrong: it admits suppliers serving only one project. Under standard relational-algebra set semantics projection automatically eliminates duplicate supplier codes.

Original paper, page 7

Report issue

Projects with an outside-city supplier

Relational Algebra & Calculus

Question 12(b.ii), GATE 1991: SUPPLIER(SCODE,SNAME,CITY), PART(PCODE,PNAME,PDESC,CITY), PROJECTS(PRCODE,PRNAME,CITY), SPPR(SCODE,PCODE,PRCODE,QTY). SPPR records shipments of parts by suppliers to projects. Give relational algebra for project codes supplied by at least one supplier in a different city.
Question 12(b.ii), GATE 1991: SUPPLIER(SCODE,SNAME,CITY), PART(PCODE,PNAME,PDESC,CITY), PROJECTS(PRCODE,PRNAME,CITY), SPPR(SCODE,PCODE,PRCODE,QTY). SPPR records shipments of parts by suppliers to projects. Give relational algebra for project codes supplied by at least one supplier in a different city.
Question 12(b.ii), GATE 1991: SUPPLIER(SCODE,SNAME,CITY), PART(PCODE,PNAME,PDESC,CITY), PROJECTS(PRCODE,PRNAME,CITY), SPPR(SCODE,PCODE,PRCODE,QTY). SPPR records shipments of parts by suppliers to projects. Give relational algebra for project codes supplied by at least one supplier in a different city.
Tap to enlarge
Answer & solution

Answer: π_P.PRCODE(σ_S.CITY≠P.CITY((ρ_S SUPPLIER) ⋈_S.SCODE=X.SCODE (ρ_X SPPR) ⋈_X.PRCODE=P.PRCODE (ρ_P PROJECTS))). (no official key was published)

Rename SUPPLIER as S, SPPR as X and PROJECTS as P so that both CITY attributes can be referenced explicitly. Form J=(S ⋈_{S.SCODE=X.SCODE} X) ⋈_{X.PRCODE=P.PRCODE} P. Then return π_{P.PRCODE}(σ_{S.CITY≠P.CITY}(J)).

The joins establish that S actually supplies P through a shipment row. The selection keeps witnesses whose endpoint cities differ, and the projection returns the set of project codes having at least one such witness. A project may also have local suppliers and must still appear: the condition is existential, not a requirement that every supplier be out of town. A natural join over unrenamed relations would wrongly equate the two CITY attributes and suppress precisely the rows sought, so use explicit theta joins or rename the city columns before joining.

Original paper, page 7