0

I have this matrix that hold path between vertexes.for example for 4 vertex we have the matrix like this :

0 0 1 1

1 0 1 1

0 0 0 1

0 0 0 0

That shows us we have path between (1,3) & (1,4) & (2,1) & (2,3) & (2,4) & (3,4).

The input of my problem is new path between two vertex and the output is the update of that matrix .

For example :

Input:(3,2)

Output:

1 1 1 1

1 1 1 1

1 1 1 1

0 0 0 0

I want to do it with this order : O(V^2)

  • If you only add one new path, why did 6 of the values change from `0` to `1`? E.g. why is output showing a path (1,1)? – Andreas Jan 22 '16 at 22:52
  • @Andreas because we can go from 1 to 3 and then 3 to 2 and back to 1 from 2 . whats the problem ? – ali khorshidi rozbahani Jan 22 '16 at 22:57
  • Ok, got it now, thanks. Now, what have you tried so far? (see item 3 in "[What topics can I ask about here?](http://stackoverflow.com/help/on-topic))" – Andreas Jan 22 '16 at 23:06

1 Answers1

1

N = number of vertex.

You have your new edge : Input (A,B).

1 Then you iterate through B: for every existing edge (B,X), you get a (possible new) edge (A,X) => si N operations

2 Same thing with A: for every existing edge (Y,A), you get a (possible new) edge (Y,B) => si N operations

You do the same thing with X, and Y (maximum 2 N).

3 For every (Y,A) and (B,X), you add (Y,X), so NxN operations.

So it is O(N^2)