Assignment 7 NPTEL DBMS January 2025
Assignment 7 NPTEL DBMS January 2025
Question 1
Consider the following lock compatibility matrix where S denotes a shared lock and X denotes
an exclusive lock:
S X
S True False
X False False
a) A transaction holding an S lock on a data item allows other transactions to acquire an S lock
but not an X lock on the same data item.
b) A transaction holding an S lock on a data item allows other transactions to acquire an X lock on
the same data item.
c) A transaction holding an X lock on a data item allows other transactions to acquire another X
lock on the same data item.
d) A transaction holding an X lock on a data item prevents other transactions from acquiring an S
lock on the same data item.
Answer: a), d)
Explanation: According to the lock compatibility matrix, a transaction holding an S lock allows
other transactions to acquire S locks but does not permit X locks. Therefore, statement (b) and (c)
are incorrect.
1
Question 2
Consider the following schedule S involving five transactions T1 , T2 , T3 , T4 , and T5 :
T1 T2 T3 T4 T5
W(X)
R(X)
W(Y)
W(X)
R(Z)
W(Y)
R(X)
W(Z)
Answer: (b)
Explanation: By drawing the precedence graph for the transactions and checking for cycles, we
can determine the serializability of the schedule. If no cycles are found, the schedule is conflict
serializable.
Additionally, conflict serializable schedules are always view serializable. So, option (b) is
correct.
2
Question 3
Consider the following schedule S involving five transactions T1 , T2 , T3 , T4 and T5 :
T1 T2 T3 T4 T5
R(Z)
R(X)
R(Y)
W(X)
W(X)
W(Z)
W(Z)
a) T1→T4→T5→T2→T3
b) T1→T2→T3→T4→T5
c) T1→T2→T4→T5→T3
d) T1→T4→T3→T5→T2
Answer: d)
Explanation: If we draw the precedence graph of the transactions as shown in the following, we
can observe that the graph has no cycle.
So, the above schedule is a conflict serializable schedule.
All conflict serializable schedules are view serializable too.
All possible topological orderings of the above precedence graph will be the possible conflict
serializable schedule.
Hence, the incorrect order of execution of all transactions among the given options is: T1→T4→T3→T5→T2
So, option (d) is the answer.
3
Question 4
Consider the following schedule S involving five transactions T1 , T2 , T3 , T4 and T5 :
T1 T2 T3 T4 T5
R(Z)
R(X)
W(X)
R(X)
R(Z)
W(X)
W(Z)
W(Y)
W(Z)
W(Y)
W(Y)
a) 1
b) 2
c) 3
d) 5
Answer: d)
Explanation: If we draw the precedence graph of the schedule, we can observe that the graph
has no cycle. Hence, the above schedule is conflict serializable schedules.
All possible topological orderings of the above precedence graph will be the possible conflict
serializable schedule.
1. T1 → T4 → T2 → T5 → T3
2. T1 → T4 → T2 → T3 → T5
3. T1 → T2 → T4 → T3 → T5
4. T1 → T2 → T4 → T5 → T3
5. T1 → T2 → T3 → T4 → T5
Hence, option d) is correct.
4
Question 5
Consider the following schedule S of transactions T1 and T2 .
The read operation on data item A is denoted by read(A) and the write operation on data item A is
denoted by write(A).
T1 T2
read(A)
A:=A-500
read(C)
write(A)
read(B)
temp:=C∗0.5
C:=C-temp
B:=B+500
write(C)
write(B)
read(B)
B:=B+temp
write(B)
c) S is serializable only as T1 , T2 .
d) S is serializable only as T2 , T1 .
Answer: c)
Explanation: First, swap all non-conflicting instructions of the above schedule S.
T1 and T2 both are working on a same data item.
So, S is serializable only as T1 , T2 .
Hence, option (c) is correct.
5
Question 6
Consider the following schedule S.
T1 T2 T3
R(Y)
W(Y)
R(Y)
W(Y)
W(Y)
a) 1
b) 2
c) 4
d) 6
Answer: a)
Explanation: Step 1: Final Update on data item: This is done on Y by T1.
Since the final update on Y is made by T1, the transaction T1 must execute after the transactions T2
and T3 So, (T2,T3) → T1.
Step 2: Initial Read + Which transaction updates after read?
Transaction T3 does the initial read Y; then, T2 updates on it.
Hence, the dependency is: T3 → T2
Step 3: Write Read Sequence: T2 writes Y and then T1 reads Y.
Hence, the dependency is as follows. T2 → T1
Thus, the only possible way, this is possible is: T3 → T2 → T1.
Hence, total possible view serializable schedule of S= 1.
So, option (a) is correct.
6
Question 7
Consider two transactions given below where lock-X(A) denotes Ti has obtained an Exclusive-mode
lock on item A and lock-S(A) denotes Ti has obtained a Shared-mode lock on item A.
T1 T2
lock-X(A) lock-X(A)
read(A) read(A)
lock-X(B) A:= A-100
read(B) write(A)
B:= B+100 lock-S(B)
write(B) read(B)
lock-S(C) lock-S(C)
read(C) read(C)
unlock(C) unlock(B)
commit unlock(C)
unlock(A) commit
unlock(B) unlock(A)
a) T2 follows the rigorous two-phase locking protocol, but T1 follows the strict two-phase
locking protocol only .
b) T1 follows the rigorous two-phase locking protocol, but T2 follows the strict two-phase
locking protocol only.
Answer: c)
Explanation: Transaction T1 first unlocks all Shared-mode lock and then commits. After commit, it
unlocks Exclusive-mode lock . That is why, T1 follows the strict two-phase locking protocol.
Transaction T2 first unlocks all Shared-mode lock and then commits. After commit, it unlocks
Exclusive-mode lock . That is why, it follows the strict two phase locking protocol only.
So, option (c) is correct.
7
Question 8
Consider the following schedule S.
T1 T2
R(X)
W(X)
R(Y)
W(Y)
COMMIT
R(X)
W(X)
R(Y)
W(Y)
COMMIT
Answer: c)
Explanation: Recoverable schedule: If a transaction Tj reads a data item previously written by a
transaction Ti , the commit operation of Ti must appear before the commit operation of Tj .
Cascadeless schedules: For each pair of transactions Ti and Tj such that Tj reads a data item previously
written by Ti , the commit operation of Ti appears before the read operation of Tj .
Here, T2 read all data items after commit operation of T1 . Hence, the schedule is recoverable as well
as casecadeless.
So, option (c) is correct.
8
Question 9
Consider the following schedule S.
T1 T2 T3
R(X)
W(X)
R(X)
W(X)
R(Y)
W(Y)
R(Y)
W(Y)
abort
a) If T2 fails (aborts), only T1 will be rolled back, while T3 will remain unaffected.
b) If T2 fails (aborts), only T3 will be rolled back, while T1 will remain unaffected.
d) If T2 fails (aborted), both transactions T1, and T3 must also be rolled back.
Answer: d)
Explanation:
• In the given schedule, T3 depends on the data item Y written by T2. If T2 aborts, T3 must also
roll back to ensure consistency.
• In the given schedule, T2 depends on the data item X written by T1. If T2 aborts, T1 must also
roll back to ensure consistency.
Thus, the correct answer is (d): If T2 fails, both transactions T1, and T3 must also be rolled back.
9
Question 10
Suppose in a database, there are three transactions T1 , T2 , and T3 with timestamps 20, 21, and 22
respectively. T2 is holding some data items which T1 and T3 are requesting to acquire. Which of the
following statement(s) is (are) correct in respect of Wait-Die Deadlock Prevention Scheme?
c) Transaction T1 will wait for T2 to release the data item and Transaction T3 will rollback.
Answer: c)
Explanation: In Wait-Die Deadlock Prevention scheme:
Older transaction may wait for younger one to release data item. (older means smaller timestamp)
Younger transactions never wait for older ones; they are rolled back instead.
Transaction T1 is older than T2 , hence T1 will wait until the data item is released. Transaction T3 is
younger than Transaction T2 , so it will be rolled back.
Hence, option c) is correct.
10