Graph optimization problem

Правка en3, от Mr.Awesome, 2016-09-02 18:18:28

Hi everyone.

Lets suppose that we have an array with differents elements, and a function f(x,y) that takes 2 elements from the array and return true or false..

We want to extract all connected components.

Note that if f(x,y) = true and f(y,z) = true then x,y,z are in the same connected component even though f(x,z) = false

My simple solution is to iterate over each pair(x,y) and connect vertex with value x to a vertex with value y if f(x,y) = true , and then extract all connected components.

The complexity of this solution is O(n^2) , However i'm looking for a better solution. Thanks.

UDP I guess i didn't explain well, so here an example :

Lets a be an array : a = { 1 , 4 , 7 , 5 , 9 }

f(1,4)=true , f(1,7)=false , f(1,5)=false , f(1,9)=false f(4,7)=false , f(4,5)=false , f(4,9)=true f(7,5)=true , f(7,9)=false f(5,9)=false

So the answer will be 2 sets ( 1,4,9 ) and (7,5)

Note that f(x,y)=f(y,x)

N=1e5

Теги graph, optimization

История

 
 
 
 
Правки
 
 
  Rev. Язык Кто Когда Δ Комментарий
en3 Английский Mr.Awesome 2016-09-02 18:18:28 103
en2 Английский Mr.Awesome 2016-09-02 18:10:24 362
en1 Английский Mr.Awesome 2016-09-02 15:11:30 615 Initial revision (published)