We are given a complete binary tree where nodes and edges have positive weights. Node weights...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
We are given a complete binary tree where nodes and edges have positive weights. Node weights are stored in a 2-dimensional array WN. Edge weights are stored in a 2-dimensional array WE where O denotes no edge. Node indices are given form top-to-bottom and left-to-right (e.g. root node index is 1, its left child 2 and so on...). Starting at the root of the tree and moving to either one of the children from the current node, the goal is to find the minimum total weight (i.e. sum of node and edge weights) path from the root to any one of the leaves. Example: Node weights array: WN=[3 4 2 6 1 9 8 851 Edge weights array: WE=[0 15 000 000 0006 20000 00000 9300 0 0 0 0 0 0 0 6 4 000000000 000000000 000000000 000000000 000000000 use java for implementations Output: Min total weight path includes nodes 1-2-5 with total weight 11. 1. Implement the greedy algorithm (i.e., write a function) of choosing the child with smallest sum of edge and node weights each time. 2. Implement a recursive algorithm (i.e., write a function) to find the minimum total weight. You must determine the input parameters. Also, give the time complexity of a recursive algorithm that implements this formulation? Show your work. 3. Implement a dynamic programming algorithm to solve the problem. You must determine the input parameters. Also, give the time complexity of your dynamic programming solution? Show your work. 4. In your main function: a. Show that the greedy algorithm does not solve this problem optimally. b. Run each of the recursive and dynamic functions with three different input sizes and compute the actual running times (in milliseconds or seconds) of these three algorithms. You will need to calculate the time passed before and after making a call to each function. Provide a 2x3 table involving the actual running times. We are given a complete binary tree where nodes and edges have positive weights. Node weights are stored in a 2-dimensional array WN. Edge weights are stored in a 2-dimensional array WE where O denotes no edge. Node indices are given form top-to-bottom and left-to-right (e.g. root node index is 1, its left child 2 and so on...). Starting at the root of the tree and moving to either one of the children from the current node, the goal is to find the minimum total weight (i.e. sum of node and edge weights) path from the root to any one of the leaves. Example: Node weights array: WN=[3 4 2 6 1 9 8 851 Edge weights array: WE=[0 15 000 000 0006 20000 00000 9300 0 0 0 0 0 0 0 6 4 000000000 000000000 000000000 000000000 000000000 use java for implementations Output: Min total weight path includes nodes 1-2-5 with total weight 11. 1. Implement the greedy algorithm (i.e., write a function) of choosing the child with smallest sum of edge and node weights each time. 2. Implement a recursive algorithm (i.e., write a function) to find the minimum total weight. You must determine the input parameters. Also, give the time complexity of a recursive algorithm that implements this formulation? Show your work. 3. Implement a dynamic programming algorithm to solve the problem. You must determine the input parameters. Also, give the time complexity of your dynamic programming solution? Show your work. 4. In your main function: a. Show that the greedy algorithm does not solve this problem optimally. b. Run each of the recursive and dynamic functions with three different input sizes and compute the actual running times (in milliseconds or seconds) of these three algorithms. You will need to calculate the time passed before and after making a call to each function. Provide a 2x3 table involving the actual running times.
Expert Answer:
Answer rating: 100% (QA)
Answer 1 Greedy Algorithm public class GreedyAlgorithm int currentLevel 0 final int maxLevel 3 Socia... View the full answer
Related Book For
Introduction to Algorithms
ISBN: 978-0262033848
3rd edition
Authors: Thomas H. Cormen, Charles E. Leiserson, Ronald L. Rivest
Posted Date:
Students also viewed these programming questions
-
Describe the variables you would include in a simple algorithm that could be used to achieve the objectives of your group's country portfolio including any adjustments or improvements you would like...
-
A scaling algorithm solves a problem by initially considering only the highest-order bit of each relevant input value (such as an edge weight). It then refines the initial solution by looking at the...
-
Consider a production function of Cobb-Douglas form: F(L,K)= LOK, for some a, (0, 1). (a) Plot the isoquant of F. (b) Derive that technical rate of substitution of F. Does Fexhibit diminishing...
-
Investors should expect to be compensated for bearing_____ risk, but they should not expect to be compensated for bearing_____ risk. a. Unsystematic: systematic b. Unsystematic; co-movement c....
-
1. Determine the internal consumption when the production matrix is 2. Show that Suppose that a simplified economy consisting of the three sectors Manufacturing, Energy, and Services has the...
-
Gallagher Company has gathered the information needed to complete its Form 941 for the quarter ended September 30, 2013. Using the information presented below, complete Part 1 of Form 941, reproduced...
-
True or False. Passive isolation systems require external power to function.
-
Consider the following transactions for Judys Sofas: (a) Incurred and paid Web site expenses, $2,900. (b) Incurred manufacturing wages of $15,000, 60% of which was direct labor and 40% of which was...
-
The following operating and cost data occurred during October: October 1, Inventory: 30,000 units Direct materials .......$60,000 Direct labor .......... 7,500 Overhead 15,000 October 31, Inventory:...
-
You are the brand manager for your favorite brand of clothing, food, vehicle, or other consumer product. Write a one-page branding statement summarizing your brand for your company's VP of Marketing....
-
At Stonehenge the Heelstone marks where the Sun rises farthest north during the year. About what day would that be on a modern calendar?
-
Is it fair, just, and moral to experiment with a control group of children who are not given a proper diet in order to test the effect of nutrition on delinquency?
-
Should juveniles who commit felonies such as rape or robbery be treated as adults?
-
Discuss the association between child abuse and delinquency. Give two different explanations for the positive relationship between abuse and antisocial behavior.
-
As sex roles become more homogenous, do you believe female delinquency will become identical to male delinquency in rate and type?
-
How does poverty cause delinquency?
-
A probability mass function for a random variable P(X=x) = f(x) is given below. 1 0.32 X f(x) 0 0.64 2 0.04
-
Use nodal analysis to determine voltages v1, v2, and v3 in the circuit Fig. 3.76. Figure 3.76 4 S 3i, 2 A 4A
-
Let e be a maximum-weight edge on some cycle of connected graph G = (V, E). Prove that there is a minimum spanning tree of G = (V, E {e}) that is also a minimum spanning tree of G. That is, there is...
-
Show that the P relation is a transitive relation on languages. That is, show that if L 1 P L 2 and L 2 P L 3 , then L 1 P L 3 .
-
We can apply the iteration operator ? used in the lg ? function to any monotonically increasing function f (n) over the reals. For a given constant c ? ?, we define the iterated function f * c by...
-
The City of Central Falls has engaged Robert Cohen, CPA to audit the June 30, 1999 financial statements of the City's Water Department under the GAO's Government Auditing Standards. Cohen's report...
-
Wil Stevens is executive vice president of a major automobile manufacturing company. Stevens was recently elected Mayor of Detroit. Prior to assuming office, he calls on you, his independent auditor,...
-
A public accounting firm has been engaged to perform the audit of a local, federally funded Housing Allowance Program. The objective of the program is to increase the housing standards of Agana...
Study smarter with the SolutionInn App