Processes exchange messages. Events are given in a valid global order: {"proc", "type": "local" | "send" | "recv", "msg"} (msg names the message for send/recv). Assign vector clocks:
send attaches the sender's clock (after incrementing) to the message.recv first takes the element-wise max of the receiver's clock and the message's clock, then
increments its own counter.Clocks are lists ordered like procs. Then answer queries [i, j] (event indexes) with "before" (i
happened before j), "after", "concurrent" or "same".
Return {"clocks": [...], "answers": [...]}.
Implement vector_clocks. Input: procs: list[str], events: list[dict], queries: list[[int, int]]. Returns: dict.
def vector_clocks(procs, events, queries):
clocks = [[i] for i in range(len(events))]
answers = ["before" if i < j else "after" for i, j in queries]
return {"clocks": clocks, "answers": answers}
Run executes the public tests. Submit grades against public and hidden tests.
Processes exchange messages. Events are given in a valid global order: {"proc", "type": "local" | "send" | "recv", "msg"} (msg names the message for send/recv). Assign vector clocks:
send attaches the sender's clock (after incrementing) to the message.recv first takes the element-wise max of the receiver's clock and the message's clock, then
increments its own counter.Clocks are lists ordered like procs. Then answer queries [i, j] (event indexes) with "before" (i
happened before j), "after", "concurrent" or "same".
Return {"clocks": [...], "answers": [...]}.
Implement vector_clocks. Input: procs: list[str], events: list[dict], queries: list[[int, int]]. Returns: dict.
def vector_clocks(procs, events, queries):
clocks = [[i] for i in range(len(events))]
answers = ["before" if i < j else "after" for i, j in queries]
return {"clocks": clocks, "answers": answers}
Run executes the public tests. Submit grades against public and hidden tests.