🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← Quiz: Graph Theory: all 10 questions

Quiz: Graph Theory · Question 7 of 10

What does this print? (code)

What does this print?

edges = [(1, 2), (2, 3), (3, 1), (3, 4)]
deg = {}
for u, v in edges:
    deg[u] = deg.get(u, 0) + 1
    deg[v] = deg.get(v, 0) + 1
print(sum(deg.values()), sum(1 for d in deg.values() if d % 2))
  1. A.4 2
  2. B.8 1
  3. C.8 2
  4. D.8 4
Answer & explanation

Correct answer: 8 2

The degree sum is 2 × 4 edges = 8, and the odd-degree vertices (3 and 4) come in an even number, as the handshaking lemma says.

Can you get the rest right without peeking?

Take the timed Quiz: Graph Theory quiz free. Pass it to earn XP and count towards your certificate.

Start the quiz →