Question: Python BFS problem: In this problem, you'll implement a version of Facebook's friend suggestions (people you may know). Write a Python function suggest_friends (adj, s,

Python BFS problem:

In this problem, you'll implement a version of Facebook's friend suggestions ("people you may know"). Write a Python function suggest_friends (adj, s, k) where adj is the adjacency lists for an undirected graph where nodes are people and edges represent friendships, s is the index of a person, and k is a positive integer. It should return a list of exactly k people (indices) who are not s or s's friends but are as close as possible to s in the graph. You may assume there are always at least k such people. You may break ties arbitrarily; e.g., if k = 10 and s has 5 friends, 6 friends-of-friends, and 7 friends-of-friends-of-friends, then the return list should include all 6 friends-of-friends follow by any 4 of the friends-of-friends-of-friends. Your program should be a modification of BFS (breadth-first search) and run in time O (n + m).

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!