Find Two vertices with lowest path weight

ぐ巨炮叔叔 提交于 2019-12-24 21:01:17

问题


I am trying to solve this question but got stuck.
Need some help,Thanks.

Given an undirected Connected graph G with non-negative values at edges.
Let A be a subgroup of V(G), where V(G) is the group of vertices in G.

-Find a pair of vertices (a,b) that belongs to A, such that the weight of the shortest path between them in G is minimal, in O((E+V)*log(v)))

I got the idea of using Dijkstra's algorithm in each node which will give me O(V*((E+V)logv))),which is too much.
So thought about connecting the vertices in A somehow,did'nt find any useful way.
Also tried changing the way Dijkstra's algorithm work,But it get's to hard to prove with no improvment in time complexity.


回答1:


Note that if the optimal pair is (a, b), then from every node u in the optimal path, a and b are the closest two nodes in A.

I believe we should extend Dijkstra's algorithm in the following manners:

  1. Start with all nodes in A, instead of a single source_node.
  2. For each node, don't just remember the shortest_distance and the previous_node, but also the closest_source_node to remember which node in A gave the shortest distance.
  3. Also, for each node, remember the second_shortest_distance, the second_closest_source_node, and previous_for_second_closest_source_node (shorter name suggestions are welcome). Make sure that second_closest_source_node is never the closest_source_node. Also, think carefully about how you update these variables, the optimal path for a node can become part of the second best path for it's neighbour.
  4. Visit the entire graph, don't just stop at the first node whose closest_source and second_closest_source are found.
  5. Once the entire graph is covered, search for the node whose shortest_distance + second_shortest_distance is smallest.


来源:https://stackoverflow.com/questions/48037215/find-two-vertices-with-lowest-path-weight

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