How can I prove the “Six Degrees of Separation” concept programmatically?

前端 未结 4 1095
-上瘾入骨i
-上瘾入骨i 2021-01-31 23:22

I have a database of 20 million users and connections between those people. How can I prove the concept of \"Six degrees of separation\" concept in the most efficient w

4条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-01-31 23:56

    Well a better answer has already been given, but off the top of my head I would have gone with the Floyd-Warshall all pairs shortest path algorithm, which is O(n^3). I'm unsure of the complexity of the graph diameter algorithm, but it "sounds" like this would also be O(n^3). I'd like clarification on this if anyone knows.

    On a side note, do you really have such a database? Scary.

提交回复
热议问题