w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
How can the shortest path between two nodes in a balanced binary tree be affected by path 'weight'?

Ok, so I think my initial reaction and the obvious answer is correct:

Positive weights cannot affect the shortest path between two nodes in a binary tree.

On the other hand, weights obviously do affect the shortest 'distance' between two nodes in a binary tree as compared to simply calculating 'distance' between nodes as the number of hops.

This is what the udacity instruction was getting at. It seems that this instruction to work with weighted binary trees was simply to enable correct automatic grading of the code which relied on using the labels to calculate the exact shortest 'distance' (which is affected by weight) as opposed to the shortest path (list of nodes) which is not.

Once I modified my algorithm to take this into account and output the correct distance, it passed the grader.

© Copyright 2018 w3hello.com Publishing Limited. All rights reserved.