AlgoFrames

The handshake lemma

Challenge · Trace the algorithm · about 7 min

At a party every handshake involves two people. In graph terms: every edge has two ends, so the degrees always add up to 2 × the number of edges.

Use this rule to answer each question, then watch the degrees being counted.

Example 1

Input:

{"n":6,"edges":[[0,1],[1,2],[0,3],[1,4],[2,5],[3,4],[4,5],[1,5]],"directed":false,"positions":[[0,0],[1.6,0],[3.2,0],[0,1.6],[1.6,1.6],[3.2,1.6]]}

Output:

[2,4,2,2,3,3]

8 edges, so the degrees add up to 16.

Constraints

  • The trace uses the graph shown

Learn the idea first: Graphs: vertices, edges, directed, weighted, degree, paths, a visual lesson.

More Graphs: vertices, edges, directed, weighted, degree, paths problems