GATE | GATE-CS-2017 (Set 2) | Question 64
Two transactions T1 and T2 are given as:
T1: r1(X)w1(X)r1(Y)w1(Y) T2 : r2(Y)w2(Y)r2(Z)w2(Z)
where ri(V) denotes a read operation by transaction Ti on a variable V and wi(V) denotes a write operation by transaction Ti on a variable V. The total number of conflict serializable schedules that can be formed by T1 and T2 is ______
Note: This question appeared as Numerical Answer Type.
(A)
54
(B)
55
(C)
56
(D)
57
Answer: (A)
Explanation:
For schedules to be conflict serializable they should be free from RW, WW, WR conflicts.
In the conflict serializable schedule we have to see that the operations in both the transactions occurring on same data item should not conflict. Data item y is shared between the two transactions so the read and write operations in T1 on data item y can produce RW, WR, WW conflict with the read and write operations of transaction T2 on data item y.
Another constraint is that the order of operations of each transaction should be maintained. We can not change the order of operation on transaction. Suppose if read(x) is before write(x) in T1 then it should be in the same order in resulting conflict serializable schedule.
In T1 we have two conflicting operations r1(y) and w1(y)
In T2 we have two conflicting operations r2(y) and w2(y)
Both the read and write of T1 on y should be performed together either before the read write pair of T2 or after read write pair to T2 because interleaving them will result in inconsistency because both these transaction are performing operation on same object.
There is only one way to have (conflict) serializable schedule as T1->T2, because last operation of T1 and first operation of T2 conflicts each other.
Now See How many schedules are conflict serializable to T2->T1.
T1- r1(x) w1(x) r1(y) w1(y)
Now See T2 from right, if we see T2 from right, see the first conflicting operation w2(z) and r2(z) don’t have any conflict with any operation, but w(y) has conflict Pick W2(y) and see, at how many places it can be there.
Case1: w2(y) r1(x) w1(x) r1(y) w1(y) Case2: r1(x) w2(y) w1(x) r1(y) w1(y) Case3: r1(x) w1(x) w2(y) r1(y) w1(y)
Pick each case and see,how many positions other operation of T2 can take.
Case1: w2(y) r1(x) w1(x) r1(y) w1(y) How many positions w2(z) and r2(z) can take ? (note that these w2(z) and r2(z) cant come before w2(y)) that is 5C1 + 5C2 = 15 (either both can take same space or two different spaces) Now see, for each of these 15 positions, how many can r2(y) take ? Obviously r2(y) cant come before w2(y) therefore one position. 15×1 = 15 total possible schedules from case 1.
Case2: r1(x) w1(y) w1(x) r1(y) w1(y) How many positions w2(z) and r2(z) can take ? that is 4C1 + 4C2 = 10 (either both can take same space or two different spaces) Now see, for each of these 10 positions, how many can r2(y) take ? Only 2 positions, because it has to come before w1(y). 10×2 = 20 total possible schedules from case 2.
Case3: r1(x) w1(x) w2(y) r1(y) w1(y) How many positions w2(z) and r2(x) can take ? that is 3C1 + 3C2 = 6 Now see, for each of these 6 positions, how many can r2(y) take ? Only 3 positions, because it has to come before w2(y). 6×3 = 18 total possible schedules from case 3. total schedules that are conflict serializable as T2->T1 = 15+20+18 = 53. total schedules that are conflict serializable as T1->T2 = 1. total schedules that are conflict serializable as either T2->​​​​​​​T1 or T1->T2 = 53+1 = 54.
This solution is contributed by Parul Sharma.
Quiz of this Question
Please comment below if you find anything wrong in the above post
Please Login to comment...