How to Solve Relational Algebra Problems for GATE
Last Updated :
07 Nov, 2024
Relational Algebra is fundamental or necessary for GATE computer science preparation. It is also an important section of the Database Management System (DBMS). Relational algebra provides a theoretical representation for querying and manipulating data in a relational database. Relational algebra has various operations like selection, projection, joins, union, and more.
In this article, Let’s discuss common types of questions in relational algebra that are asked in GATE. Before reading this article, you should have an idea about basic operators and extended operators in relational algebra.Â
Types of Relational Algebra Problems
Type-1: Given a relational algebra expression, find the result.Â
Suppose you have a relation Order(Prod_Id, Agent_Id, Order_Month) and you have to find out what will the following algebra expression return.Â
ÏOrder1.Prod_Id (Ï Order1.Prod_Id=Order2.Prod_Id
and Order1.Agent_Id <> Order2.Agent_Id
and Order1.Order_Month=Order2.Order_Month (Order2,Order1))
Process the expression starting from the innermost brackets.Â
In this example, we have renamed order to Order1 and Order2 (Both represent the same relation order). Then we have applied the conditional join between Order1 and Order2. It will return those rows where Product_Id and Order_Month of Order1 and Order2 are the same but Agent_Id of Order1 and Order2 is different. It implies the rows where the same product is ordered by two different agents in the same month. Then we are projecting the Prod_Id.Â
So the final output will return the Prod_Id of products that are ordered by different agents in the same month. We can do this by taking sample data. Let Order relation consists of the following data.Â
Table – OrderÂ
| Prod_Id |
Agent_Id |
Order_Month |
| P001 |
A001 |
JAN |
| P002 |
A002 |
FEB |
| P002 |
A001 |
FEB |
| P001 |
A002 |
FEB |
When we apply the following expression, the rows which are highlighted in blue will be selected.Â
ÏOrder1.Prod_Id=Order2.Prod_Id
and Order1.Agent_Id <> Order2.Agent_Id
and Order1.Order_Month=Order2.Order_Month (Order2,Order1))
| Order1.Prod_Id |
Order1.Agent_Id |
Order1.Order_Month |
Order2.Prod_Id |
Order2.Agent_Id |
Order2.Order_Month |
| P001 |
A001 |
JAN |
P001 |
A001 |
JAN |
| P002 |
A002 |
FEB |
P001 |
A001 |
JAN |
| P002 |
A001 |
FEB |
P001 |
A001 |
JAN |
| P001 |
A002 |
FEB |
P001 |
A001 |
JAN |
| P001 |
A001 |
JAN |
P002 |
A002 |
FEB |
| P002 |
A002 |
FEB |
P002 |
A002 |
FEB |
| P002 |
A001 |
FEB |
P002 |
A002 |
FEB |
| P001 |
A002 |
FEB |
P002 |
A002 |
FEB |
| P001 |
A001 |
JAN |
P002 |
A001 |
FEB |
| P002 |
A002 |
FEB |
P002 |
A001 |
FEB |
| P002 |
A001 |
FEB |
P002 |
A001 |
FEB |
| P001 |
A002 |
FEB |
P002 |
A001 |
FEB |
| P001 |
A001 |
JAN |
P001 |
A002 |
FEB |
| P002 |
A002 |
FEB |
P001 |
A002 |
FEB |
| P002 |
A001 |
FEB |
P001 |
A002 |
FEB |
| P001 |
A002 |
FEB |
P001 |
A002 |
FEB |
After projecting Order1.Prod_Id, the output will be P002 which is Prod_Id of products that are ordered by at least two different agents in the same month.Â
Note – If we want to find Prod_Id which are ordered by at least three different agents in same month, it can be done as:Â
ÏOrder1.Prod_Id (ÏOrder1.Prod_Id=Order2.Prod_Id
and Order1.Prod_Id=Order3.Prod_Id
and  Order1.Agent_Id <> Order2.Agent_Id
and Order1.Agent_Id <> Order3.Agent_Id
and Order2.Agent_Id <> Order3.Agent_Id
and Order1.Order_Month=Order2.Order_Month
and Order1.Order_Month=Order3.Order_Month((Order1,Order2),Order3) )
Type-2: Given two relations, what will be the maximum and minimum number of tuples after natural join?Â
Consider the following relation R(A,B,C) and S(B,D,E) with underlined primary key. The relation R contains 200 tuples and the relation S contains 100 tuples. What is the maximum number of tuples possible in the natural Join R and S?Â
To solve this type of question, first, we will see on which attribute natural join will take place. Natural join selects those rows which have equal values for common attribute. In this case, the expression would be like:Â
ÏR.B=S.B (R X S)
In relation R, attribute B is the primary key. So Relation R will have 200 distinct values of B. On the other hand, Relation S has BD as the primary key. So attribute B can have 100 distinct values or 1 value for all rows.Â
Case-1: S.B has 100 distinct values and each of these values match to R.BÂ

In this case, every value of B in S will match to a value of B in R. So natural join will have 100 tuples.Â
Case-2: S.B has 1 values and this values match to R.BÂ

In this case, every value of B in S will match to a value of B in R. So natural join will have 100 tuples.Â
Case-3: S.B has 100 distinct values and none of these values matches to R.BÂ

In this case, no value of B in S will match to a value of B in R. So natural join will have 0 tuple.Â
Case-4: S.B has 1 value and it does not match with R.BÂ

In this case, no value of B in S will match to a value of B in R. So natural join will have 0 tuples.Â
So the maximum number of tuples will be 100 and min will be 0.Â
Note – If it is explicitly mentioned that S.B is a foreign key to R.B, then Case-3 and Case-4 discussed above are not possible because the value of S.B will be from the values of R.B. So, the minimum and maximum number of tuples in natural join will be 100.Â
Consider the following three relations in a relational database.
Example: Employee(eId, Name), Brand(bId, bName), Own(eId, bId)
Which of the following relational algebra expressions return the set of eIds who own all the brands? (GATE 2022)
Option:
1. Ïeld (Own) / ÏbId (Brand)
2. Ïeld (Own)(ÏbId (Brand))
3. Ïeld (Own)(Ï (Brand,Own), Employee)
4. Ïeld (Own) ( ÏbId (Brand))
Ans: Option 1 is correct.
Concept:
The “Division operator” in relational algebra return all the entities that are associated with entities of different relation.
The result of the query in option 1:
It will display all the eId of relation “Own” which are associated with all the bId of relation “Brand”.
Conclusion
In conclusion, solving Relational Algebra problems for GATE requires a good understanding of core operations (like selection, projection, and join), derived operations (like intersection and division), and the ability to logically plan query steps. You must be understand the problem so you can breaking down problems into simpler tasks, applying the operations in an efficient sequence. Practicing with past GATE questions is game changer step to improve speed and accuracy. At the last, if you want to solve the question then you understand the problem, apply the operations and arrange the query in efficient sequence.
How to Solve Relational Algebra Problems for GATE – FAQ’s
What are the most important Relational Algebra operations for GATE?
The basic operations are Selection (Ï), Projection (Ï), Cartesian Product (Ã), Union (âŠ), Set Difference (-), Rename (Ï), and Join (âĻ). Derived operations like Intersection, Division, and Outer Joins are also important.
What are the common mistakes to avoid in Relational Algebra problems?
Common mistakes include misapplying join conditions, overlooking duplicates (for example, in Union), and neglecting to project necessary attributes in intermediate steps. Always keep track of the attributes and rows you need at each step of the operation.
How can I solve problems with nested queries?
Start from the innermost query, solve for the intermediate relation, and move outward. By breaking down the problem step-by-step, youâll keep track of the conditions and projected attributes at each level of nesting.
Similar Reads
How to Solve Relational Algebra Problems for GATE
Relational Algebra is fundamental or necessary for GATE computer science preparation. It is also an important section of the Database Management System (DBMS). Relational algebra provides a theoretical representation for querying and manipulating data in a relational database. Relational algebra has
6 min read
SELECT Operation in Relational Algebra
Prerequisite - Relational Algebra Select operation chooses the subset of tuples from the relation that satisfies the given condition mentioned in the syntax of selection. The selection operation is also known as horizontal partitioning since it partitions the table or relation horizontally. Notation
2 min read
How to Start GATE Preparation for CSE
GATE CSE 2025 is a crucial exam for students seeking admission to prestigious institutes like IITs, NITs, and IISc, or aiming for recruitment in PSUs. The competition is fierce, and a structured approach to preparation is essential. This guide provides you with essential strategies and tips to build
4 min read
PROJECT Operation in Relational Algebra
Prerequisite - Relational Algebra Project operation selects (or chooses) certain attributes discarding other attributes. The Project operation is also known as vertical partitioning since it partitions the relation or table vertically discarding other columns or attributes. Notation: πA(R) where
2 min read
Set Difference Operator in Relational Algebra
Relational Algebra is used to play with the data stored in relational databases. Relational Algebra has many operations to play with tables. One of the fundamental operations is set difference. This article will discuss Set Difference, its condition, and its examples. Key Terms Used in Set Differenc
4 min read
Example Queries on Relational Algebra
Given below are a few examples of a database and a few queries based on that. (1). Suppose there is a banking database which comprises following tables : Customer(Cust_name, Cust_street, Cust_city) Branch(Branch_name, Branch_city, Assets) Account (Branch_name, Account_number, Balance) Loan(Branch_na
1 min read
What are the Unary Operations in Relational Algebra?
The unary operations in Relational algebra are selection, projection, and rename. The select, project, and rename operators in relational algebra work on one relation only so they are called unary operators. In this article, we will discuss the unary operations in relational algebra. We will also di
4 min read
RENAME (ρ) Operation in Relational Algebra
Prerequisites - Introduction of Relational Algebra in DBMS, Basic Operators in Relational Algebra The RENAME operation is used to rename the output of a relation. Sometimes it is simple and suitable to break a complicated sequence of operations and rename it as a relation with different names. Reaso
2 min read
Extended Operators in Relational Algebra
Basic idea about relational model and basic operators in Relational Algebra: Relational Model Basic Operators in Relational Algebra Extended operators are those operators which can be derived from basic operators. There are mainly three types of extended operators in Relational Algebra: JoinIntersec
6 min read
Basic Operators in Relational Algebra
The Relational Model is a way of structuring data using relations, which are a collection of tuples that have the same attributes. Relational Algebra is a procedural query language that takes relations as input and returns relations as output. It uses a set of operators to manipulate and retrieve da
4 min read