Efficient way to implement LinkedIn like “How you are connected to” feature?
LinkedIn has this cool feature in which while visiting some user's profile, LinkedIn prompts how you are connecting to that user through the network. Assuming that the visitor and the profile owner are two nodes of a graph where the nodes represent users and edge represents friendship, a simple solution could be a bfs starting from both the nodes up to certain level and see if there are any intersections. The intersections would be the network link-nodes. Although this sounds neat, the problem is that in order to determine friends of each person, a separate DB query is needed. When the network