Pinpoint Bad Nodes with Disjoint Group Probes of Size Two or More
Greedy & IntervalsModel answerLast updated
Find exactly which cluster nodes are bad when the only probe is a group test that fails if any member is bad, parallel probes must be disjoint, and each probe needs at least two nodes.
You manage n GPU nodes labelled 0 to n - 1. An unknown subset is faulty, and you cannot examine a node directly. The only available operation is a probe of a node set S:
- it returns
Trueif every node inSis healthy; - it returns
FalseifScontains at least one faulty node.
Probes are submitted in rounds, and all probes in one round run simultaneously. Two rules apply:
- Probes within a round must use pairwise disjoint node sets, so a node appears in at most one probe per round.
- Each probe must contain at least two nodes.
def run_tests(groups: list[list[int]]) -> list[bool]:
"""One call = one parallel round. Returns one result per group.
Groups must be pairwise disjoint and each must have >= 2 nodes."""
def find_bad_nodes(n: int, run_tests) -> set[int]:
...
Probes are deterministic, and node health does not change while you work.
What to produce
- An adaptive algorithm that returns exactly the faulty set whenever the probe outcomes make it determinable.
- A correctness argument: every node ends up classified, and each inference is justified.
- Costs in rounds and in total probes, for both few faulty nodes and many.
- A precise statement of when the faulty set cannot be determined, and what your function does in that case.
- How the design would change if a probe could occasionally return a wrong answer.
Before designing, state what you are optimising (rounds, total probes, or both) and any assumption you make about the number of faulty nodes.
Hints
Hint 1
A passing probe proves every node in it is healthy. A failing probe is only informative when all but one member is already known healthy. How does a known-healthy node let you test a single suspect despite the size-two minimum?
Hint 2
Before any node is known healthy, the only way to learn something decisive is to find a passing probe. Think about how to schedule every pair of nodes into rounds of disjoint pairs (the circle method for round-robin tournaments), and about when no pair can ever pass.
Hint 3
Once you have a pool of proven-healthy nodes, each can vet one unknown node per round, and every newly proven node joins the pool. Ask how fast the pool grows when faults are rare versus common, and how you could use bigger groups to save probes when faults are rare.
Model answer
Medium Try it yourself first — then compare your approach, complexity and edge cases.
Key observations
- A probe passes iff every member is healthy. A pass on a group of size at least 2 proves all its members healthy.
- A fail only says "at least one member is faulty". It pins down a single node only when every other member is already known healthy.
- Therefore a faulty node can only be identified through a failing probe of the form
{known-healthy node, suspect}. A known-healthy node is the "adapter" that lets us test one suspect despite the minimum group size of two. - Identifiability. If at most one node is healthy, every legal probe contains a faulty node, so every probe fails. The outcome is then identical for "all faulty" and for "exactly one healthy, any of them". If at least two nodes are healthy, that pair passes and the rest can be resolved. So the faulty set is determinable iff
n >= 2and at least two nodes are healthy.
Algorithm
Phase 1: find a healthy seed. Schedule every pair of nodes using the circle method. For even n this gives n - 1 rounds of n/2 disjoint pairs, and each pair appears exactly once. For odd n, add a dummy slot and drop any pair containing it. Run rounds until some pair passes, and mark both nodes healthy. If the schedule ends with no pass, at most one node is healthy, so report non-identifiability.
Phase 2: spread the knowledge. Keep a pool good of proven-healthy nodes and a list unknown. Each round, pair each pool node with a distinct unknown node, using min(|good|, |unknown|) probes:
- pass: the unknown node is healthy and joins
good; - fail: the unknown node is faulty, because its partner is known healthy.
Repeat until unknown is empty.
def find_bad_nodes(n, run_tests):
if n == 0:
return set()
if n < 2:
raise ValueError("not identifiable: no legal probe exists")
# Phase 1: round-robin pairs until one passes
ring = list(range(n)) + ([None] if n % 2 else [])
m = len(ring)
good = []
for _ in range(m - 1):
groups = [[ring[i], ring[m - 1 - i]]
for i in range(m // 2)
if ring[i] is not None and ring[m - 1 - i] is not None]
if groups:
for g, ok in zip(groups, run_tests(groups)):
if ok:
good.extend(g)
if good:
break
ring = [ring[0], ring[-1]] + ring[1:-1] # rotate all but ring[0]
if not good:
raise ValueError("not identifiable: fewer than two healthy nodes")
# Phase 2: healthy nodes vet one unknown node each per round
known = set(good)
unknown = [x for x in range(n) if x not in known]
bad = set()
while unknown:
k = min(len(good), len(unknown))
batch, unknown = unknown[:k], unknown[k:]
groups = [[good[i], batch[i]] for i in range(k)]
for u, ok in zip(batch, run_tests(groups)):
if ok:
good.append(u)
else:
bad.add(u)
return bad
Newly proven nodes are appended to good only after the round ends, so no node is used twice in the same round and every group stays disjoint.
Correctness
- Every group in Phase 1 has two distinct nodes, and the pairs within a round are disjoint by construction of the circle method. Phase 2 groups use distinct pool nodes and distinct unknowns, so they are disjoint too.
- A node enters
goodonly through a passing probe, sogoodnever contains a faulty node. - A node enters
badonly through a failing probe whose other member is ingood, sobadnever contains a healthy node. - Each node leaves
unknownafter exactly one Phase 2 probe, so the loop terminates and every node is classified. - If Phase 1 finds no pass, the argument above shows the true set cannot be recovered, so raising an error is the only honest answer.
Cost
Phase 1
- Worst case: exactly two healthy nodes. Only their pair passes, so up to
n - 1rounds andn(n-1)/2probes. This cannot be avoided. With exactly two healthy nodes, any group of three or more fails regardless, so only pair probes carry information, and the adversary can place the pair last. - Typical case: with healthy fraction
h, a pair passes with probabilityh^2, and a round hasn/2pairs. Ifhis at least aboutsqrt(2/n), round 1 usually already contains a pass. With rare faults this costs 1 round andn/2probes.
Phase 2
- Every remaining node is probed exactly once, so about
nprobes in total. - Rounds depend on pool growth. If a fraction
qof the unknowns is healthy, the pool grows by about1 + qper round. With rare faults it nearly doubles, giving aboutlog2 nrounds. In the worst case (two healthy nodes, everything else faulty) the pool never grows and it takes aboutn/2rounds.
Overall: with rare faults, about log2 n + 1 rounds and roughly 1.5n probes. With many faults, about n probes in Phase 2 plus a potentially expensive Phase 1, and up to O(n) rounds. About n probes is hard to beat when faults are dense, since each faulty node needs its own failing probe against a healthy partner.
Saving probes when faults are rare
Once a pool exists, test blocks of about 1/p unknown nodes, where p is the fault rate. A passing block clears all its members in one probe, and blocks are disjoint, so many run in parallel. For a failing block, split it in half and re-test; if one half passes, the other half is known to contain a fault and needs no probe of its own. A half of size one is paired with a pool node. This brings expected probes down toward n * H(p) (the binary entropy), far below n when p is small, at the price of a few more sequential rounds.
Flaky probes
- Model the noise first: is it one-sided (healthy groups sometimes fail) or two-sided?
- Repeat each decisive probe
k = O(log(n / delta))times and take a majority vote, so a union bound over aboutnprobes keeps the total error belowdelta. - The seed is the single point of failure: one wrongly trusted node would poison every later conclusion. Confirm the seed pair several times, and use independent partners from the pool when confirming a node as faulty, so a mislabelled partner cannot repeat the same mistake.
- Larger groups become less reliable under noise, so cap block size when the false-fail rate rises.
Common mistakes
- Treating a failed pair as proof that both nodes are faulty.
- Reusing a node twice in one round.
- Forgetting that with fewer than two healthy nodes the answer is unrecoverable, not "everything is faulty".
- Starting with large random groups: when faults are common they almost always fail and teach nothing.