PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Monday, June 27, 2022

[FIXED] How does facebook calculate mutual friends?

 June 27, 2022     database-design, graph, mysql, php, web-development-server     No comments   

Issue

In your opinion, how does facebook calculate mutual friends?

Has it cached all mutual friends for each user? Or does it let MySQL calculate through a query each time it displays them? Or does it make a query to the database and then calculate from a list? Or is there another way?


Solution

I believe it is pre-computed and not done when you load the page. How? There are a couple of options to look at this problem. A common way is to look at the data as a graph, where each person is a vertex, and an edge defines a friendship. Iterating through each existing pair of persons, and finding 2 edges paths. The vertexes you went over, are the mutual friends. If you really want to get into it, I would suggest starting with learning about Graph Theory

When dealing with such an amount of data, using MySql and queries won't work. On small amounts of data, it will.



Answered By - Noam
Answer Checked By - Gilberto Lyons (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing