Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Question. We are given a complete binary tree where nodes and edges have positive weights. Node weights are stored in a 1-dimensional array WN. Edge

image text in transcribed

Question. We are given a complete binary tree where nodes and edges have positive weights. Node weights are stored in a 1-dimensional array WN. Edge weights are stored in a 2-dimensional array WE where 0 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 = 1 3 4 2 6 1 9 8 8 5 ] Edge weights array: WE = 10 15 0 0 0 6 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 OOOOOOOO ONOOOOOOO OOMOOOOOO OOOOOOOOO OOOOOOOO ] 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

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

how would you have done things differently?

Answered: 1 week ago

Question

3. What information do participants need?

Answered: 1 week ago