GATE 2026 CS1 Q.43
Consider a relational database schema with two relations and .
Let be a tuple relational calculus expression.
Which one of the following relational algebraic expressions is equivalent to ?
- (A)
- (B)
- (C)
- (D)
GATE CS · DA
Relational algebra and tuple calculus
The relational model stores data as relations (sets of tuples) identified by keys. Relational algebra (procedural) and tuple relational calculus (declarative) are two formal languages for querying them, and their safe forms express exactly the same queries. GATE DA questions on this topic ask you to evaluate an expression on small tables and count the result tuples, to pick the expression that answers a stated query, and to judge which calculus expressions are safe, so these notes concentrate on exact operator rules, equivalences and cardinality bounds.
13 previous-year questions · 13 solved · 6 practice questions
A relation schema names the attributes; a relation instance is a finite set of tuples, each giving one value per attribute. Because a relation is a set, there is no tuple order and no duplicate tuple. The degree is the number of attributes and the cardinality is the number of tuples.
Convention used in these notes. Relational algebra and tuple calculus use set semantics: no result ever contains a duplicate tuple. SQL uses bag semantics: SELECT keeps duplicates unless DISTINCT is written, while UNION, INTERSECT and EXCEPT remove duplicates unless ALL is written. Wherever NULL appears, any comparison involving it is unknown (three-valued logic), and a selection or join condition that is unknown does not select the tuple, as in a SQL WHERE clause. SQL keywords are written in capitals.
Term | Meaning |
|---|---|
Superkey | A set of attributes such that no two distinct tuples agree on all of (in every legal instance) |
Candidate key | A minimal superkey: removing any attribute breaks uniqueness |
Primary key | The one candidate key chosen to identify tuples; its attributes cannot be |
Alternate key | A candidate key that was not chosen as primary |
Prime attribute | An attribute that belongs to at least one candidate key |
Foreign key | A set of attributes of whose value in every tuple is either |
SUPERKEY CONDITION
Every superset of a superkey (within the attributes of ) is a superkey, so under set semantics the set of all attributes is always a superkey. Candidate keys are the minimal superkeys.
COUNTING SUPERKEYS
is the number of attributes of . A superkey is any attribute set that contains at least one candidate key. With two keys, inclusion-exclusion subtracts the sets counted twice: those containing .
EXAM TIP
Keys are a property of the schema (they must hold for every legal instance), not of one instance. A small table can show that a set is not a key (two rows agree), but it can never prove that a set is a key.
Every operator takes relations and returns a relation (the algebra is closed), so expressions nest. The basic operators are selection , projection and rename (unary), and union , set difference and Cartesian product (binary). Theta and natural joins, intersection and division can all be written using these six. Rename only changes names, so is often called the complete set.
SELECTION
Keeps whole tuples satisfying the condition; schema unchanged; .
PROJECTION
Keeps the listed columns and removes duplicate rows (set semantics). For non-empty , , with whenever the list contains a superkey.
CARTESIAN PRODUCT
Pairs every tuple of with every tuple of . Clashing attribute names are qualified (, ) or renamed with .
UNION AND SET DIFFERENCE
Defined only for union-compatible relations: the same degree, with the -th attributes of both having the same domain. By convention the result takes its attribute names from the first operand. Union is commutative and associative; difference is neither.
RENAME
Gives the result the relation name and attribute names ; needed for self-joins.
CARDINALITY BOUNDS FOR SET OPERATIONS
Set semantics, and union-compatible. Also and . The upper bounds of and are reached when ; their lower bounds when the smaller relation is contained in the larger.
EXAM TIP
Projection and union remove duplicates, so a count taken after or can be smaller than you expect. Always list the distinct rows before counting.
Theta join, natural join, intersection and division are derived operators: each can be rewritten with the basic ones, and they exist because they shorten common queries. Outer joins, at the end of this section, are an extension: they also need NULL to pad the missing side.
THETA JOIN
. An equi-join is a theta join whose condition is only equalities; it keeps both copies of the compared attributes.
NATURAL JOIN
are the attributes with the same name in both relations, and the result has degree . With no common attribute it equals ; when the two schemas are identical it equals . A NULL never matches, not even another NULL. Natural join is commutative and associative (up to column order).
INTERSECTION
Union-compatible relations; .
DIVISION
and , where the attributes of are a proper subset of those of and is the rest. The result has schema (degree ): the -values that appear in paired with every tuple of . If is empty, the formula gives .
DIVISION SIZE BOUNDS
Each -value in the result needs its own tuples in , one for each tuple of , and these tuples are different for different -values.
Outer joins keep tuples that find no partner, padding the missing side with NULL. Write (left outer), (right outer) and (full outer); the superscripts name the kind of join, not a relation. The left outer join keeps every tuple of the left relation, the right keeps every tuple of the right, and the full outer join keeps both.
OUTER JOIN COUNTS
is the inner (natural) join; and are the numbers of tuples of and of that match no tuple of the other relation. Left outer adds only , right outer only .
NATURAL JOIN SIZE BOUNDS
If the common attributes form a key of , each tuple of matches at most one tuple of , so . If they are also a foreign key of referencing with no NULL in it, the size is exactly .
WORKED EXAMPLE
Let and . Find .
.
has tuples: every with and .
Subtract (6 tuples). The tuples left are the pairs that lacks: and .
Project on : . These -values are missing at least one from .
. Check: only and appear with both and .
Answer: , two tuples.
EXAM TIP
To read a division quickly, group by and ask which groups contain every -value. A group may contain extra -values and still qualify: extras do no harm, only gaps do.
Two expressions are equivalent when they return the same relation on every legal instance. One counter-example instance is enough to show that two expressions are not equivalent.
Equivalence | Condition |
|---|---|
Always | |
(otherwise the left side is undefined) | |
uses only attributes in | |
(also for ) | uses only attributes of |
, and likewise for and | Always; also |
Always | |
and | Equality can fail (example below) |
and | Natural join, up to column order |
and are commutative and associative | is neither: and in general |
WORKED EXAMPLE
Show that projection does not distribute over set difference or intersection, using and .
, so .
. The two sides differ.
, so .
. The two sides differ again.
Answer: Both equalities fail on this instance, so neither is a valid rewrite. Only the one-way inclusions in the table hold.
LARGEST VALUE WITHOUT AGGREGATION
is a renamed copy of . The subtracted part is every -value that some other value of exceeds, so what remains is the maximum value of . Use in place of for the minimum. This assumes contains no NULL.
EXAM TIP
To decide whether two expressions are equivalent, first try a tiny instance (one or two tuples per relation, sharing a value so the operators interact). A counter-example settles a no; a yes needs an argument that works for every instance.
Procedure for a counting question
Write the schema and the tuples of every base relation as a small list.
Evaluate from the innermost bracket outwards, writing out each intermediate relation in full.
For a join, match on the common attributes (or on the stated condition) and list each matching pair; do not guess from sizes.
After any projection or union, delete duplicate rows (set semantics).
For outer joins, add the unmatched tuples with NULL padding last.
Count only at the end, and cross-check with the bounds above.
WORKED EXAMPLE
and . How many tuples are in , , , and ?
Join on : meets ; meets and ; meets and ; and have no partner.
: 5 tuples.
: are all distinct: 5 tuples.
: : duplicates collapse, 3 tuples.
Left outer adds the unmatched tuple as : .
Full outer also adds the unmatched tuple as : .
Answer: 5, 5, 3, 6 and 7 tuples respectively.
EXAM TIP
A selection such as returns nothing, because a comparison with NULL is unknown. Testing for NULL needs IS NULL in SQL, which has no plain equivalent in the basic algebra above.
Tuple relational calculus (TRC) is declarative: it describes what the answer tuples satisfy, not how to compute them. An expression is , where is a tuple variable and is a formula.
TRC EXPRESSION
The result is the set of all tuples for which formula is true. is the only free variable of ; every other tuple variable must be bound by a quantifier.
Building blocks of a formula
Atoms: (range of ), and with and a constant. abbreviates .
Connectives: , and implication .
Quantifiers: and ; both bind .
Duality: and .
Reading the table. The answer tuple has the schema of the algebra result in the same row, and , , may each be a list of attributes. For , and , and are union-compatible. In the product row has schema and has schema ; in the natural-join row and ; in the division row and .
Algebra | Tuple calculus |
|---|---|
An expression is safe if it is guaranteed to return a finite set: every value in an answer tuple must come from the relations named in the expression or from the constants written in it, and quantified variables range only over such values. is unsafe: over an unbounded domain, infinitely many tuples are not in . is safe when and are union-compatible. Safe tuple calculus and basic relational algebra express exactly the same queries; a query language that can express all of them is called relationally complete. Neither can express aggregation (such as counting tuples), ordering, or recursion such as transitive closure.
EXAM TIP
To spot an unsafe expression, check every disjunct separately. In each one, every attribute of the answer variable must be pinned down positively: by , or by equality with a constant or with a variable that ranges over a relation. (only compared), (only negated) and (second disjunct unbounded) are all unsafe.
Each algebra shape has a standard SQL form. A selection-projection-join query is SELECT-FROM-WHERE. Difference becomes EXCEPT or a correlated NOT EXISTS; intersection becomes INTERSECT or EXISTS; division becomes a double NOT EXISTS. NOT IN expresses difference only when the subquery returns no NULL: if it returns one, x NOT IN (...) is never true (it is false or unknown), so the query returns no rows.
The algebra query with and is, in SQL (DISTINCT matches the set semantics of the algebra):
SELECT DISTINCT R.A
FROM R
JOIN S
ON R.B = S.B
WHERE S.C > 5;Division for and reads as: an A such that there is no B of S that fails to appear with it in R. If S is empty, the query returns every A of R, which agrees with .
SELECT DISTINCT r.A
FROM R r
WHERE NOT EXISTS (
SELECT *
FROM S s
WHERE NOT EXISTS (
SELECT *
FROM R r2
WHERE r2.A = r.A
AND r2.B = s.B
)
);Algebra idea | SQL form | Calculus form |
|---|---|---|
Difference |
| |
Intersection |
| |
Division | double | inside |
Natural join |
| with equal common attributes |
Outer join |
| no direct form: it needs tuples padded with |
EXAM TIP
When a question says every, all or never, think division or difference: for all is , which is , which is a double NOT EXISTS. An inner join alone can only say there exists.
PREVIOUS-YEAR QUESTIONS
Try each question first, then open the answer. We placed each question under a topic ourselves; the exam paper does not label topics.
See these papers in full: GATE CSE 2026 Set 1 · GATE CSE 2026 Set 2 · GATE CSE 2025 Set 1 · GATE CSE 2024 Set 1 · GATE CSE 2024 Set 2 · GATE CSE 2023 · GATE CSE 2022 · GATE CSE 2018 · GATE DA 2026 · GATE DA 2025 · GATE DA 2024
Consider a relational database schema with two relations and .
Let be a tuple relational calculus expression.
Which one of the following relational algebraic expressions is equivalent to ?
In the context of DBMS, consider the two sets T and S given below.
Which one of the following is the correct match from T to S?
Tap to open full sizeA two-column table headed T and S with three rows: I: Logical schema with L: Views; II: Physical schema with M: File organization and indexes; III: External schema with N: Relations.
I – L, II – M, III – N
I – M, II – L, III – N
I – N, II – M, III – L
I – N, II – L, III – M
Consider the given relations , and . The relation has three columns , and . The relation has three columns , and . The relation has two columns and .
Relation : (P1, Q1, R1), (P2, Q2, R2), (P3, Q3, R2).
Relation : (P1, Q1, 2), (P1, Q2, 5), (P2, Q1, 6), (P3, Q3, 1).
Relation : (P1, T1), (P3, T2), (P4, T3), (P4, NULL).
Consider the relational algebra expression
where denotes natural join operation.
Which of the following options is the correct output for the given expression?
Tap to open full sizeThree small tables side by side. X(P,Q,R): rows (P1,Q1,R1), (P2,Q2,R2), (P3,Q3,R2). Y(P,Q,S): rows (P1,Q1,2), (P1,Q2,5), (P2,Q1,6), (P3,Q3,1). Z(P,T): rows (P1,T1), (P3,T2), (P4,T3), (P4,NULL).
Two rows (P1, R1, 2) and (P1, R1, 5)
Three rows (P1, R1, 2), (P1, R1, 5) and (P2, R2, 6)
One row (P1, R1, 2)
Zero rows
Let there be two relations and as shown. has three columns , and . has two columns and .
Relation X (columns P, Q, R): (P1, Q1, R1), (P2, Q2, R2), (P3, Q3, R2).
Relation Y (columns P, S): (P1, 10), (P1, 15), (P2, 20), (P3, 1).
Consider that the following tuple relational calculus expression is evaluated.
The number of tuples that will be returned is ______. (Answer in integer)
Tap to open full sizeTwo tables side by side. X has header P, Q, R and rows (P1, Q1, R1), (P2, Q2, R2), (P3, Q3, R2). Y has header P, S and rows (P1, 10), (P1, 15), (P2, 20), (P3, 1).
Consider two relations describing teams and players in a sports league:
Which ONE of the following tuple relational calculus queries returns the name of the players who play for the team having as 'MI'?
Consider the following three relations:
Car (model, year, serial, color)
Make (maker, model)
Own (owner, serial)A tuple in Car represents a specific car of a given model, made in a given year, with a serial number and a color. A tuple in Make specifies that a maker company makes cars of a certain model. A tuple in Own specifies that an owner owns the car with a given serial number. Keys are underlined; (owner, serial) together form key for Own. (⋈ denotes natural join)
Which one of the following options describes what the above expression computes?
All owners of a red car, a car made by ABC, or a red car made by ABC
All owners of more than one car, where at least one car is red and made by ABC
All owners of a red car made by ABC
All red cars made by ABC
Consider the following tables, Loan and Borrower, of a bank.
Query: where denotes natural join.
The number of tuples returned by the above relational algebra query is ______ (Answer in integer)
Tap to open full sizeTwo tables. Loan(loan_num, branch_name, amount): (L11, Banjara Hills, 90000), (L14, Kondapur, 50000), (L15, SR Nagar, 40000), (L22, SR Nagar, 25000), (L23, Balanagar, 80000), (L25, Kondapur, 70000), (L19, SR Nagar, 65000). Borrower(customer_name, loan_num): (Anand, L11), (Karteek, L11), (Karteek, L14), (Ankita, L15), (Gopal, L19), (Karteek, L22), (Karteek, L23), (Sunil, L23), (Sunil, L25).
Consider the following two relations, R(A,B) and S(A,C):
The total number of tuples obtained by evaluating the following expression
is _________
Tap to open full sizeTwo tables. 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). Then the expression sigma_B<C(R join_R.A=S.A S).
The relation schema, Person(pid, city), describes the city of residence for every person uniquely identified by pid (pid is underlined, the key). The following relational algebra operators are available: selection, projection, cross product, and rename.
To find the list of cities where at least 3 persons reside, using the above operators, the minimum number of cross product operations that must be used is
1
2
3
4
Consider a database that includes the following relations:
Defender(name, rating, side, goals)
Forward(name, rating, assists, goals)
Team(name, club, price)
Which ONE of the following relational algebra expressions checks that every name occurring in Team appears in either Defender or Forward, where denotes the empty set?
Which one of the options given below refers to the degree (or arity) of a relation in relational database systems?
Number of attributes of its relation schema.
Number of tuples stored in the relation.
Number of entries in the relation.
Number of distinct domains of its relation schema.
Consider the following three relations in a relational database.
, ,
Which of the following relational algebra expressions return the set of s who own all the brands?
Consider the relations r(A, B) and s(B, C), where s.B is a primary key and r.B is a foreign key referencing s.B. Consider the query
Q: r ⋈ (σ_{B<5}(s))
Let LOJ denote the natural left outer-join operation. Assume that r and s contain no null values.
Which one of the following queries is NOT equivalent to Q?
σ_{B<5}(r ⋈ s)
σ_{B<5}(r LOJ s)
r LOJ (σ_{B<5}(s))
σ_{B<5}(r) LOJ s
PRACTICE
Relation and relation . Under set semantics, how many tuples does the full outer join on the common attribute contain?
Answer:
Matching on : and each meet , giving 2 tuples.
meets and , giving 2 more, so .
Unmatched in : and , since has no . So .
Unmatched in : , since has no . So .
Full outer join size .
Let record that employee works on project , and let list all projects; is non-empty. Which expressions return exactly the employees who work on every project in , as a relation with schema ?
Answer: (A), (B)
A is the definition of division with and : the -values paired in with every tuple of . Correct.
B is the expansion of division: lists every possible (employee, project) pair, subtracting leaves the missing pairs, and removing those employees leaves exactly the ones with no gap. Correct.
C returns employees who work on at least one project that is in , not necessarily all of them. Wrong.
D is a Cartesian product with schema , not a set of employees. Wrong.
has 6 tuples and has 4 tuples. Under set semantics, let . What are the minimum and maximum possible values of , in that order?
2 and 10
6 and 10
0 and 10
2 and 6
Answer: (A)
Let , so .
, hence .
At , (maximum). At , (minimum, when ).
So the range is 2 to 10.
Which of the following tuple relational calculus expressions is NOT safe? Here and are relations with the same single attribute , and in every option the answer tuple has the single attribute .
Answer: (B)
A restricts to tuples of , so the answer is a subset of a finite relation. Safe.
B asks for every tuple not in , and there are infinitely many such tuples over an unbounded domain. Unsafe.
C fixes the only attribute of to an -value that occurs in . Safe.
D is the union of two finite relations, and each disjunct bounds . Safe.
A relation has exactly two candidate keys, and . How many distinct non-empty attribute sets are superkeys of ?
Answer:
A superkey is any set that contains a candidate key.
Sets containing : , which is 4 sets.
Sets containing but not : only , which is 1 set.
Total . Check with the formula: .
Let and be union-compatible relations with schema . Under set semantics, which equivalence does NOT hold for every instance?
Answer: (C)
A holds: a tuple with is in exactly when it is in , so both sides are the tuples of with that are not in .
B holds: every -value of comes from a tuple of or of , and conversely.
C fails: with and , the left side is but the right side is .
D holds: cascading selections is the same as selecting on the conjunction.
OFFICIAL GATE 2027 SYLLABUS WORDING
Copied from the GATE 2027 syllabus; see all 2027 syllabi.
GATE CS
Relational model: relational algebra, tuple calculus
GATE DA
relational model: relational algebra, tuple calculus