Given two S and T vertices in an undirected graph G I was thinking on the best way to find their common neighbors. I was thinking about this:
Map all the neighbors of S in a hash table in a size of V. The hash table simply take each vertex and put him in his place in the table based on his index. Then I go over all the neighbors of T and put him in the same hash table and if one of them get to a place that is already taken than this is the common vertex. the complexity for this algorithm is O(V+E).
Is there any better algorithm?