I'm trying to figure out how I can calculate the shortest path within many nodes to a root node, but i have no clue how to do it the right way. The Nodes are somehow connected to each other, so there are always multiple paths to the root node.
I have a js object with all nodes, here is a snippet if it:
var nodes = {
11420 : { // no out, but many other nodes have 11420 in their out
out : []
},
18866 : {
out : [11420]
},
739 : {
out : [18866]
},
1957 : {
out : [739]
},
33296 : {
out : [1957, 36774]
},
57264 : {
out : [33296]
},
54447 : { // root
out : [57264]
},
37569 : {
out : [36542, 57264]
}
// ... 1500 nodes more
}
How can I calculate the shortest Path for lets say Node 11420 to root 54447? The result should be an array with the node ids.
Thank you.