0% found this document useful (0 votes)
57 views20 pages

Mock

The document contains solutions to mock quiz questions on topics related to databases and relational algebra. The questions cover concepts like temporal databases, BCNF, functional dependencies, relational algebra operations, and lossless decomposition. Example solutions and explanations are provided for multiple choice and multiple selection questions.

Uploaded by

nathandawson211
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
57 views20 pages

Mock

The document contains solutions to mock quiz questions on topics related to databases and relational algebra. The questions cover concepts like temporal databases, BCNF, functional dependencies, relational algebra operations, and lossless decomposition. Example solutions and explanations are provided for multiple choice and multiple selection questions.

Uploaded by

nathandawson211
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 20

BSCCS2001: Mock Quiz 2 with Solutions

Weeks 1 to 8
1. Kiran was born on 19 Janurary, 1980. His date of birth was registered in the municipal
corporation database on 21 January, 1980.
Considering that the municipal corporation database is a temporal database, which
among the following statements is true.

[MCQ:2points]

19 Janurary, 1980 is a valid time which provides historical information, whereas
21 January, 1980 is a transaction time which provides rollback information.
⃝ 19 Janurary, 1980 is a valid time which provides rollback information, whereas
21 January, 1980 is a transaction time which provides historical information.
⃝ 19 Janurary, 1980 is a transaction time which provides rollback information,
whereas 21 January, 1980 is a valid time which provides historical information.
⃝ 19 Janurary, 1980 is a transaction time which provides historical information,
whereas 21 January, 1980 is a valid time which provides rollback information.

Solution:

• 19 Janurary, 1980 is time when actual event took place. Thus, it is the valid
time and provides historical information.

• 21 January, 1980 is the time when event information is entered into the tam-
poral database. Thus, it is transaction time and provides rollback information.

Page 2
2. Consider the relational schema R(A, B, C, D), where the domains of A, B, C and D
include only atomic values. Identify the sets of functional dependencies satisfied by R
such that R is in BCNF.

[MSQ:2points]

FD: {ABC → D, AD → BC}
⃝ FD: {AB → CD, CD → B, D → A}

FD: {A → B, B → C, C → D, D → A}
⃝ FD: {AB → D, D → B, D → C, C → A}

Solution:
For FD: {ABC → D, AD → BC}, since (ABC)+ = ABCD and (AD)+ = ABCD,
ABC and AD are superkeys. Thus, it is in BCNF.
For FD: {AB → CD, CD → B, D → A}, since (D)+ = AD, D is not superkey in
FD D → A . Thus, it is not BCNF.
For FD: {A → B, B → C, C → D, D → A} , since (A)+ = ABCD, (B)+ = ABCD,
(C)+ = ABCD, (D)+ = ABCD, A, B, C, D all are superkeys . Thus, it is in BCNF.
For FD: {AB → D, D → B, D → C, C → A} , since (C)+ = CA, C is not superkey
in FD C → A . Thus, it is not BCNF.

Page 3
3. Which among the following methods of psycopg2 is/are used to execute SQL statements?

[MSQ:2points]

cursor.execute()

cursor.executemany()
⃝ cursor.fetchall()
⃝ cursor.fetchmany()

Solution:
The methods cursor.execute() and cursor.executemany() are used to execute
an SQL statement.
Whereas, cursor.fetchall() fetches all the rows and cursor.fetchmany() fetches
next n (required to pass as an argument in the method) rows from a query result.

Page 4
4. Consider a relation R(A, B, C, D, E, F, G, H, I, J) having functional dependencies as
follows F = {AB → C, B → F, D → IJ, A → DE, F → GH}.
Then, which among the following is a lossless decomposition of R? [MCQ:4 Points]
⃝ R1 (A, B, C, I, J), R2 (D, E, F ) and R3 (G, H, I)
⃝ R1 (A, B, C), R2 (D, E, F ), R3 (G, H) and R4 (D, I, J)

R1 (A, B, C), R2 (A, D, E), R3(B, F ), R4 (F, G, H) and R5 (D, I, J)
⃝ R1 (A, B, C, D), R2 (D, E), R3 (B, F ), R4 (F, G, H) and R5 (D, I, J)

Solution:
Option 1: R1(A, B, C, I, J), R2(D, E, F ) and R3(G, H, I) is a lossy decomposition.

• R1 ∪ R2 ∪ R3 = R

• Here, R1 ∩ R2 = ϕ, R2 ∪ R3 = ϕ, and also R1 ∪ R3 = ϕ

Option 2: R1(A, B, C), R2(D, E, F ), R3(G, H) and R4(D, I, J) is a lossy decompo-


sition.

• R1 ∪ R2 ∪ R3 ∪ R4 = R

• R2 ∩ R4 = D, by using D → IJ, we can determine R4.

• But, R1 ∩ R3 = ϕ

Option 3: R1(A, B, C), R2(A, D, E), R3(B, F ), R4(F, G, H) and R5(D, I, J)

• R1 ∪ R2 ∪ R3 ∪ R4 ∪ R5 = R

• R1 ∩ R3 = B, by using B → F, we can determine R3. Let R13 = R1 ∪ R3 =


(A, B, C, F)

• R2 ∩ R5 = D, by using D → IJ, we can determine R5. Let R25 = R2 ∪ R5 =


(A, D, E, I, J)

• Now, R13 ∩ R4 = F, by using F → GH, we can determine R4. Let R134 =


R13 ∪ R4 = (A, B, C, F, G, H)

• Now, R134 ∩ R25 = A, by using A → DE and D → IJ, we can determine R25.


So, given decomposition is lossless and thus option 3 is correct.

Option 4: R1 (A, B, C, D), R2 (D, E), R3 (B, F ), R4 (F, G, H) and R5 (D, I, J)

• R1 ∪ R2 ∪ R3 ∪ R4 ∪ R5 = R

Page 5
• R1 ∩ R3 = B, by using B → F, we can determine R3. Let R13 = R1 ∪ R3 =
(A, B, C, D, F)

• R2 ∩ R5 = D, by using D → IJ, we can determine R5. Let R25 = R2 ∪ R5 =


(D, E, I, J)

• Now, R13 ∩ R4 = F, by using F → GH, we can determine R4. Let R134 =


R13 ∪ R4 = (A, B, C, D, F, G, H)

• Now, R134 ∩ R25 = D, here we cannot determine R25 or R134.


So, given decomposition is lossy.

Page 6
5. A database designer observes that a relation R is in 2NF, and has transitive functional
dependencies. Relation R is then decomposed into relations R1 and R2, such that the
decomposition is 3NF and lossless. Now, the designer observes that, R2 is in 3NF
but not in BCNF. Relation R2 is further decomposed into R3 and R4 such that the
decomposition is in BCNF, and it satisfies the following conditions:

• R2 = R3 ∪ R4
• R3 ∩ R4 → R3

Choose the correct options. [MSQ:3Points]


⃝ The decomposition of R2 into R3 and R4 is lossy.

The decomposition of R2 into R3 and R4 is lossless.

R = R1 ⋊⋉ R2
⃝ The number of tuples in R2 is more than the number of tuples in (R3 ⋊
⋉ R4)

Solution:

• Since, the decomposition of R into R1 and R2 is lossless, then it must satisfy


R = R1 ⋊ ⋉ R2.

• From the given conditions, we can say that decomposition of R2 into R3 and
R4 is lossless. Since it is lossless decomposition, The number of tuples in R2 is
equal to the number of tuples in (R3 ⋊ ⋉ R4) i.e., R2 = R3 ⋊
⋉ R4.

Page 7
6. Find the equivalent SQL statement corresponding to the below relational algebraic ex-
pression :
[ MCQ: 2 points]

Πemp name σemployee.dept id=department.dept id ∧ dept name=′ F inance′ (employee × department)
⃝ select emp_name from employee, department
where dept_name=‘Finance’;
⃝ select e.emp_name from employee e, department d
where d.dept_name=‘Finance’;
⃝ select e.emp_name from employee e, department d
where e.dept_id=d.dept_id or d.dept_name=‘Finance’;

select e.emp_name from employee e, department d
where e.dept_id=d.dept_id and d.dept_name=‘Finance’;

Solution: σemployee.dept id=department.dept id (employee × department) will associate


employee names with the department details, on equality between employee.dept id
and department.dept id.

σdept name=′ F inance′ (σemployee.dept id=department.dept id (employee×department)) will se-


lect out the department of Finance.

After simplifying it, we get 


σemployee.dept id=department.dept id ∧ dept name=′ F inance′ (employee × department


Πemp name σemployee.dept id=department.dept id ∧ dept name=′ F inance′ (employee×department)
will project down the employee names.

Option 1, Option 2 and Option 3 will give incorrect results, i.e., they fetch the
wrong employee names.

Option 4 will give the name of only those employees who work in the ’Finance’
department.

Page 8
7. Let R(V, W, X, Y, Z) be a given relation with the following functional dependencies:
F = {V → W, W X → Z, Y Z → V }
Then, which among the following is/are the candidate key(s)?
[MSQ: 3 points]

⃝ XY

W XY

V XY
⃝ VW

Solution: Consider the closure of each set of attributes given in the options. We can
see that the closures of options 2 and 3 contain all attributes. So, both W XY and
V XY are super keys. Since both W XY and V XY are minimal, both are candidate
keys.

Page 9
8. Consider relational instance given in Figure 1.
[MCQ: 2 points]

Figure 1: Relational instance

Which of the following functional dependencies does not hold on the given table?
⃝ V → WX
⃝ YZ →X

X →YZ
⃝ WY → Z

Solution: A functional dependency is a relationship between attributes sets. For


any relation R, if an attribute Y is functionally dependent on an attribute X, de-
noted by X → Y , then for every instance of X, the value of X uniquely determines
the value of Y .

Option 3 : For X → Y Z, the value of X in the first tuple, 8, determines 7 AND 5.


and the same value of X in the second tuple determines 7 AND 1. So, X → Y Z
violates the basic principles of functional dependencies.
Thus, option 3 is correct.

Page 10
9. In the relational schema given below, all attributes take atomic values only.
R(bike name, bike model, bike engine no)

Suppose R satisfies the following functional dependencies:


bike name → bike model
bike model → bike engine no
bike engine no → bike name
If R is decomposed into:
R1(bike name, bike model) and
R2(bike model, bike engine no),
then the decomposition is: [MCQ: 4 points]

a lossless decomposition as well as a dependency preserving one
⃝ not a lossless decomposition but dependency preserving
⃝ a lossless decomposition but not dependency preserving
⃝ neither a lossless decomposition nor dependency preserving

Solution:
1.Attributes(R1) ∪ Attributes(R2) = R
2.Attributes(R1) ∩ Attributes(R2) ̸= ϕ
3. bike model is a candidate key of R2 table
So, decomposition is lossless

Decomposition D = {R1,R2..Rn} of relation R is dependency preserving with


respect to Functional dependency F if :
Closure of Union of all functional dependencies with respect to each relation is equiv-
alent to closure of F.
Decomposition:
here,
R1(bike name, bike model)

bike name → bike model


bike model → bike name

R2(bike model, bike engine no)

bike model → bike engine no


bike engine no → bike model
here, (R1 ∪ R2)+ = (R)+
So, dependency is preserved

Page 11
10. Consider the relation R(M, N, O, P, Q) with the functional dependency set
F ={N → P, Q → M, OP → Q, M → N O}.

Choose all the correct statement(s) among the following.

[MSQ:3 points]

⃝ R is in BCNF and all dependencies in F are preserved on R.


⃝ If R is decomposed into 3NF (but not BCNF) then all dependencies on R can
not be preserved.
⃝ R can be decomposed into BCNF such that all dependencies are preserved.

If R is decomposed into BCNF then all dependencies on R can not be pre-
served.

Solution: Candidate keys of R = M, Q, OP, ON.


So all the attributes are prime and hence we can infer that the relation is in 3NF.
Also we can see that all the functional dependencies in F is applicable on R so R is
a relation which is in 3NF and it is also retaining all the dependencies.
But R is not in BCNF since in N → P the left hand side i.e. N is not a superkey.
In order to make it BCNF we have to decompose the table further into : R1(M,N,O,Q)
and R2(N,P ).
But in such a decomposition the functional dependency OP → Q is lost, so depen-
decies are not preserved.

Therefore option D is the correct choice.

Page 12
11. Consider a relation R(I, J, K, L, M, N ) with the following set of functional dependencies.
F ={IK → N, L → M N, JK → L, KN → JL, IKL → J, KM → IN }
From among the following options, choose all the sets of functional dependencies which
serve as canonical covers of F on R.

[MSQ: 4 points]

⃝ FC ={L → M N, JK → L, KM → I, KM → N }

FC ={L → M N, JK → L, KM → I, IK → N, KN → J}
⃝ FC ={L → M N, JK → L, KM → IJ, IK → J}

FC ={L → M N, JK → L, KM → I, IK → J, KN → L}

Solution: Refer slide 24.15, 24.16 for the algorithm to find canonical cover.

Page 13
12. Pseudo-transitivity is a derived Armstrong’s axiom. From among the options, select
those basic Armstrong’s axiom(s) which are used to derive the pseudo-transitivity axiom.

[MSQ: 2 points]

⃝ Composition Axiom
⃝ Decomposition Axiom

Transitivity Axiom

Augmentation Axiom

Solution: Transitivity and augmentation axiom is used to derive pseudo-transitivity


axiom.

Page 14
13. Consider a string of pending block references in the order given: 3, 2, 4, 1, 3, 2, 4, 1, 4, 2.
The system has a buffer with 3 slots. Assume that initially the buffer is empty. If LRU
buffer replacement policy is used, then what will be a number of misses and number of
hits?
(2 ∗ Number of misses) + (3 ∗ Number of hits)
[NAT: 4 points]

Answer: 22

Solution:
In the given block reference order of 10 blocks, the first 8 block references would be
miss, only the last 2 block reference would be hit when LRU replacement algorithm
is used.
Accordingly, the answer would be :

2 ∗ 8 + 3 ∗ 2 = 22

Page 15
14. Consider the Binary Search Tree (BST) shown in Figure 2.

Figure 2: Binary Search Tree (BST)

Which of the following is/are the correct insertion order(s) which will result in the given
BST? [MSQ: 4 points]
⃝ 64, 31, 20, 52, 10, 96, 98, 69, 84, 25, 79

64, 31, 20, 52, 10, 96, 25, 79, 84, 98, 69
⃝ 64, 31, 20, 52, 10, 84, 98, 25, 79, 69, 96
⃝ 64, 31, 20, 52, 10, 84, 25, 69, 96, 98, 79

Solution: Option 1: 64, 31, 20, 52, 10, 96, 98, 69, 84, 25, 79 will result in :

Option 2: 64, 31, 20, 52, 10, 96, 25, 79, 84, 98, 69 will result in :

Page 16
Option 3: 64, 31, 20, 52, 10, 84, 98, 25, 79, 69, 96 will result in:

Option 4: 64, 31, 20, 52, 10, 84, 25, 69, 96, 98, 79 will result in:

Thus, option 2 is the correct option.

Page 17
15. Consider a disk having 128 tracks per surface, 512 sectors per track and 256 bytes/sector.
If the minimum number of bits required to access a sector is 21, then find out the number
of platters required? [NAT: 3 points]
Ans: 16

Solution: The total number of sectors = 2n , where n is a number of bits required


to access a sector.
Total no. of sectors = 221 = 2097152.
Now, Total no. of sectors = no. of recording surfaces * 128 * 512 = 2097152
Thus, no. of recording surfaces = 32.
No of platter=16

Page 18
16. Consider a relation R(A, B, C, D, E ) with the following multivalued dependencies:

• A →→ B
• B →→ D

Suppose relation R contains the tuples (0, 1, 2, 3, 4) and (0, 5, 6, 7, 8). Which of the
following tuple(s) must also be in R? [ MSQ: 4 points]

⃝ (0, 1, 2, 7, 8)

(0, 5, 6, 3, 8)

(0, 1, 6, 7, 8)
⃝ (0, 1, 6, 3, 4)

Solution: First consider the two given tuples. Try to apply the given MVDs to any
pair of tuples that have the same values for the attributes on the left side of the
MVD.
Each application of an MVD lets you add two tuples to the relation: the tuples
formed by swapping the values for the attributes on the right side of the MVD.
This can be done using the formal definition of an MVD. Repeat this process until
all the tuples implied by the MVDs are already in the relation.

Page 19
17. Which of the following components of MVC is/are responsible for receiving events, pro-
cessing and generating a view for the user?
[MSQ: 2 points]
⃝ View
⃝ Model

Controller
⃝ All of these

Solution: Model-View-Controller (MVC) architecture:

• model: business logic

• view: presentation of data, depends on display device

• controller: receives events, executes actions, and returns a view to the user

Page 20

You might also like