Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8887265
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T21:45:50+00:00 2026-06-14T21:45:50+00:00

I have a balanced tree with branching factor 2 and height 100, and each

  • 0

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.

  1. Is the algorithm choice correct?
  2. 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.)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T21:45:51+00:00Added an answer on June 14, 2026 at 9:45 pm

    Is the algorithm choice correct?

    Yes. You can use positive weights, and call nx.dijkstra_predecessor_and_distance to get the shortest paths starting from the root node, 0.


    How do I “easily” import this data set into a Networkx graph object?

    import networkx as nx
    import matplotlib.pyplot as plt
    
    def flatline(iterable):
        for line in iterable:
            for val in line.split():
                yield float(val)
    
    with open(filename, 'r') as f:
        G = nx.balanced_tree(r = 2, h = 100, create_using = nx.DiGraph())
        for (a, b), val in zip(G.edges(), flatline(f)):
            G[a][b]['weight'] = val
    
    # print(G.edges(data = True))
    
    pred, distance = nx.dijkstra_predecessor_and_distance(G, 0)
    
    # Find leaf whose distance from `0` is smallest
    min_dist, leaf = min((distance[node], node) 
                         for node, degree in G.out_degree_iter()
                         if degree == 0)
    nx.draw(G)
    plt.show()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Suppose I have a balanced BST (binary search tree). Each tree node contains a
I have a large tree that grows as my algorithm progresses. Each node contains
I have two load balanced servers each running exactly the same copy of various
I have a bunch of EC2 servers that are load balanced. Some of the
I have an application that is load balanced across two web servers (soon to
I have a tasks to build binary tree as follow: Build ideal balanced tree.
I have a possibly large rooted tree structure that I want to transform into
I have implemented an iterative algorithm, where each iteration involves a pre-order tree traversal
We have a website load balanced across two servers that calls into a WCF
We have a website that runs on two load balanced servers. We used the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.