Skip to content
DeepForgeby svx
All problems
EasyProbabilitypr-268

Two-State Transition Eigenvalues

Problem

The transition matrix [[1 - p, p], [q, 1 - q]] has eigenvalues 1 and 1 - p - q. Return both eigenvalues as a list with the larger first, or an empty list when p or q is outside [0, 1].

Hint

One eigenvector is the stationary distribution for eigenvalue 1; the trace gives the other eigenvalue.

Test cases

case 1
in: [0.1,0.2]
expected: [1,0.7]
case 2
in: [0.5,0.5]
expected: [1,0]
case 3
in: [1,1]
expected: [1,-1]
case 4
in: [0,0]
expected: [1,1]
case 5
in: [1.2,0.3]
expected: []
Starter codePython
def two_state_transition_eigenvalues(p, q):
    # Your code here
    pass

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