Relational Algebra Questions with Solutions | Complete Guide for DBMS Learners
Relational Algebra Question with Solution
Question
Suppose relation R(ABC) has the following tuples:
A | B | C |
---|---|---|
1 | 2 | 3 |
1 | 2 | 3 |
3 | 2 | 1 |
How many tuples are resulted by the given RA expression?
πAB(R) ⋈R.B < S.B ρS(A, B)(πBC(R))
- (a) 6
- (b) 2
- (c) 3
- (d) 4
Solution
The correct answer is: (b) 2.
The relational algebra expression breaks down as follows:
- Projection
πAB(R)
results in the following relation:
A B 1 2 3 2 - Projection
πBC(R)
followed by renaming produces:
A B 2 3 2 1 - The join
⋈R.B < S.B
is performed, yielding:
A B A’ B’ 1 2 2 3 3 2 2 3
Relational Algebra Question on Student Enrollments
Question
Consider the following schema:
- Student (
Sid
,Sname
,Sage
) - Course (
Cid
,CourseName
,Credit
) - Enrolled (
Sid
,Cid
)
The relational algebra query is:
Q = πSid(Student) - πSid(σCredit < 5(Course) ⋈ Enrolled)
Which of the following is correct about the relational algebra query Q?
- (a) Finds
Sid
of students who enrolled in at least one course with credit greater than 5. - (b) Finds
Sid
of students who enrolled in all courses with credit ≥ 5. - (c) Finds
Sid
of students who enrolled in all courses with credit less than 5. - (d) None of these.
Solution
The correct answer is: (b) Finds Sid
of students who enrolled in all courses with credit ≥ 5.
Explanation:
- First, compute:
S = πSid(σCredit < 5(Course) ⋈ Enrolled)
This computes the
Sid
of students who are enrolled in at least one course with credit less than 5. - Next, compute:
Q = πSid(Student) - S
This computes the
Sid
of students who are enrolled in every course with credit greater than or equal to 5.
Advanced Relational Algebra Questions with Solutions
Questions
Q6
Consider the selection of the form SA ≤ 200(r)
, where r
is a relation with 1000 tuples. Assume attribute values of A
among the tuples are uniformly distributed in the interval [1, 500]. Find the number of tuples returned by the given query:
- (a) 100
- (b) 200
- (c) 300
- (d) 400
Q7
Consider the relation P(A, B, C)
, Q(C, D, E)
, and R(E, F)
having tuples 200, 300, and 100 respectively. Estimate the number of tuples in relation P ⋈ Q ⋈ R
.
- (a) 100
- (b) 200
- (c) 300
- (d) 400
Q8
Consider the following statements:
- If
R(A, B)
andS(A, B)
are any two relations, thenπA(R ∪ S) = πA(R) ∪ πA(S)
. - If
P(A, B)
andQ(A, B)
are two relations, thenπA(R ∩ S) = πA(P) ∩ πA(Q)
.
Which of the above statements is/are correct?
- (a) Only (i)
- (b) Only (ii)
- (c) Both (i) and (ii)
- (d) None of these
Solutions
Q6
Answer: (d) 400
Explanation:
A is uniformly distributed among [1, 500]. The number of tuples in [1, 100], [101, 200], [201, 300], [301, 400], and [401, 500] is 200 each. Therefore, the number of tuples in [1, 200] is 400.
Q7
Answer: (a) 100
Explanation:
P ⋈ Q
: The common attribute isC
, which is a key for bothP
andQ
.|P ⋈ Q| = min(200, 300) = 200
tuples.R1 ⋈ R
: The common attribute isE
, which is a key for bothR1
andR
.|R1 ⋈ R| = min(200, 100) = 100
tuples.- So,
|P ⋈ Q ⋈ R| = 100
tuples.
Q8
Answer: (a) Only (i)
Explanation:
Statement (ii) is false. For example, consider:
P(A, B) = {(0, 1)} Q(A, B) = {(0, 2)} πA(P ∩ Q) = ∅ but πA(P) ∩ πA(Q) = {0}
Therefore, (i) is correct and (ii) is false.
Relational Algebra Question: Finding the Lowest Value
Question
Consider the relation R(A, B, C, D)
. Which relational algebra expression returns the lowest value of A
?
- (a)
πR1.A(R1 ⋈R1.A < R2.A R2)
- (b)
πA(R) − πR1.A(R1 ⋈R1.A > R2.A R2)
- (c)
πA(R) − πR1.A(R1 ⋈R1.A < R2.A R2)
- (d) None of these (
R1
andR2
are just renames ofR
)
Solution
Answer: (b)
Explanation:
- Compute:
S = πR1.A(R1 ⋈R1.A > R2.A R2)
This finds all values of
A
except the lowest. - Subtract
S
fromπA(R)
to find the lowest value ofA
:πA(R) − S
Relational Algebra: Full Outer Join and Null Values
Question
Consider the following two tables:
Table: R1
A | B | C |
---|---|---|
1 | 2 | 3 |
1 | 2 | 4 |
2 | 1 | 3 |
3 | 1 | 3 |
Table: R2
A | B | D |
---|---|---|
1 | 2 | 1 |
2 | 1 | 5 |
4 | 2 | 1 |
3 | 2 | 1 |
The number of rows where null entries are present in the table R1 ⟗ R2
(R1 natural full outer join R2) is _______.
Solution
Answer: 7
Explanation:
In a natural full outer join, all rows from both tables are included. Rows with no matching values in the other table result in null entries. After performing the join:
- Rows from
R1
that do not have a match inR2
result in null values for columnsD
. - Rows from
R2
that do not have a match inR1
result in null values for columnsC
.
In this example, there are 7 such rows with null entries after the join.
Relational Algebra, DBMS Questions, GATE DBMS, UGC NET DBMS, Full Outer Join, Relational Algebra Solutions, SQL Joins, DBMS Study Guide, Database Queries.
Tag:Advanced Relational Algebra, Database Management Systems, Database Queries., DBMS Chapter Questions, DBMS Competitive Exams, DBMS Concepts, DBMS Exercises, DBMS for GATE, DBMS for NET, DBMS GATE Questions, DBMS Interview Questions, DBMS Natural Join, DBMS Outer Join, DBMS Preparation, DBMS Q&A, DBMS Query Solutions, DBMS Questions, DBMS Solutions, DBMS solved questions, DBMS Study Guide, DBMS Theory, DBMS Tutorials, Full Join Explained, Full Outer Join, Full Outer Join Null Values, GATE DBMS, GATE DBMS Notes, Learn Relational Algebra, Natural Join, Outer Join Explained., Outer Join Nulls, Projection in DBMS, relational algebra, Relational Algebra Examples, Relational Algebra Expressions, Relational Algebra for Beginners, Relational Algebra in SQL, Relational Algebra Join, Relational Algebra Practice, Relational Algebra Practice Questions, Relational Algebra Questions, Relational Algebra Schema, Relational Algebra Simplified, Relational Algebra Solutions, Relational Algebra Step-by-Step, Relational Database Questions, Selection in DBMS, SQL Joins, SQL Query Optimization, SQL vs Relational Algebra, UGC NET DBMS, UGC NET DBMS Notes