All problems
Laplacian Eigenvalue Trace Sums
Problem
Return the sum and the sum of squares of the Laplacian eigenvalues without computing eigenvalues.
The trace of L equals the sum of eigenvalues and trace(L^2) equals the sum of squared eigenvalues; build L = D - A and evaluate both by matrix multiplication. edges is a list of [u, v] pairs. Return [trace, trace_square] as integers.
Hint
trace(L^2) also equals sum of squared degrees plus twice the number of edges.
Test cases
case 1
in: [3,[[0,1],[1,2]]]
expected: [4,10]
case 2
in: [3,[[0,1],[1,2],[2,0]]]
expected: [6,18]
case 3
in: [4,[[0,1],[0,2],[0,3]]]
expected: [6,18]
case 4
in: [1,[]]
expected: [0,0]
case 5
in: [4,[[0,1],[1,2],[2,3],[3,0]]]
expected: [8,24]
Starter codePython
def laplacian_spectrum_sums(n, edges):
# Your code here
pass5 test cases · run your code against them in the editor