skip to content

questions

25

In a replication mesh where each link joins two machines, why does the sum of machines' link counts equal twice the link count?

level: juniorimportance: must knowfreq 70%

answer

  1. count ends, not whole links
  2. each link touches exactly two machines
  3. one set of objects, two totals
  4. parity falls out of the total
  5. degree total never comes out odd

basics

~20 s

Every link has two ends, and each end raises exactly one machine's link count by one. Totalling link counts therefore counts every link twice. This is the handshake lemma: the degree sum equals 2E, so it is always even.

solid answer

~40 s

Model each machine as a vertex and each replication link as an edge; a machine's **degree** is how many link-ends it carries. The handshake lemma is a double count of one set: the set of link-ends. Walk the links and you find `2E` ends, since each link has exactly two. Walk the machines and you find the degree sum. Both totals count the same objects, so the degree sum is `2E`. Two consequences do real work: the degree sum can never be odd, and the average number of links per machine is `2E/V`. So a proposed wiring plan whose per-machine counts add to an odd number is not merely awkward to build - no mesh realises it at all.

go deeper

for a junior

Recall the identity in one line: total link-ends equals twice the number of links, because every link has two ends. Be able to state that the degree total is therefore always even.

for a middle

Explain it as a double count of link-ends rather than quoting it, and state what changes under self-links, parallel links and one-way links. Derive the average fan-out as twice the link count over the machine count.

for a senior

Use it as a screen on a real plan: halve the stated degree total to get the link budget, reject an odd total outright, and be clear that passing the screen does not prove the plan is buildable.

for a principal

Know when the model itself is the decision: whether links are one-way changes which identity applies and therefore which capacity numbers a plan should be judged against. Choosing the wrong model quietly halves or doubles the budget.

## What a degree counts Model a peer-to-peer replication mesh as a graph: each machine is a **vertex**, each bidirectional replication link is an **edge**. The **degree** of a machine is the number of *link-ends* attached to it. In a **simple** graph - no link from a machine to itself, never two links between the same pair - degree also equals the number of distinct peers, which is why the two ideas get conflated. The link-end reading is the one that survives every convention, so prefer it. ## The double count The **handshake lemma** states that the sum of all degrees equals twice the number of edges. The argument is a *double count*: pick one set of objects and total it two different ways. 1. Take the set of all link-ends. Every link contributes exactly two ends, so walking the links gives `2E` ends. 2. Walk the machines instead. Each machine reports its own degree, so this walk gives the degree sum. 3. Both walks enumerate the same set of link-ends without omission or repetition, so the two totals are equal: degree sum `= 2E`. Nothing in that argument depends on the mesh being connected, on the links being placed sensibly, or on any machine's degree in particular. It is pure bookkeeping, which is exactly why it is safe to lean on during a design review. ## What the lemma forces - The degree sum is **even**, in every graph, always. There is no wiring, however exotic, that makes it odd. - The number of machines with an **odd** degree is even - odd values have to pair up for the total to come out even. - The **average** degree is `2E/V`. Ask for the average number of peers per machine and you are really asking for this ratio. - Adding one link raises exactly **two** degrees by one each, so the degree sum moves in steps of two. - In a simple mesh no degree exceeds `V - 1`, because a machine has only that many distinct peers available. ## Conventions that change the arithmetic The lemma is stable, but what one link contributes depends on the structure you chose to model with: | structure | what one link contributes | resulting identity | |---|---|---| | ordinary undirected link | one to each of two endpoints | degree sum = `2E` | | self-link (loop) | two to its single endpoint | degree sum = `2E` | | parallel links between one pair | one to each endpoint, per link | degree sum = `2E` | | directed link | one out-degree, one in-degree | out-sum = in-sum = `E` | The self-link row is the one people get wrong. A loop is drawn once, so it looks like it should add one - but it attaches **both** of its ends to the same machine, so it adds two. That convention exists precisely to keep the lemma true; abandon it and the identity breaks for no gain. The directed row is worth internalising separately. Once links carry a direction, there is no single degree per machine: there is an in-degree and an out-degree, and each *individually* sums to `E` rather than `2E`. If replication in your mesh is one-way per link, that is the identity to quote. ## Using it on a wiring plan The practical move is to treat the degree sum as a cheap screen before anyone reasons about topology. Given a plan that states how many peers each machine should end up with: - add the numbers up; if the total is odd, stop - the plan is unrealisable and no amount of rearranging helps; - if the total is even, it equals `2E`, so halve it to learn how many links the plan actually requires, which is usually the number someone wanted for capacity planning anyway; - divide by the machine count for the average fan-out, and compare it against the ceiling `V - 1`. None of this proves the plan *is* buildable - an even sum is necessary, not sufficient, and a plan can clear it and still fail for structural reasons. But it is a one-line check that kills a whole family of bad plans, and it is the reason this lemma shows up in interviews at all: it is the smallest example of an argument that constrains a design before the design exists. ## The name The lemma is called the handshake lemma because of its oldest phrasing: in any room, the total number of hands shaken, counted per person, is twice the number of handshakes - since each handshake involves exactly two people.

  • Does the identity still hold when a machine has a link to itself?
    Yes, by convention a self-link adds two to its own machine's degree, because both of its ends attach there. That convention exists to keep the degree sum equal to twice the edge count; the lemma is unchanged, and the degree sum stays even.
  • What does the lemma say about the average number of peers per machine?
    The average degree is the degree sum divided by the machine count, so it equals `2E/V`. A mesh of 50 machines and 120 links averages 4.8 peers each. The average alone says nothing about the spread - one machine may still carry far more links than the average.
  • How does the identity change if replication links are one-way?
    There is no single degree per machine any more. Each directed link adds one out-degree at its source and one in-degree at its target, so the out-degrees sum to `E` and the in-degrees sum to `E` separately - not `2E`. Adding the two sums back together recovers `2E`.

Count the plugged-in cable ends at the back of a rack instead of the cables. Every cable has two ends, so the end count is always exactly double the cable count.

saying these in an interview costs you the question

  • Says the degree sum equals the number of links.
  • Counts a self-link as adding one to a machine's degree.
  • Thinks the identity needs the mesh to be connected.
  • Confuses the degree sum with the number of machines.
  • Claims an odd degree sum is possible in some layouts.
  • Treats degree as the count of machines reachable, not links attached.
open as a page

What does the chromatic number of a conflict graph tell a scheduler that joins clashing jobs by an edge?

level: middleimportance: must knowfreq 65%

basics

~20 s

The chromatic number is the fewest colours that label every vertex so no edge has one colour at both ends. On a conflict graph it is the minimum number of time slots any valid schedule can use.

open as a page

In a fibre backbone graph, what makes a site a cut vertex and a span a bridge?

level: middleimportance: must knowfreq 64%

basics

~20 s

A cut vertex is a site whose removal, together with its spans, leaves the network in more pieces than before; a bridge is a span whose removal alone does that. Both name single points of failure.

open as a page

In a fibre network, when can one closed route use every span exactly once?

level: middleimportance: must knowfreq 58%

basics

~20 s

Exactly when every span lies in one connected piece and every site has even degree. Each visit to a site uses one span in and one out, so an odd degree makes a closed route over every span impossible.

open as a page

A wiring plan gives each of seven machines exactly three replication links - why can no such mesh exist?

level: middleimportance: must knowfreq 54%

basics

~20 s

The degrees would sum to 7 x 3 = 21, which is odd, but every graph's degree sum equals twice its edge count and so must be even. The plan is impossible for any wiring, not just awkward ones.

open as a page

A scheduler pairs work items to eligible engineers until no further pair fits, so why can the result still be undersized?

level: middleimportance: must knowfreq 62%

basics

~20 s

A maximal pairing is one no extra pair can be added to; a maximum pairing is one of the largest possible size. Stopping when nothing more fits guarantees only the first, because an early pair can block two later ones.

open as a page

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

level: middleimportance: must knowfreq 58%

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.

open as a page

In a tree-shaped broadcast overlay, why does exactly one path connect any two nodes?

level: middleimportance: must knowfreq 50%

basics

~10 s

Because connectivity guarantees at least one path and acyclicity forbids a second: two distinct paths would diverge and rejoin, and that closed region is a cycle. Uniqueness is itself a definition of a tree.

open as a page

Why does colouring overlapping reservations in start-time order need exactly as many slots as the busiest instant?

level: seniorimportance: must knowfreq 55%

basics

~20 s

In start-time order a reservation meets only earlier ones still open, and those all contain its start instant, so it takes a new slot only when the overlap grows. The busiest instant is both the unavoidable floor and the count the sweep reaches.

open as a page

Every backlog item lists the engineers allowed to take it, so what condition on those lists decides whether all items can be staffed at once?

level: seniorimportance: must knowfreq 52%

basics

~20 s

All items can be staffed at once exactly when every set of items is collectively eligible for at least as many distinct engineers as that set has items. That is Hall's condition, and a violating set is the proof of failure.

open as a page

Why can a greedy colouring of a conflict graph never need more than the maximum degree plus one colours?

level: middleimportance: should knowfreq 45%

basics

~20 s

Greedy gives each vertex the smallest colour none of its already-coloured neighbours holds. A vertex has at most maximum-degree neighbours, so at most that many colours are blocked, and one of the first maximum-degree-plus-one colours is always free.

open as a page

Why does 'reachable from' split an undirected backbone into components with every site in exactly one?

level: middleimportance: should knowfreq 41%

basics

~20 s

Because reachability in an undirected graph is an equivalence relation — reflexive, symmetric and transitive — and the classes of an equivalence relation partition the set. So every site lies in exactly one component and no two components overlap.

open as a page

In a mesh of n machines with no self-links or duplicate links, what is the maximum possible number of links?

level: middleimportance: should knowfreq 46%

basics

~10 s

At most n(n-1)/2, one link per unordered pair of machines. Every machine then reaches degree n-1, so the degree sum is n(n-1), which is twice the link count exactly as the handshake lemma requires.

open as a page

Why does a clique of mutually conflicting jobs put a floor under the number of slots a schedule needs?

level: seniorimportance: should knowfreq 38%

basics

~20 s

In a clique every job conflicts with every other, so no two may share a slot and k mutually conflicting jobs force k distinct slots. The size of the largest clique is therefore a lower bound on the chromatic number.

open as a page

A wiring plan lists the link count each machine must end with - which checks decide whether it is buildable?

level: seniorimportance: should knowfreq 33%

basics

~20 s

Three screens rule plans out: every listed count must be between 0 and one less than the fleet size, and the counts must sum to an even number. Those are necessary only; a recursive reduction decides the rest.

open as a page

In a partial pairing of work items to eligible engineers, what is an augmenting path and what does its existence prove?

level: seniorimportance: should knowfreq 42%

basics

~20 s

An augmenting path runs between two currently unpaired vertices and alternates unpaired and paired edges. One exists exactly when the pairing is not maximum, and flipping every edge along it enlarges the pairing by exactly one.

open as a page

On a bipartite eligibility graph, why does the largest possible pairing also fix the smallest set of vertices touching every edge?

level: seniorimportance: should knowfreq 36%

basics

~10 s

A vertex cover needs a distinct vertex for each pair of a matching, so no cover is smaller than the largest matching. Konig's theorem says that on bipartite graphs the two are exactly equal.

open as a page

An audit lists every bridge in a backbone: how do you decide which new spans to fund?

level: principalimportance: should knowfreq 33%

basics

~20 s

Fund the spans that put bridges on cycles, ranked by what each bridge separates. A span only helps if it creates a second route across the cut; clearing every bridge still leaves cut vertices, which is a separate exposure to price.

open as a page

A broadcast overlay runs n-1 links over n nodes: what does that tree structure force you to trade away when the cluster is asked to survive the loss of any single link?

level: principalimportance: should knowfreq 30%

basics

~20 s

Tree-ness itself. n-1 links is the floor for reaching everyone, so a tree has no spare route: losing any link splits it in two. Surviving any single loss needs at least n links, hence cycles and duplicates.

open as a page

A span map has four sites of odd degree: what does that force on an inspection plan covering every span?

level: seniorimportance: nice to knowfreq 26%

basics

~20 s

No single route can cover every span exactly once. Four odd-degree sites force at least two separate open routes, because each route absorbs only two odd sites — or you repeat spans to pair the odd sites up first.

open as a page

Why does a mesh diagram that can be drawn with no crossing links hold at most 3V - 6 links?

level: seniorimportance: nice to knowfreq 24%

basics

~20 s

A crossing-free drawing satisfies Euler's formula V - E + F = 2, and every face needs at least three link-sides while each link borders two faces. Combining the two caps links at 3V - 6, so such diagrams stay sparse.

open as a page

How many distinct spanning-tree overlays can a fully-meshed cluster of n labelled nodes have?

level: seniorimportance: nice to knowfreq 22%

basics

~20 s

n to the power n-2, by Cayley's formula: 16 for four nodes, 125 for five, 1296 for six. When only some pairs can be linked, the matrix-tree theorem counts instead, as a cofactor of the graph's Laplacian determinant.

open as a page

When a conflict graph's slot count keeps climbing, how do you decide between better colouring and changing the model?

level: principalimportance: nice to knowfreq 26%

basics

~20 s

Measure the floor first: the largest mutually conflicting group is a count no colouring can beat. If that floor is what is rising, only deleting conflicts or adding capacity helps; a wide gap above the floor means better colouring is still available.

open as a page

A staffing tool reports only that 6 of 20 items went unassigned, so what certificate should it surface instead and what decision does that unlock?

level: principalimportance: nice to knowfreq 24%

basics

~20 s

Surface the constrained set: the group of items whose combined eligibility names too few engineers, with its exact shortfall. That set is a proof rather than an outcome, and it says precisely where cross-training or hiring raises the ceiling.

open as a page