Suggestions of the easiest algorithms for some Graph operations
Posted
by Nazgulled
on Stack Overflow
See other posts from Stack Overflow
or by Nazgulled
Published on 2010-04-15T16:44:01Z
Indexed on
2010/04/15
17:13 UTC
Read the original article
Hit count: 314
Hi,
The deadline for this project is closing in very quickly and I don't have much time to deal with what it's left. So, instead of looking for the best (and probably more complicated/time consuming) algorithms, I'm looking for the easiest algorithms to implement a few operations on a Graph structure.
The operations I'll need to do is as follows:
- List all users in the graph network given a distance X
- List all users in the graph network given a distance X and the type of relation
- Calculate the shortest path between 2 users on the graph network given a type of relation
- Calculate the maximum distance between 2 users on the graph network
- Calculate the most distant connected users on the graph network
A few notes about my Graph implementation:
- The edge node has 2 properties, one is of type
char
and anotherint
. They represent the type of relation and weight, respectively. - The Graph is implemented with linked lists, for both the vertices and edges. I mean, each vertex points to the next one and each vertex also points to the head of a different linked list, the edges for that specific vertex.
What I know about what I need to do:
- I don't know if this is the easiest as I said above, but for the shortest path between 2 users, I believe the Dijkstra algorithm is what people seem to recommend pretty often so I think I'm going with that.
- I've been searching and searching and I'm finding it hard to implement this algorithm, does anyone know of any tutorial or something easy to understand so I can implement this algorithm myself? If possible, with C source code examples, it would help a lot. I see many examples with math notations but that just confuses me even more.
- Do you think it would help if I "converted" the graph to an adjacency matrix to represent the links weight and relation type? Would it be easier to perform the algorithm on that instead of the linked lists? I could easily implement a function to do that conversion when needed. I'm saying this because I got the feeling it would be easier after reading a couple of pages about the subject, but I could be wrong.
- I don't have any ideas about the other 4 operations, suggestions?
© Stack Overflow or respective owner