How to find common element in Adjacency List

Mar 6, 2010 at 4:30am
I have a graph and as you know we can use adjacency matrix or adjacency list to represent a graph.

For example, there are two representations of a graph with five vertices.

Adjacency List
1
2
3
4
5
0 1 3 4
1 0 2 3
2 1 3
3 0 1 2 4
4 0 3


This can also be represented as following;

Adjacency Matrix
1
2
3
4
5
6
  0 1 2 3 4
0 0 1 0 1 1
1 1 0 1 1 0
2 0 1 0 1 0
3 1 1 1 0 1
4 1 0 0 1 0


What I would like to do is the following;
Using Adjacency List, given two vertices, say v1 and v2, find common neighboring vertices.

For example, given vertices 0 and 1, I would like to find common neighboring vertex, which is 3 in the above example.

This is easy with Adjacency Matrix, but my problem size is huge, I would like to use Adjacency List.

Just for your information, I stored the Adjacency List in 2D vector.

Any help would be appreciated!!
Topic archived. No new replies allowed.