Domain: Computer Systems & Operating Systems

You are given a distributed system with 4 processes: P0, P1, P2, P3.

Each process maintains a vector clock of size 4.
All clocks are initially: [0,0,0,0]

-----------------------------------
VECTOR CLOCK RULES
-----------------------------------

1. Internal event:
   Increment own component.

2. Send event:
   Increment own component and send the updated clock.

3. Receive event:
   Take component-wise max of local and received clock,
   then increment own component.

-----------------------------------
EVENT SEQUENCE
-----------------------------------

E1: P0 internal  
E2: P1 internal  
E3: P0 sends M1 to P2  
E4: P2 receives M1 from P0  
E5: P1 sends M2 to P3  
E6: P3 receives M2 from P1  
E7: P2 sends M3 to P1  
E8: P3 internal  
E9: P1 receives M3 from P2  
E10: P0 sends M4 to P3  
E11: P2 internal  
E12: P3 receives M4 from P0  
E13: P1 sends M5 to P0  
E14: P0 receives M5 from P1  
E15: P3 sends M6 to P2  
E16: P2 receives M6 from P3  

-----------------------------------
TASK
-----------------------------------

Compute vector clocks and answer the following:

1. Vector clock at E4  
2. Vector clock at E9  
3. Vector clock at E12  
4. Vector clock at E14  
5. Vector clock at E16  
6. Total number of happened-before (→) pairs among all unordered event pairs {Ei, Ej} with i < j. Count a pair if the vector clock of one event is strictly less than the other component-wise.  
7. Total number of concurrent (||) pairs among the same 120 unordered event pairs. Two events are concurrent if neither vector clock is strictly less than the other component-wise.  
8. Event with maximum vector clock sum  
9. Length of the longest causal chain, defined as the maximum number of distinct events in a sequence X1 → X2 → ... → Xk, where each adjacent pair satisfies happened-before.  
10. Number of receive events where exactly 2 components increase when comparing the receiver's local clock immediately before the receive with its clock immediately after applying the receive rule  

-----------------------------------
FINAL OUTPUT FORMAT

E4,E9,E12,E14,E16,HB,CONC,MAX_EVENT,CHAIN_LEN,RECV2

Where:
- Each vector clock is formatted as [a,b,c,d]
- MAX_EVENT is event label (e.g., E16)


Grading rubric:
criterion: Correctly computes E4 = [2,0,1,0]
weight: 10
criterion: Correctly computes E9 = [2,3,2,0]
weight: 10
criterion: Correctly computes E12 = [3,2,0,3]
weight: 10
criterion: Correctly computes E14 = [4,4,2,0]
weight: 10
criterion: Correctly computes E16 = [3,2,4,4]
weight: 10
criterion: Correctly computes the number of happened-before pairs among the 120 unordered event pairs as 67
weight: 10
criterion: Correctly computes the number of concurrent pairs among the 120 unordered event pairs as 53
weight: 10
criterion: Correctly identifies E16 as max sum event
weight: 10
criterion: Correctly computes the longest causal chain length as 7 events
weight: 10
criterion: Correctly computes that 3 receive events have exactly 2 component increases from the receiver's pre-receive clock to its post-receive clock
weight: 10

Answer:
[2,0,1,0],[2,3,2,0],[3,2,0,3],[4,4,2,0],[3,2,4,4],67,53,E16,7,3

EXPLANATION

Apply the vector clock rules in order. The complete clock after each event is:

- E1 (P0 internal): [1,0,0,0]
- E2 (P1 internal): [0,1,0,0]
- E3 (P0 sends M1 to P2): [2,0,0,0]
- E4 (P2 receives M1): max([0,0,0,0],[2,0,0,0]) = [2,0,0,0], then increment P2 -> [2,0,1,0]
- E5 (P1 sends M2 to P3): [0,2,0,0]
- E6 (P3 receives M2): max([0,0,0,0],[0,2,0,0]) = [0,2,0,0], then increment P3 -> [0,2,0,1]
- E7 (P2 sends M3 to P1): [2,0,2,0]
- E8 (P3 internal): [0,2,0,2]
- E9 (P1 receives M3): max([0,2,0,0],[2,0,2,0]) = [2,2,2,0], then increment P1 -> [2,3,2,0]
- E10 (P0 sends M4 to P3): [3,0,0,0]
- E11 (P2 internal): [2,0,3,0]
- E12 (P3 receives M4): max([0,2,0,2],[3,0,0,0]) = [3,2,0,2], then increment P3 -> [3,2,0,3]
- E13 (P1 sends M5 to P0): [2,4,2,0]
- E14 (P0 receives M5): max([3,0,0,0],[2,4,2,0]) = [3,4,2,0], then increment P0 -> [4,4,2,0]
- E15 (P3 sends M6 to P2): [3,2,0,4]
- E16 (P2 receives M6): max([2,0,3,0],[3,2,0,4]) = [3,2,3,4], then increment P2 -> [3,2,4,4]

From this table:

1. E4 = [2,0,1,0]
2. E9 = [2,3,2,0]
3. E12 = [3,2,0,3]
4. E14 = [4,4,2,0]
5. E16 = [3,2,4,4]

For happened-before and concurrency, compare all unordered pairs of events using vector clock comparison. There are C(16,2) = 120 unordered pairs total.

- A pair is happened-before if one vector is strictly less than the other component-wise.
- A pair is concurrent if neither vector is strictly less than the other.

Counting all 120 pairs gives:

- Happened-before pairs = 67
- Concurrent pairs = 53

The event with maximum vector clock sum is E16 because:

- sum(E14) = 4 + 4 + 2 + 0 = 10
- sum(E15) = 3 + 2 + 0 + 4 = 9
- sum(E16) = 3 + 2 + 4 + 4 = 13

No earlier event has a sum greater than 13, so MAX_EVENT = E16.

For the longest causal chain, one maximum-length sequence is:

E1 -> E3 -> E4 -> E7 -> E9 -> E13 -> E14

Each event in this sequence happened-before the next one, so the chain length is 7 events. No longer chain exists.

For receive events with exactly 2 component increases, compare the receiver's local clock immediately before and immediately after each receive:

- E4: [0,0,0,0] -> [2,0,1,0], increases in components 0 and 2 only
- E6: [0,0,0,0] -> [0,2,0,1], increases in components 1 and 3 only
- E9: [0,2,0,0] -> [2,3,2,0], 3 components increase
- E12: [0,2,0,2] -> [3,2,0,3], increases in components 0 and 3 only
- E14: [3,0,0,0] -> [4,4,2,0], 3 components increase
- E16: [2,0,3,0] -> [3,2,4,4], 4 components increase

So exactly 3 receive events satisfy the condition: E4, E6, and E12.

FINAL ANSWER

[2,0,1,0],[2,3,2,0],[3,2,0,3],[4,4,2,0],[3,2,4,4],67,53,E16,7,3