I have to use a graph traversal ( i was thinking of BST) to determine how many vertex in g are in a distance of v in less or equal to N , this is , a travel wich the distance is N ou less edges.
int succN (Grafo g, int v, int N)
I have this struct to work with :
#define MAX 100
typedef int WEIGHT;
struct edge {
int dest;
WEIGHT weight;
struct edge *next;
};
typedef struct edge Edge;
typedef struct edge *GraphL[MAX];
I'm having a difficult time to make a efficient solution in c. The only way i'm seeing right now its to make a recursive call in an aux function with the BST
If your weights are nonnegative, you can use Dijkstra algorithm Here is a simple pseudo-code. It has a
O(n^2)
time complexity (n
= number of nodes).If all your weights are equal to 1 (as you are pointing out in comments), then a breadth-first search will be enough.