, BFS http://en.wikipedia.org/wiki/Breadth-first_search
-:
, , , .
: cost runtime O(n) (, , O(1)).
-
, O(n*n), n - . O(1) O(logn) ,
( , , , O(n) O(n*n)).
, , , . , - , , , , , .
</" > 17 . , .
. O(n*n) , , , .
, , .
, - :
( userId). ( - userId).
17 . 17 mio. ( O(n*n)).
Offline BFS , , , BFS . , , . BFS node, .. .
, BFS node, O(n*n) runtime. , , .. . , , .
, . " , , ". BFS, O(n), . BFS (userId) , .
Online userId .