Q1: Consider the following two relations, R(A,B) and S(A,C) : (2024 SET 1)The total number of tuples obtained by evaluating the following expression σ B < C ( R ⋈ R . A = S . A S ) is ____
(a) 1
(b) 2
(c) 4
(d) 6
Ans: (b)
Sol: The output of R (⋈ R . A = S . A S is simply return the number of tuples where R.A value is equal to S.A. So the output is as follow:
from the above table now we have to perform (σ B < C ( R ⋈ R . A = S . A S)) . it return the number of rows where B′s value is less than C. so the output is:
So the given expression returns 2 tuples as output.
Q2: A relation r ( A , B ) in a relational database has 1200 tuples. The attribute A has integer values ranging from 6 to 20, and the attribute B B has integer values ranging from 1 to 20. Assume that the attributes A and B are independently distributed. (2021 SET 1)
The estimated number of tuples in the output of σ ( A >10 )∨( B =18 ) ( r )) is ____________
(a) 1200
(b) 205
(c)15
(d) 820
Ans: (d)
Sol:
P (A >10 v B=18)= P(A > 10) + P(B = 18) - P(A > 10 v B = 18)
= 2/3 + 1/20 - 1/30 = (40 + 3 - 2)/60 = 41/60
Estimated number of tuples = 41/60 X 1200 = 820
The above answer is TRUE for SQL SELECT but not for Relational Algebra as by theory relational algebra operates on a set which means all the elements must be distinct. Since we have 15 distinct possible values for A and 20 distinct possible values for B , in strict relational algebra we’ll get
Estimated number of tuples = 41/60 X (15 X20) = 205
Official Answer: 205 OR 820 .
Q3: Consider a database that has the relation schemas EMP(EmpId, EmpName, DepId) and DEPT(DeptName, DeptId). Note that the DeptId can be permitted to be NULL in the relation EMP. Consider the following queries on the database expressed in tuple relational calculus. (2017 SET 1)
Which of the above queries are safe?
(a) (I) and (II) only
(b) (I) and (III) only
(c) (II) and (III) only
(d) (I), (II) and (III)
Ans: (d)
Sol: before ∧ operation all three expressions are the same,
i.e.return true if for each tuple t we have finite no of tuple u in employee table for which they have same employee_name.
(I) but in 2 nd part, for each tuple v in department there may exist infinite no of tuple t for which they may not be equal.
i.e. true for finite no of tuples ∧ true for infinite no of tuples, over all true for finite tuple.
(II) there may exist infinite no of tuple for which at least one tuple v belongs to department table for which they may not be equal.
i.e. true for finite no of tuples ∧ true for infinite no of tuples, over all true for finite tuple.
(III) this one actually true for finite no of tuples, as there may exist only finite tuple which may be equal to at least one tuple v in
department. because department table contain finite no of tuple all tuple t which are same may not be more than all tuple v in
department table in case of equality operation.
i.e. true for finite ∧ true for finite tuple, over all true for finite tuple.
So all TRC query will return finite tuple which implies all are safe.
Q4: Let R and S be relational schemes such that R={a,b,c} and S={c}. Now consider the following queries on the database: (2009)
I. π R−S (r)−π R−S (π R−S (r) × S−π R−S , S (r))
II. {t∣t ∈ πR−S (r) ∧ ∀u ∈ s (∃ v ∈r(u = v[s] ∧ t = v[R − S]))}
III. {t∣t ∈ πR−S (r) ∧ ∀u ∈ r (∃ v ∈s (u = v[s] ∧ t = v[R − S]))}
Which of the above queries are equivalent?
(a) I and II
(b) I and III
(c) II and IV
(d) III and IV
Ans: (a)
Sol:
1. π R-S(r) - π R-S ( π R-S(r) X s - π R-S, S(r))
= π a, b (r) – π a, b (π a, b(r) X s - πR(r))
= (r/s)
2. Expanding logically the statement means to select t ( a , b ) from r such that for all tuples u in s , there is a tuple v in r , such that u = v [ S ] and t = v [ R − S ] . This is just equivalent to (r/s)
3. Expanding logically the statement means that select t ( a , b ) from r such that for all tuples v in r , there is a tuple u in s , such that u = v [ S ] and t = v [ R − S ] . This is equivalent to saying to select ( a , b ) values from r , where the c value is in some tuple of s .
4. This selects ( a , b ) from all tuples from r which has an equivalent c value in s .
Q5: Which of the following tuple relational calculus expression(s) is/are equivalent to ∀ t ∈ r ( P ( t ) ) ? (2008)
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
Ans: (c)
Sol: Only III is correct.
The given statement means for all tuples from r, P is true. III means there does not exist a tuple in r where P is not true. Both are equivalent.
IV is not correct as it as saying that there exist a tuple, not in r for which P is not true, which is not what the given expression means.
Q6: Consider the relation employee(name, sex, supervisorName) with name as the key. supervisorName gives the name of the supervisor of the employee under consideration. What does the following Tuple Relational Calculus query produce? (2007)
(a) Names of employees with a male supervisor.
(b) Names of employees with no immediate male subordinates
(c) Names of employees with no immediate female subordinates.
(d) Names of employees with a female supervisor
Ans: (c)
Sol: OR (∨) is commutative and associative, therefore i can rewrite given query as:
It is clear now they are saying something about female employees, This query does not say anything about male employees. Therefore Option A and B are out of consideration.
This query retrieves those e. name who satisfies this condition:
∀x[(employee (x) x. sex =' female) ⇒ x. supervisor Name ≠ e.name]
Means retrieves those e.name, who is not a supervisor of any female employees.
i.e it retrieves name of employees with no female subordinate.
(here "immediate" is obvious, as we are checking first level supervisor.)
Hence, option C.
Q7: Which of the following relational query languages have the same expressive power? (2006)
I. Relational algebra
II. Tuple relational calculus restricted to safe expressions
III. Domain relational calculus restricted to safe expressions
(a) II and III only
(b) I and II only
(c) I and III only
(d) I, II and III
Ans: (d)
Sol: Relational algebra is a procedural query language where we input - relations and it yields relations as output. It provides method to get the result. It is performed recursively on a relation and the in between results are relations(output). Basic set of operations for the relational model. Relational calculus is a non - procedural query language. It provides the query to get result. Higher level declarative language for specifying relational queries. Tuple Relational Calculus operates on each tuple.
Domain Relational Calculus operates on each column or attribute. Safe expression means fixed no. of tuple or column or attribute as a result But all of them has same expressive power. Just different ways to do so.
62 videos|66 docs|35 tests
|
1. What is Tuple Calculus in the context of computer science engineering? |
2. How does Tuple Calculus differ from Relational Algebra? |
3. What are the main components of Tuple Calculus? |
4. How is Tuple Calculus used in database management systems? |
5. Can you provide an example of a Tuple Calculus query? |
|
Explore Courses for Computer Science Engineering (CSE) exam
|