4

There is a Dijkstra's algorithm. I want to generate graph with given |E| and |V|, in which the algorithm perform maximum number of relaxations: alt ← dist[u] + length(u, v).

This is a ACM problem. But I have no idea how to solve it. I look forward to any ideas.

Example. Let |V| = 4 and |E| = 3. Than, I looking for a graph with the following edges and weight (v1, v2, w):

(1, 2, 0)

(1, 3, 1)

(1, 4, 2)

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
Max
  • 1,803
  • 3
  • 25
  • 39

1 Answers1

5

This looks like it might work, although I didn't give it much thought yet.

Add edges (1, 2, 1); (1, 3, 2); ...; (1, N, k).

If not done, add edges (2, 3, cost(1, 3) - 2); (2, 4, cost(1, 4) - 2); ...

If not done, add edges (3, 4, cost(1, 4) - 3); ...

And so on, until done.

Your graph will look like:

 4---------------
 |        \     |
 |         |    |
(3)       (1)   |
 |         |    |
 |         |    |
 1 --(1)-- 2   (0) 
 |         |    |
 |         |    |
(2)       (0)   |
 |         |    |
 |        /     |
 3---------------

First, the algorithm will relax all nodes connected to node 1:

d[4] = 3
d[2] = 1
d[3] = 2

Then, all those connected to node 2:

d[3] = 1
d[4] = 2

Then all those connected to node 3

d[4] = 2

So we did 6 relaxations: one for each edge. This is the maximum possible.

IVlad
  • 43,099
  • 13
  • 111
  • 179