I have a balanced tree with branching factor 2 and height 100, and each edge has a weight given by a text file that looks like:
73 41
52 40 09
26 53 06 34
etc etc until row nr 99
i.e: The edge weight from node 0 to 1 is 73, from 0 to 2 is 41, and from 1 to 3 is 52, etc.
I wish to find the shortest path (with the corresponding edge weight sum) from the root to the end of the tree. As far as I understand, this can be done by multiplying all edge weights by -1 and using the Dijkstra algorithm in Networkx.
- Is the algorithm choice correct?
- How do I “easily” import this data set into a Networkx graph object?
(PS: This is Project Euler Problem 67, finding the maximum sum in a triangle of numbers. I have solved the question with recursion with memoization, but I want to try and solve it with the Networkx package.)
Yes. You can use positive weights, and call nx.dijkstra_predecessor_and_distance to get the shortest paths starting from the root node,
0.