|
Graphs->Linked List Representation |
||||||
You can
imagine the possible way of representing a graph using a linked list.
Well, you do not have just one list but a list for every VERTEX. A linked
list of all these individual lists will finally represent the graph. These
individual lists depict the adjacent edges for a particular vertex.
If there would have been an edge from A to B in the graph, in the linked list representation we would have an extra node B after or before D in the down list for A. You can understand from the above representation that there are two types of Lists - one to maintain the adjacency list of every vertex and the other one to maintain the graph. Accordingly, we have two types of List nodes - one which has that red coloured pointer and the other with the black colour pointer. Sorry, to use such a raw language to explain! You will realise the difference after I give you the respective NODE structures. Although there is no formal algorithm for the linked list representation, I am giving an informal one so that you understand its C implementation. Algorithm:- C implementation:-
struct adj_node /*the NODE
which forms the part of the adjacency list; look at figure [B]*/ struct node /*the
NODE which forms the part of the Graph; look at figure [A]*/ LinkListrepresentation() Note:- If you don't want to use aux_ptr, you can always maintain a Adjacency List for the graph and check it for every vertex, to find the respective adjacent edges. Related Operations: |
||||||
| Index || Doubts / Clarifications || Related Topics || Web Links | ||||||