Is there a way, (efficiently or not), to find, given two persons X and Y on facebook, the number defined like this. If X and Y are friends then 1. Else if X has a friend who is a friend of Y, then 2. Else if X is a friend of a friend of a friend Y, then 3. etc.
clarification:
A program that does this, takes as input the names X and Y of any two persons on facebook.
Then if they are on eachothers friendslist, the program outputs 1.
If not, but they each have a common friend, then output 2.
If they are not friends and dont have a common friend, but each have a friend who are friends, then output 3.
If not, but X have a friend x, and Y have a freind y, and x and y have a common friend, then output 4. etc…
And if there is no connection between friends, output 0.
You are looking for something called the degree of separation.
The only way to fill each case would be to list as many friends of friends of friends … basically as close as your application allows to cover the Facebook graph. Then you represent the Facebook users as nodes on a graph and calculate the path from A to B. So it’s not really possible for a complete working application unless you had all the data from Facebook. Assuming you did, you can just use Dijkstra’s algorithm.
For a watered down version, you can check only your friends, make a graph out of it and find any degrees greater than 1.
You will need queries such as
me/friendsfor initializing the building of the graphSELECT uid1, uid2 FROM friend WHERE uid1 = ' + uid1 + ' AND uid2 IN (SELECT uid2 FROM friend WHERE uid1=me())for finding which of your friends are connected within the networkIf you just need this to display a path to a user from the current user, there is a hidden plugin within the JS SDK http://www.fbrell.com/saved/12bd86306fe69a2af6134fe2a9e645e3