i am coding an app like facebook with java and android studio, how do i set code for knowing mutual friends? any hint please. | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 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.

11th May 2020, 4:22 PM
Vaibhav Agarwal
Vaibhav Agarwal - avatar
29 Answers
0
i didn't understand your last message. can you please simplify it! Mark McGuire
11th May 2020, 9:01 PM
Vaibhav Agarwal
Vaibhav Agarwal - avatar
+ 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).
13th May 2020, 12:57 PM
Gaurav Agrawal
Gaurav Agrawal - avatar
+ 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/
13th May 2020, 5:05 PM
Gaurav Agrawal
Gaurav Agrawal - avatar
+ 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.
13th May 2020, 11:25 AM
Pulkit Kamboj
Pulkit Kamboj - avatar
+ 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.
14th May 2020, 8:18 AM
David Carroll
David Carroll - avatar
+ 4
How do friends work?
11th May 2020, 8:33 PM
Mark McGuire
Mark McGuire - avatar
+ 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.
11th May 2020, 8:57 PM
Mark McGuire
Mark McGuire - avatar
+ 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 )
13th May 2020, 3:57 PM
Vaibhav Agarwal
Vaibhav Agarwal - avatar
+ 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();
14th May 2020, 5:02 AM
Divya Peddapalyam
Divya Peddapalyam - avatar
+ 1
So are the profiles a linked list, or is there like an array of profiles?
11th May 2020, 8:48 PM
Mark McGuire
Mark McGuire - avatar
+ 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?
11th May 2020, 9:03 PM
Mark McGuire
Mark McGuire - avatar
+ 1
no , thanks for asking. All queries resolved. Mark McGuire
11th May 2020, 9:06 PM
Vaibhav Agarwal
Vaibhav Agarwal - avatar
+ 1
checkpass fb
12th May 2020, 3:09 PM
Thịnh Đỗ Quốc
+ 1
I would loooove to partner but the situation won't allow. All the best anyway.
12th May 2020, 5:37 PM
Wanjiku Turky Alex
Wanjiku Turky Alex - avatar
+ 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 😊😊
13th May 2020, 10:47 AM
Abhijeet Thorat
Abhijeet Thorat - avatar
+ 1
Use Hashmaps..
13th May 2020, 2:00 PM
Anurag Chaudhary
Anurag Chaudhary - avatar
+ 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:)
13th May 2020, 4:20 PM
Pulkit Kamboj
Pulkit Kamboj - avatar
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 . !
11th May 2020, 8:39 PM
Vaibhav Agarwal
Vaibhav Agarwal - avatar
0
Right. But how do you keep track of who is friends with who?
11th May 2020, 8:40 PM
Mark McGuire
Mark McGuire - avatar
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
11th May 2020, 8:45 PM
Vaibhav Agarwal
Vaibhav Agarwal - avatar