Schedules and Conflict Serializability: Precedence Graphs Worked Step by Step

Turn an interleaved DBMS schedule into a precedence graph. Follow every read and write, recover the serial order, and see how one moved block creates a cycle.

KnowledgeGate Team

Exam prep & CS education

Updated 4 Dec 20266 min read
Schedules and Conflict Serializability: Precedence Graphs Worked Step by Step

A long interleaving of r and w operations can look like a simulation exercise. The faster, reliable test is to translate only its conflicting order constraints into a graph. In the schedule below, those edges force serial order T1,T2,T3; moving T1's C block instead creates a cycle.

What a schedule preserves and what serializability asks

A transaction is an ordered program of reads, local calculations, writes, and finally a commit or abort. A schedule interleaves operations from multiple transactions while preserving the original operation order inside each transaction. A serial schedule finishes one complete transaction before starting another. A non-serial schedule overlaps them.

Conflict serializability does not ask whether a schedule is visibly serial. It asks whether the schedule preserves the same ordering constraints between conflicting operations as some serial schedule. The useful output is therefore not just yes or no. We should also recover an equivalent serial order, such as T1,T2,T3.

Review Transactions and Concurrency Control in DBMS if ACID properties and concurrent execution need a refresh. The CS Fundamentals for Exams and Placements route places this graph test inside the wider subject.

The three-part conflict test

Two operations conflict only when all three conditions hold:

  1. They belong to different transactions.

  2. They access the same data item.

  3. At least one operation is a write.

Therefore, r1(X) and r2(X) do not conflict. The pairs r1(X) before w2(X), w1(X) before r2(X), and w1(X) before w2(X) do conflict.

Direction comes from schedule order. If T1's conflicting operation occurs first, add T1 -> T2. Reverse their occurrence and the edge becomes T2 -> T1. Adjacent operations on different items produce no edge.

Use this four-line scan routine:

  1. Group operations by data item.

  2. Discard same-transaction pairs.

  3. Discard read-read pairs.

  4. Direct every remaining pair from the earlier transaction to the later one.

Several conflicts may produce the same edge, but store it once. Never add a self-loop for operations from one transaction.

Conflict equivalence and the acyclic-graph theorem

Two schedules are conflict equivalent when they contain the same operations and preserve the relative order of every conflicting cross-transaction pair. Constructively, adjacent non-conflicting operations can be swapped without changing those constraints. If such swaps can gather each transaction into a serial arrangement, the original schedule is conflict serializable.

The theorem gives a direct test: a schedule is conflict serializable if and only if its precedence graph is acyclic. Create one vertex per transaction. Add an earlier-to-later edge for every conflicting pair. If the result is a directed acyclic graph, any topological ordering is an equivalent serial order.

Equal final database values alone do not prove conflict equivalence. Conversely, unequal final values are not a substitute for the graph algorithm. Conflict serializability, view serializability, and recoverability are also different properties with different tests.

Worked schedule: execute all 12 reads and writes

Start with A=100, B=40, and C=5.

  • T1: r1(A); A:=A+20; w1(A); r1(C); C:=C+2; w1(C).

  • T2: r2(A); A:=2*A; w2(A); r2(B); B:=B-10; w2(B).

  • T3: r3(B); B:=B+5; w3(B); r3(C); C:=3*C; w3(C).

Execute schedule S in order:

Step

T1

T2

T3

Database value after a write

1

r1(A)=100

2

w1(A=120)

A=120, B=40, C=5

3

r2(A)=120

4

w2(A=240)

A=240, B=40, C=5

5

r2(B)=40

6

w2(B=30), commit T2

A=240, B=30, C=5

7

r1(C)=5

8

w1(C=7), commit T1

A=240, B=30, C=7

9

r3(B)=30

10

w3(B=35)

A=240, B=35, C=7

11

r3(C)=7

12

w3(C=21), commit T3

A=240, B=35, C=21

T2 runs between T1's A block and C block, but every transaction keeps its own program order. Commits add no precedence edge in this basic read-write test. The exact final state is (A,B,C)=(240,35,21).

Build the precedence graph and recover the serial order

Scan A first. r1(A) before w2(A), w1(A) before r2(A), and w1(A) before w2(A) all collapse to T1 -> T2. The read-read pair adds nothing.

For B, the corresponding read-write, write-read, and write-write conflicts all give T2 -> T3. For C, they give T1 -> T3. The complete edge set is {T1 -> T2, T2 -> T3, T1 -> T3}.

Now compute the topological order:

  • Initially, in(T1)=0, in(T2)=1, and in(T3)=2.

  • Remove T1. T2's indegree becomes 0, and T3's becomes 1.

  • Remove T2. T3's indegree becomes 0.

  • Remove T3.

The unique order is T1,T2,T3. Re-executing it confirms the values: T1 makes A=120,C=7; T2 makes A=240,B=30; T3 makes B=35,C=21. This matches (240,35,21), while the acyclic graph remains the proof.

The order is unique because every transaction pair is constrained: T1 must precede T2 and T3, while T2 must precede T3. Keep T1 -> T3 in the graph even though the path through T2 already implies that order. A precedence graph records direct conflict evidence, not merely a transitive reduction.

Two-panel schedule and precedence graph show transaction lanes T1, T2, T3, edges T1 → T2, T2 → T3, T1 → T3, and final values A=240, B=35, C=21.

One moved operation block creates a cycle

Create S_cycle by moving T1's complete r1(C), w1(C) block and its commit to the end. Every other relative order remains unchanged. T3 now reads C=5 and writes C=15. T1 then reads C=15 and writes C=17. A and B still finish at 240 and 35, so the new final state is (240,35,17).

Only the C edge changes. A still gives T1 -> T2, and B still gives T2 -> T3. On C, T3's conflicting operations now occur first, giving T3 -> T1. The graph contains T1 -> T2 -> T3 -> T1. Every vertex has indegree 1, so no topological removal can begin and no serial order satisfies all constraints.

Once a directed cycle is proved, stop. Name each edge and its data item: A causes T1 -> T2, B causes T2 -> T3, and C causes T3 -> T1. The fact that all transactions commit does not make the schedule conflict serializable.

Side-by-side DAG and cycle comparison shows edges T1 → T2, T2 → T3, T3 → T1, no indegree-0 vertex, and final values (240,35,17).

Traps and the ways questions test this topic

Keep these traps separate:

  • Read-read is not a conflict, and different data items never conflict.

  • Edge direction follows schedule order, not transaction number.

  • One transaction pair can have edges in both directions.

  • Repeated conflicts do not require parallel edges.

  • A cycle can contain two or more vertices.

  • A DAG can have several valid topological orders.

For the worked schedule, the answers are: A gives T1 -> T2; B gives T2 -> T3; original C gives T1 -> T3; the serial order is T1,T2,T3; moved C gives T3 -> T1 and closes the three-vertex cycle. For the fresh schedule r1(X),r2(X), there is only a read-read pair. Its graph has two isolated vertices, so both T1,T2 and T2,T1 are valid serial orders.

Questions may ask you to identify conflicts, draw the graph, decide serializability, list topological orders, or find an operation move that creates or removes a cycle. They may also ask you to distinguish conflict from view serializability. Use DBMS Transaction MCQs: 12 Solved to practise these decisions without inventing extra rules.

The short version and the next step

Preserve program order. Keep only same-item, cross-transaction pairs containing a write. Direct each edge from earlier to later, collapse duplicates, and topologically sort. The original graph gives T1,T2,T3; moving T1's C block creates T1 -> T2 -> T3 -> T1.

For a broader CS route, use Zero to Hero, Complete CS Course. For placement-focused revision, use CS Fundamentals for Placements by Sanchit Sir. Then hide the graph, rebuild its three edges from the schedule, and solve the linked transaction questions.