How to find all equivalent vertices in a graph?

Equivalent vertices are those that have the same inbound and outbound vertices.

in this case ** a ** and ** c **

Can someone help me how to approach the algorithm?

I thought something like this: to search for two vertices at the same time, and if I find equal incoming and outgoing vertices to print them .. and so on, this will be actual brute force, but how to do it, for example, with recursion? What is the best solution?

+4
source share
2 answers

Here's the recursive solution I came up with.

Imagine that we delete all the vertices except two (it does not matter which two).

, , a b. , a b , a b, - b a. .

, ( ). . i) , - . ii) , - , .

1.

, c (, a b). , a b . ? a , b, c, c . , - , c. , c c. , a c .

: =, .

, , ( , z) , , , (, x y), x!= y, z, x = y z. , :

, x w, y . , w!= Z, z. , z, y w. x!= Y z. , - , z.

2

. , d (, a, b c ). , a c , , d. , , , , a c d . .


, , , . , case 1 case 2, .

, , EQ (n), . , n, EQ (n-1), .. ( z). case 1 case 2, , z . n = 2, .

, T (2) = O (1) T (n) = T (n - 1) + O (n ). , O (n ^ 2).

+1

, , List ingoingVertices, , List outgoingVertices. List outgoingVertices , , List ingoingEdges . , , , .

, , . Brute, , , .

+1

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


All Articles