Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Python3 question! Please use python programming language for each question. Thanks One Question. We are given a complete binary tree where nodes and edges have

Python3 question! Please use python programming language for each question. Thanks

image text in transcribed

One 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 (.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 8 5 ] Edge weights array: WE = [O 1 SOOOOOO OOOOOOO 64 o o o o o o o o o OOOOOOOOO 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

Visual Basic 4 Ole Database And Controls Superbible

Authors: Michael Hatmaker, C. Woody Butler, Ibrahim Malluf, Bill Potter

1st Edition

1571690077, 978-1571690074

More Books

Students also viewed these Databases questions

Question

Identify and use the five steps for conducting research.

Answered: 1 week ago

Question

4. Does cultural aptitude impact ones emotional intelligence?

Answered: 1 week ago

Question

7. Do the organizations social activities reflect diversity?

Answered: 1 week ago