KatInterview

Pinpoint Bad Nodes with Disjoint Group Probes of Size Two or More

Greedy & IntervalsModel answer
MediumModel answerGreedy & Intervalsgroup-testingadaptive-algorithmsround-robin-scheduling

Last 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 True if every node in S is healthy;
  • it returns False if S contains at least one faulty node.

Probes are submitted in rounds, and all probes in one round run simultaneously. Two rules apply:

  1. Probes within a round must use pairwise disjoint node sets, so a node appears in at most one probe per round.
  2. 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

  1. An adaptive algorithm that returns exactly the faulty set whenever the probe outcomes make it determinable.
  2. A correctness argument: every node ends up classified, and each inference is justified.
  3. Costs in rounds and in total probes, for both few faulty nodes and many.
  4. A precise statement of when the faulty set cannot be determined, and what your function does in that case.
  5. 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.