Question: Tesla organizes their distribution system as a non - binary tree. The root of such tree is the source distributor, and every node in the
Tesla organizes their distribution system as a nonbinary tree. The root of such tree is the source distributor, and every node in the tree represents another Tesla distributor that receives cars from the parent node and sends them to its children's nodes. The leaves of the tree are the final dealers that sell cars to customers. Further, every node holds an integer representing the cost associated of shipping a car to it
Tesla would like to compute the minimum cost in its distribution tree. Given a rootNode, write a program getMinimumCost that computes the minimum route's cost in the tree. For example, given the root node of the tree above, your program should return since it is the minimal route we have two minimal cost paths:
Use the following code to build the nodes of the tree.
# A node
class Node:
# Constructor to create a new node
definitself cost:
self.cost cost
self.children
self.parent None
Given the root of a binary tree, using DFS return the tree's nodes as if you were doing the following:
get all the leaf nodes
remove all leaf nodes
repeat previous two steps until the tree is empty.
Example:
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
