Recently, an interesting question has been asked.
- You have 1 million users.
- Each user has 1 thousand friends.
- Your system should effectively answer the question
Do I know him? for each pair of users. The user "knows" the other if he is connected through 6 levels of friends.
eg. A is a friend of B , B is a friend of C , C is a friend of D , D is a friend of E , E is a friend of F , so we can say that A knows F
Obviously, you cannot effectively solve this problem using BFS or other standard moving techniques. The question is how to save this data structure in the database and how to quickly perform this search.
I did not find the answer, maybe someone has an idea?
source share