0

I have a graph that can be composed of 2 types of algorithms: Cluster and Normal.

I need a way to find out wish type of node is my normal node based on its nearest node of type cluster:

enter image description here

  • So for example in pic above, I want to know what type is Node (A) bases on its nearest node of type cluster.
  • As you can see normal node A has a distance of 1 edge/link to node Cluster 1.
  • Also, node A**strong text** has distance of 2 edges/links to node Cluster 2.
  • Since distance to Cluster 1 is less than distance to Cluster 2. Node (a) is Type 1.
  • if distance to Cluster 2 was shorter than distance to Cluster 1 then it would be type 2.

I'm using javascript + d3 for this graph.

I searched on the internet and found that Djikastra's algorithm might be what I need but Djikastras need an initial node and a goal node.

My problem is:

That all of my Cluster type nodes are my goals and I need to find for each normal type node which type it would be based on its nearest cluster.

Is Djikstra's the best algorithm for this? I'm not sure if in a fairly complex graph with hundreds of nodes that algorithm will perform efficiently.

This is more or less how my nodes and links look:

Node A = {
   name: A,
   type: normal,
   id: node_1
}

Node Cluster 1 = {
   name: Cluster 1,
   type: cluster,
   id: node_2
}

Edge or link = {
   from= node_1,
   to= node_2
}

1 Answer 1

1

The best algorithm for this problem would be a breadth-first search. You can stop the search as soon as you identify a node that is of type cluster.

1
  • thanks it took me a long time to complete but it really was this the algorithm to do Commented Jan 20, 2017 at 2:49

Not the answer you're looking for? Browse other questions tagged or ask your own question.