Transaction deadlock detection
Detect whether a set of transactions is deadlocked given a wait-for graph. Input is a list of (a, b) edges meaning transaction a is waiting for a resource held by transaction b. A deadlock exists if and only if this directed graph contains a cycle. Return True if any cycle exists, else False. Node labels are arbitrary hashable values; an edge may appear more than once; self-loops (a waits for itself) count as a cycle. The edge list may be empty.
Implement
has_deadlock(edges: list[tuple]) → boolExamples
in
[[["t1","t2"],["t2","t3"],["t3","t1"]]]outtrueWhat a strong answer looks like
State your approach and its time/space complexity out loud before you optimize. Handle the edge cases (empty input, duplicates, overflow), and say why you chose this over the brute force. Green tests are the floor, not the grade.
0:00 of about 35 min
solution.py
InputExpectedGot
[[["t1","t2"],["t2","t3"],["t3","t1"]]]truenot run yetsample