Skip to content
DeepForgeby svx
All problems
MediumML Fundamentalsml-158

Isolation Path Length Factor

Problem

Compute the isolation forest path-length normalization c(n) = 2*H(n-1) - 2*(n-1)/n, where H(m) is the m-th harmonic number.

Return 0.0 for n <= 1.

Hint

c(n) normalizes the average path length of an unsuccessful search in a binary search tree.

Test cases

case 1
in: [2]
expected: 1
case 2
in: [3]
expected: 1.6666666666666667
case 3
in: [5]
expected: 2.566666666666666
case 4
in: [1]
expected: 0
case 5
in: [0]
expected: 0
Starter codePython
def isolation_path_factor(n):
    # Your code here
    pass

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