skip to content

An overlay of n nodes reports exactly n-1 links: does that alone prove it reaches every node?

level: middleimportance: must knowfreq 58%

answer

  1. a count is not a structure
  2. necessary, not sufficient
  3. any two of three give the third
  4. forest with c components has n-c links
  5. triangle plus a separate path

basics

~20 s

No. Exactly n-1 links is necessary for a tree but not sufficient: six nodes wired as a triangle plus a separate three-node path also have five links. Add either connectivity or acyclicity and the third property follows.

solid answer

~40 s

Three properties travel together for an undirected graph on `n` nodes: **connected**, **acyclic**, and **exactly `n-1` edges**. Any two of them imply the third, but no single one implies anything. A link count of `n-1` is compatible with a graph that both has a cycle and is split into pieces — six nodes as a triangle plus a disjoint two-link path give `3 + 2 = 5 = n-1`. The cycle wastes one link, and the waste shows up as a missing link somewhere else. So the count is a cheap necessary check, not a proof: to conclude the overlay is a tree you must also observe that a broadcast from one node reaches all the others, or that no link closes a loop. Given either of those, the count then pins the rest.

go deeper

for a junior

Remember the shape of the fact: a tree over n nodes has n-1 links, and that is the fewest that can reach everyone. The count is a quick sanity check, not a proof.

for a middle

Explain the two-of-three rule and produce the counterexample on demand: a triangle plus a separate path hits n-1 links while being both cyclic and split. Say which property you actually verified.

for a senior

In an operational setting, treat the link count as a cheap guard and the traversal as the real check. Be able to say what a wrong count implies before anything is walked.

for a principal

Decide which invariant the system maintains and where. Enforcing acyclicity at link-creation time and enforcing connectivity by periodic traversal are different costs with different failure modes.

## The three properties For a finite undirected simple graph on `n` nodes, three properties can be checked independently: - **Connected** — every node is reachable from every other by some sequence of links. - **Acyclic** — no simple cycle: no closed walk that repeats no link and no node except its start. - **Exactly `n-1` links** — a pure count, with no reference to structure at all. A **tree** is a graph with all three. The theorem worth carrying is not "a tree has `n-1` links" but the stronger statement: **any two of the three properties imply the third**, and no one of them implies either of the others. ## Any two imply the third 1. **Connected + acyclic implies `n-1` links.** Build the graph up one node at a time. Start with a single node and no links. Every later node must arrive attached by at least one link (or it would be unreachable) and by at most one link into the part already built (a second link into the built part would close a cycle). So each of the `n-1` later nodes contributes exactly one link. 2. **Acyclic + `n-1` links implies connected.** An acyclic graph — a **forest** — with `n` nodes and `c` components has exactly `n-c` links, because each component is a tree on its own node set. Setting `n-c = n-1` gives `c = 1`. 3. **Connected + `n-1` links implies acyclic.** If a cycle existed, you could delete one of its links and stay connected, because the rest of that cycle still joins the two endpoints. That leaves a connected graph on `n` nodes with `n-2` links, which is impossible: a connected graph needs at least `n-1` links. ## Why the count alone proves nothing The counterexample is small enough to draw. Take six nodes. Wire `A-B`, `B-C`, `C-A` as a triangle, and `D-E`, `E-F` as a separate path. That is `3 + 2 = 5` links over `6` nodes, exactly `n-1` — and the graph is both cyclic and disconnected. The arithmetic explains itself: the triangle spends one link more than its three nodes need, and the shortfall reappears as a component that was never joined on. | What you observe | What you may conclude | What stays open | |---|---|---| | `n-1` links only | nothing structural | may be cyclic, may be split | | Connected only | at least `n-1` links | may carry extra links and cycles | | Acyclic only | at most `n-1` links | may be split into several pieces | | Connected + `n-1` links | it is a tree | — | | Acyclic + `n-1` links | it is a tree | — | ## Reading it off a running overlay The practical asymmetry is cost. Counting links is a scan of the membership table. Deciding connectivity or acyclicity means walking the graph — visiting nodes and links once each — which is the more expensive check but the one that carries information. That is why the count is best used as a **guard**: if a broadcast overlay over `n` nodes reports anything other than `n-1` links, it is certainly not a tree, and you stop there. If it reports exactly `n-1`, you still have to walk it once. Two bounds fall out of the same argument and are worth keeping separately: - **Any connected graph on `n` nodes has at least `n-1` links.** So `n-1` is the floor for reaching everyone, and a tree is a connected graph that sits exactly on the floor. - **Any connected graph on `n` nodes with `n` or more links contains a cycle.** So the moment an overlay carries one link beyond the floor, some redundancy exists — though not necessarily where you wanted it. ## Where this bites A broadcast overlay that is meant to be a tree but is quietly a forest-plus-cycle behaves in two bad ways at once: part of the cluster never receives the message, and another part receives it more than once around the loop. Both symptoms are consistent with the same innocent-looking link count, which is exactly why the count is not the check. State the pair you actually verified, and the third property is free.

  • Why does every tree with two or more nodes have at least two nodes of degree one?
    Take a longest path in the tree and look at its two endpoints. If an endpoint had a second link, that link either leads to a node outside the path — which would make the path longer, contradicting the choice — or back to a node on the path, which would close a cycle. A tree has neither, so both endpoints have degree one. That is the guarantee behind "there is always a node you can peel off".
  • A connected overlay reports n+2 links over n nodes. What does that number tell you?
    It is connected with three links beyond the `n-1` floor, so it certainly contains cycles — specifically three independent ones, since the count of independent cycles in a connected graph is links minus nodes plus one. It does not tell you where they are, nor that each of the three sits on a different part of the overlay; several of them can share links.
  • Does the two-of-three rule still hold if the overlay allows two links between the same pair of nodes?
    Not as stated. A duplicated link is a cycle of length two, so a graph with repeated links can be connected with `n-1` links only if none are repeated. The characterizations are stated for simple graphs; with multi-links you must count distinct pairs, or treat a repeated link as the cycle it is.

saying these in an interview costs you the question

  • Says n-1 links alone proves the overlay is a tree
  • Thinks a cycle always pushes the link count above n-1
  • Assumes any acyclic link set already reaches every node
  • Believes a disconnected overlay must have fewer than n-1 links
  • Thinks adding any one link reconnects a split overlay
  • Claims a connected graph can have fewer than n-1 links