All problems
HITS Hub/Authority One Iteration
Problem
Perform one iteration of the HITS algorithm on a directed graph with n nodes.
Start with all hub and authority scores equal to 1. The new authority score of v is the sum of hub scores of its in-neighbors, and the new hub score of u is the sum of authority scores of its out-neighbors. Normalize each vector by its L2 norm (leave an all-zero vector as zeros). Return [hubs, authorities]. edges is a list of [u, v] pairs.
Hint
Hubs point to good authorities; authorities are pointed to by good hubs.
Test cases
case 1
in: [3,[[0,1],[0,2]]]
expected: [[1,0,0],[0,0.7071067811865475,0.7071067811865475]]
case 2
in: [3,[[0,1],[1,2],[2,0]]]
expected: [[0.5773502691896258,0.5773502691896258,0.5773502691896258],[0.5773502691896258,0.5773502691896258,0.5773502691896258]]
case 3
in: [2,[[0,1],[1,0]]]
expected: [[0.7071067811865475,0.7071067811865475],[0.7071067811865475,0.7071067811865475]]
case 4
in: [2,[]]
expected: [[0,0],[0,0]]
Starter codePython
import math
def hits_one_iteration(n, edges):
# Your code here
pass4 test cases · run your code against them in the editor