Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6366467
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T00:25:30+00:00 2026-05-25T00:25:30+00:00

How you would code an efficient algorithm which can return a social ‘distance’ between

  • 0

How you would code an efficient algorithm which can return a social ‘distance’ between two users.

For example, when you visit a profile on LinkedIn you can see what is the distance between you and the user.

-> user A is friend with user B – and B is friend with C. when A will visit C (the distance will be 1)

The graph is huge and so I’m wondering how it can be perform so fast.

I know that this question is likely to be closed but I really think it is a programming/algorithm question – I would not specify any languages because I am interested about the concept.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T00:25:30+00:00Added an answer on May 25, 2026 at 12:25 am

    assuming you don’t have any heuristic function about the distance to the target, the best solution that is valid is bi-directional BFS:

    Algorithm idea: do a BFS search simultaneously from the source and the target: [BFS until depth 1 in both, until depth 2 in both, ….].

    The algorithm will end when you find a vertex v, which is in both BFS’s front.

    Algorithm behavior: The vertex v that terminates the algorithm’s run will be exactly in the middle between the source and the target.

    This algorithm will yield much better result in most cases then BFS from the source [explanation why it is better then BFS follows], and will surely provide an answer, if one exist.

    why is it better then BFS from the source?

    assume the distance between source to target is k, and the branch factor is B [every vertex has B edges].

    BFS will open: 1 + B + B^2 + ... + B^k vertices.

    bi-directional BFS will open: 2 + 2B + 2B^2 + 2B^3 + .. + 2B^(k/2) vertices.

    for large B and k, the second is obviously much better than the first.

    EDIT:

    NOTE, that this solution does NOT require storing the whole graph in memory, it only requires implementing a function: successor(v) which returns all the successors of a vertex [all vertices you can get to, within 1 step from v]. With this, only the nodes you open [2 + 2B + ... + 2B^(k/2) as explained above] should be stored. To further save memory, you can use Iterative Deepening DFS from one direction, instead of BFS, but it will consume more time.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Given a URL, what would be the most efficient code to download the contents
Can somebody please demonstrate for me a more efficient Cartesian product algorithm than the
Question of the century? I basically want to know which would be more efficient
Prior to C# generics, everyone would code collections for their business objects by creating
Developing websites are time-consuming. To improve productivity, I would code a prototype to show
How would one code the following C# code in Managed C++ void Foo() {
I thought this code would work, but the regular expression doesn't ever match the
I would like a code sample for a function that takes a tDateTime and
in my code i would like boost::shared_ptr not to call delete but call ptr->deleteMe()
Suppose I have some code that would, in theory, compile against any version of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.