+ 4
i am coding an app like facebook with java and android studio, how do i set code for knowing mutual friends? any hint please.
29 Respuestas
0
i didn't understand your last message. can you please simplify it! Mark McGuire
+ 8
Generally graphs used for such platforms are sparse graphs(not too many edges/connections, too less than (number of users)^2, you can say in k.(number of users)).
Adjacency list implementation of graph will save you space by not storing data about which nodes/users are not connected but it will not be that fast in identifying if 2 users are friends(for user having too many friends it will be little slow but is best implementation as most of users have less number of friends).
+ 7
Vaibhav Agarwal
You can get shortest path from source node to destination node using bfs(breadth first search), some more algorithms are there for it.
I hope this link will help you
https://www.geeksforgeeks.org/shortest-path-unweighted-graph/
+ 6
Bro, you can use graph data structure to know mutual friends, this is the same algorithm which is used by Facebook as well as most of the apps to know mutual friends, Let us take three persons with names A ,B and C, now if A and C are mutual friends if A is connected to B and not connected to C directly but B is connected to C. So, we use undirected graphs to acheive it.
+ 6
Vaibhav Agarwal From my own personal experience, using a graph database would be a good place to start.
I highly recommend looking at Neo4J as your graph database.
https://neo4j.com/sandbox/
Go through the various demos where you learn by doing within the UI. It's simply quite brilliant.
+ 4
How do friends work?
+ 2
There are two easy ways. It's just a question of what one is better. Sorry if I'm overwhelming you with a lot of questions. I'm going to school for engineering so I've been thinking about these trade offs way too much.
+ 2
nipnix , Gaurav Agrawal , Pulkit Kamboj , Abhijeet Thorat ,Mark McGuire thanks for your answers,
one more thing please. What do i code, if i provide a feature (in my facebook alike app) by which users just search any name on app and he could know that how the person he search is connected with him?
for ex:
mr A has many friends including mr L
mr L has many friends including mr K
mr K has many friends including mr W.
mr W has many friends including mr F.
so if mr A search for mr F, then my app can show that mr A is connected with mr F in four steps that is mr A>mr L>mr K>mr W>mr F.
(because after all everyone is connected with everyone else )
+ 2
Hai vaibhav,You can try this,Hope this may help youThis is for innovators and developers like you.I think you can achieve this.Here is an examples you can try this
/* make the API call */
new GraphRequest(
AccessToken.getCurrentAccessToken(),
"/{Mutual-friends}",
null,
HttpMethod.GET,
new GraphRequest.Mutual friends() {
public void onCompleted(GraphResponse response) {
/* handle the result */
}
}
).executeAsync();
+ 1
So are the profiles a linked list, or is there like an array of profiles?
+ 1
Basically. I may be thinking about this too hard because it's been in my coursework a lot. Would you like me to point you a simple answer?
+ 1
no , thanks for asking. All queries resolved. Mark McGuire
+ 1
checkpass fb
+ 1
I would loooove to partner but the situation won't allow.
All the best anyway.
+ 1
I would recommend to try using proper data structures to do that
The idea is your list of friends and someone others lisy of friends is created
Then using an loop that goes through the whole list (any data struture you use) and read every unique id of your friends
Then the same process with other friend
Then the 3rd loop would be used for comparison and the same entry of mutual friends would be saved to new list
This way you can create mutual friend for both of them
Make this as an function and look for not having any dependencies to make it easy
😊😊
+ 1
Use Hashmaps..
+ 1
Yes Vaibhav Agarwal , you should Google depth first search algorithm of graph and you can find the shortest path from source node to destination node(if multiple relations exist)(source node - L , destination node= F)
Edit- doing a breadth first search would be better as it will give you the shortest path automatically, totally agree with Gaurav Agrawal
hence you can print the shortest path
Hope it helps:)
0
Mark McGuire , i want to ask that, what code i write to let my users know, which friends they have in common with someone else on my app . !
0
Right. But how do you keep track of who is friends with who?
0
same like facebook , first users make some friends by sending and accepting friends requests.
for example- mr A has 10 friends , & mr B has 15 friends.. and say they have 3 friends in common , then how mr A& mr B can know this fact! Mark McGuire