Skip to content
DeepForgeby svx
All problems
EasyGraph Algorithmsgraph-080

Laplacian Zero Eigenvalue Count

Problem

Return the multiplicity of the zero eigenvalue of the Laplacian of an undirected graph.

A classical result states that this multiplicity equals the number of connected components, so simply count components, treating isolated nodes as their own component. edges is a list of [u, v] pairs.

Hint

The multiplicity of eigenvalue 0 equals the number of connected components.

Test cases

case 1
in: [4,[[0,1],[1,2]]]
expected: 2
case 2
in: [3,[]]
expected: 3
case 3
in: [5,[[0,1],[1,2],[2,3],[3,4]]]
expected: 1
case 4
in: [4,[[0,1],[2,3]]]
expected: 2
case 5
in: [1,[]]
expected: 1
Starter codePython
def zero_eigenvalue_multiplicity(n, edges):
    # Your code here
    pass

5 test cases · run your code against them in the editor