-1

I need to find the minimum distance between two nodes in a undirected graph, here are some details

  • The graph is undirected and huge(no of nodes is in order of 100,000)
  • The graph is sparse, no of edges is less than no of nodes
  • I am not interested in the actual path, just the distance.

What representation and algorithm should I use for a) Space efficiency b)time efficiency?

EDIT: If it matters,

  • The wieghts are all non zero positive integers.
  • No node connects to itself.
  • Only single edge between two adjacent nodes
Salvador Dali
  • 182,715
  • 129
  • 638
  • 708
Registered User
  • 2,139
  • 3
  • 27
  • 52

1 Answers1

0

It depends on the weights of the edges. If they are non-negative - Dijkstra suits you. If your graph is planar, you can use A*.

If you have negative weights, you have to use Bellman-Ford.

Salvador Dali
  • 182,715
  • 129
  • 638
  • 708