Google Interview Question
Country: India
hmm.
For just Friends of Friends..
Do a BFS with slight change
when you reach a visited node again, instead of ignoring just increment the count, which indicates common friends. Keep a top 100 Priority Queue and keep adding whenever the count is more than the smallest in the queue.
Add other weightage factors now like,
same (ex-)company, same school, common group, same city etc.
Could this algorithm create an infinite loop?
Say a has a friend b who has a friend c who has a friend a.
also if c is a frnd of a, a is frnd of a too,indirect graph, so it will discovered at first and no loop
It seems like graph problem.
1) Check if one node can be reached(friends) from more than one node then that will be highly recommended node.
2) Friend of friend will next recommendation. (Less priority than first).
Graphs can be made for one person in many ways.
1) Based on names.
2) Based on places.
3) Based on schools.
(All Parameters like places etc.)
For each node in the FB graph, first find all nodes which can be reached with a path of length 2 from our node. These represent friends of friends nodes. For our nodes, sort these nodes list by the maximum no of paths of length 2 via which we can reach a node. Say that I have 5 nodes in the list which I can reach via a path of length 2 from my node. Now, if I can reach one of these nodes(say 'C') via 6 different 2-paths, that means that C and I share 6 mutual friends. This node is given the highest priority of recommendation.
- Anonymous December 11, 2011But, I think this way, we'll be storing way too much information for each and every node......a sorted list for each node....the length of which can go to thousands......