The shortest way in the complement graph algorithm

Today I had a test (Data Structures course), and one of the questions was as follows: Given the undirected, non-weighted graph G = (V, E), you need to write an algorithm that for this node s returns the shortest path from s to all nodes v 'in the complement graph.

The complement graph G '= (E', V ') contains an edge between any nodes in G that do not share an edge, and only those.

The algorithm should be executed in O (V + E) (the original graph).

I asked 50 different students, and even one of them did not solve it correctly.

any ideas? Thanks a lot, Barak.

+4
source share
1

.

:

" BFS . node 2 - next prev. , Doubly-Linked : L1, L2. L1 , L2 . BFS ( ):

The algorithm

3-5 L1 , u G, , , , u . BFS . O (V + E), 4-5 2E, 7-9 V ( node L1 ).

: , .

, , , ,

Barak.

+4

Source: https://habr.com/ru/post/1546473/


All Articles