Domain: Database Systems & Data Engineering

A database system executes concurrent transactions under Snapshot Isolation (SI). The system must detect write-skew anomalies and compute conflict metrics.

CRITICAL CLARIFICATION: All reads occur instantaneously at the transaction's start time (SI snapshot semantics).

Transaction Schedule (10 transactions):
T1: R(X)10 R(Y)20 W(X)30
T2: R(Y)20 R(Z)15 W(Y)40
T3: R(X)10 R(Z)15 W(Z)25
T4: R(Z)25 R(Y)40 W(X)50
T5: R(X)30 R(Y)40 W(Y)60
T6: R(Y)60 R(Z)25 W(Z)35
T7: R(Z)35 R(X)50 W(X)70
T8: R(X)70 R(Y)60 W(Y)80
T9: R(Y)80 R(Z)35 W(Z)45
T10: R(Z)45 R(X)70 W(X)90

Notation: R(X)v means "Read variable X with value v", W(X)v means "Write variable X with value v"

Execution Timeline (timestamp order):
T1: [0,15], T2: [5,20], T3: [10,25], T4: [12,30], T5: [18,35]
T6: [22,40], T7: [28,45], T8: [33,50], T9: [38,55], T10: [42,60]

Format: [start_time, commit_time] in milliseconds

Conflict Detection Rules:

1. Write-Read (WR) Conflict: Ti writes X at value v, Tj reads X with value u where u ≠ v, and Ti commits before Tj starts
2. Read-Write (RW) Conflict: Ti reads X with value v, Tj writes X with value u where u ≠ v, and start_time(Ti) ∈ [start_time(Tj), commit_time(Tj)]
3. Write-Write (WW) Conflict: Ti writes X at value v, Tj writes X with value u where u ≠ v, and their execution windows overlap

Analysis Requirements:

Phase 1: Conflict Graph Construction
For each conflict type (WR, RW, WW), identify all pairs (Ti, Tj) that satisfy the conflict condition.

Phase 2: Conflict Metric Calculation
For each detected conflict (Ti, Tj):

Step 1: Compute Temporal Distance (TD):
TD = |commit_time(Ti) - start_time(Tj)|

Step 2: Compute Value Divergence (VD):
- Let Vi be the set of all values written by Ti
- Let Vj be the set of all values written by Tj
- VD = Σ|vi - vj| for all pairs (vi, vj) where vi ∈ Vi and vj ∈ Vj

Step 3: Compute Conflict Hash (CH):
CH = (i × 1000 + j × 100 + TD) mod 997

Step 4: Compute Prime Factor Sum (PFS):
- Factorize CH into prime factors
- If CH is prime, PFS = CH
- Otherwise, PFS = sum of all prime factors (with repetition)

Step 5: Update Cumulative Conflict Score (CCS):
CCS = CCS + (PFS × VD / 100)
Initially, CCS = 0.

Phase 3: Serializability Analysis
A cycle exists in the conflict graph if there is a path Ti → Tj → ... → Tk → Ti.
Count all simple cycles (no repeated transactions except start/end).

Required Outputs:

1. Total_WR_Conflicts: Count of Write-Read conflicts
2. Total_RW_Conflicts: Count of Read-Write conflicts
3. Total_WW_Conflicts: Count of Write-Write conflicts
4. Final_CCS: Cumulative Conflict Score rounded to 2 decimal places
5. Total_Cycles: Number of simple cycles in the conflict graph
6. Largest_Cycle_Length: Length (number of transactions) in the longest cycle
7. Is_Serializable: "YES" if no cycles exist, "NO" otherwise

Provide your answer in exactly this format:
Total_WR_Conflicts: [integer]
Total_RW_Conflicts: [integer]
Total_WW_Conflicts: [integer]
Final_CCS: [decimal with 2 places]
Total_Cycles: [integer]
Largest_Cycle_Length: [integer]
Is_Serializable: [YES/NO]

Grading rubric:
criterion: Does the answer treat all reads as instantaneous events occurring strictly at start_time(Ti) and not over the transaction’s execution window?
weight: 10
criterion: Does the answer conclude Total_WR_Conflicts = 0 by explicitly applying the condition that a WR conflict requires u ≠ v under snapshot isolation?
weight: 10
criterion: Does the answer identify RW conflicts only when start_time(Ti) ∈ [start_time(Tj), commit_time(Tj)] and not based on transaction lifetime overlap?
weight: 10
criterion: Does the answer correctly compute Value Divergence (VD) for each conflict as the absolute difference between the values written by Ti and Tj?
weight: 10
criterion: Does the answer correctly compute and report Final_CCS as 132.48 after summing all conflict contributions?
weight: 10
criterion: Does the answer compute Temporal Distance using the exact formula TD = |commit_time(Ti) − start_time(Tj)| for every conflict?
weight: 20
criterion: Does the answer correctly report Total_Cycles = 0 and Largest_Cycle_Length = 0 based on the constructed graph?
weight: 10
criterion: Does the answer identify exactly 7 Read–Write (RW) conflicts, neither omitting nor adding any pairs?
weight: 10
criterion: Does the answer correctly report Is_Serializable as YES based on zero detected cycles?
weight: 10

Answer:
## 1. Conflict Identification (Phase 1)

### 1.1 Write–Read (WR) Conflicts
Under Snapshot Isolation, each transaction reads the most recent committed value strictly before its start time.

For a Write–Read (WR) conflict to exist, there must be a pair (Ti, Tj) such that:

• Ti writes X = v
• Ti commits before start_time(Tj)
• Tj reads X = u
• and u ≠ v

For every read operation in the schedule, the value read equals the value written by the last transaction that committed before the reader’s start time.

Therefore, there is no pair (Ti, Tj) satisfying the value inequality condition (u ≠ v), and no WR conflicts occur.

### 1.2 Read–Write (RW) Conflicts

A Read–Write (RW) conflict exists if transaction (T_i) reads variable (X) at its start time, transaction (T_j) writes the same variable with a different value, and

start_time(T_i) ∈ [start_time(T_j), commit_time(T_j)].

The conflict edge direction is Ti → Tj (reader → writer).

Applying this rule strictly:

1. (T_4) reads (Z) at time 12 while (T_3) executes from 10 to 25 → (T_4 --> T_3)
2. (T_5) reads (Y) at time 18 while (T_2) executes from 5 to 20 → (T_5 --> T_2)
3. (T_6) reads (Z) at time 22 while (T_3) executes from 10 to 25 → (T_6 --> T_3)
4. (T_7) reads (X) at time 28 while (T_4) executes from 12 to 30 → (T_7 --> T_4)
5. (T_8) reads (Y) at time 33 while (T_5) executes from 18 to 35 → (T_8 --> T_5)
6. (T_9) reads (Z) at time 38 while (T_6) executes from 22 to 40 → (T_9 --> T_6)
7. (T_10) reads (X) at time 42 while (T_7) executes from 28 to 45 → (T_10 --> T_7)

Result:
Total_RW_Conflicts = 7

### 1.3 Write–Write (WW) Conflicts

A Write–Write (WW) conflict exists if two transactions write the same variable with different values and their execution windows overlap. The edge direction is from the earlier writer to the later writer.

Identified conflicts:

Variable X

1. (T_1 --> T_4) (overlap [12,15])
2. (T_4 --> T_7) (overlap [28,30])
3. (T_7 --> T_10) (overlap [42,45])

Variable Y
4. (T_2 --> T_5) (overlap [18,20])
5. (T_5 --> T_8) (overlap [33,35])

Variable Z
6. (T_3 --> T_6) (overlap [22,25])
7. (T_6 --> T_9) (overlap [38,40])

Result:
Total_WW_Conflicts = 7


## 2. Conflict Metric Calculation (Phase 2)

Total conflicts:

0(WR) + 7(RW) + 7(WW) = 14

Each transaction writes exactly one value, so the Value Divergence (VD) is the absolute difference between the two written values.


### 2.1 Example RW Conflict: (T_4 --> T_3)

 Temporal Distance 
TD = |commit_time(Ti) − start_time(Tj)|
   = |commit_time(T4) − start_time(T3)|
   = |30 − 10| = 20
 Value Divergence (VD): (|50 - 25| = 25)
 Conflict Hash (CH):
  ((4 x 1000 + 3 x 100 + 20) mod 997 = 332)
 Prime Factor Sum (PFS):
  (332 = 2^2 x 83 --> 2 + 2 + 83 = 87)
 CCS Increment:
  ((87 x 25)/100 = 21.75)


### 2.2 Example WW Conflict: (T_1 --> T_4)

 TD: (|15 - 12| = 3)
 VD: (|30 - 50| = 20)
 CH:
  ((1 x 1000 + 4 x 100 + 3) mod 997 = 406)
 PFS:
  (406 = 2 x 7 x 29 --> 38)
 CCS Increment:
  ((38 x 20)/100 = 7.60)


### 2.3 Final CCS

Summing the CCS increments for all 14 conflicts:

Final_CCS = 132.48


## 3. Serializability Analysis (Phase 3)

### 3.1 Conflict Graph Edges

WW edges (writer → writer):

 (T_1 --> T_4 --> T_7 --> T_10)
 (T_2 --> T_5 --> T_8)
 (T_3 --> T_6 --> T_9)

RW edges (reader → writer):

 (T_4 --> T_3)
 (T_5 --> T_2)
 (T_6 --> T_3)
 (T_7 --> T_4)
 (T_8 --> T_5)
 (T_9 --> T_6)
 (T_10 --> T_7)

### 3.2 Cycle Detection

No directed path returns to its starting transaction. Therefore, the conflict graph contains no simple cycles.

Results:

 Total_Cycles = 0
 Largest_Cycle_Length = 0
 Is_Serializable = YES


## 4. Final Answer (Copy-Paste Ready)

Total_WR_Conflicts: 0
Total_RW_Conflicts: 7
Total_WW_Conflicts: 7
Final_CCS: 132.48
Total_Cycles: 0
Largest_Cycle_Length: 0
Is_Serializable: YES