views:

31

answers:

1

Where would be the best place to put the edge length in an adjacency list implementation? I using this site as reference. What I am thinking is to put it in the edge node so to find the length from one vertex to another, you go to one of the vertex nodes and find its connecting edges and access the relevant member. (see part 5: "Data types for implementation" on the linked page)

This seems sound to me, but I've looked through many sites and no site confirms that this works. I also remember reading somewhere that it is much easier to implement lengths in adjacent matrices but stopped short of saying whether it possible to implement lengths in adjacency lists at all or just harder.

A: 

The edgeTag is the perfect place for the edge length. And about the graph representation, it depends on your needs - adjacency matrix is ineffective for sparse graphs(to find the adjacent nodes you must check them all), although it is a little bit easier to work with it.

Petar Minchev