Algorithm for finding t-friends of node

痞子三分冷 提交于 2019-12-11 06:20:37

问题


I have the following exercise where I have a social graph look below. From my understanding if t = 2 and we have p = H then the result would be equal O and B.

Is this understanding correct?


回答1:


Do a breadth-first search from the origin point. When you enqueue a point, also enqueue the distance from the origin. Limit the distance to t by not enqueueing point with a distance more than t. The set of visited nodes is the solution.

You visit each vertex at most once, you visit each edge at most once. Complexity is O(E).



来源:https://stackoverflow.com/questions/55455796/algorithm-for-finding-t-friends-of-node

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!