Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Python (Dynamic Programming) Implement Dynamic Programming Algorithm for Independent Set (IS) on a Line Graph This problem is exactly the one discussed in lecture on

Python (Dynamic Programming)

Implement Dynamic Programming Algorithm for Independent Set (IS) on a Line Graph This problem is exactly the one discussed in lecture on 09/25. You are given a graph on n vertices, where the vertices are connected together in a line. Each vertex has a weight. These weights are specified by v_1,v_2, ..., v_n. An independent set (IS) is a subset of the vertices such that no two vertices in the set have an edge between them. The weight of an IS is the sum of the weights of the vertices in the set. The problem is to find a maximum weight IS in the graph. Recall from the recitation that the dynamic programming recurrence for the problem is given as follows: OPT(i) = max( v_i + OPT(i - 2), OPT(i - 1) ) In this problem, your goal is to implement a bottom-up dynamic programming algorithm, based on the above recurrence. Starter code is provided. Input: The input is given in a file called input.txt. It contains a list of white-space delimited integers. This list corresponds to the weights of the problem: v_1, ..., v_n. Output: Your output must contain three lines. The first line should contain a list of white-space delimited integers. These integers should correspond to the values OPT(1), OPT(2), ..., OPT(n), in that order. The second line should contain a single integer, which is the the maximum weight of an IS. The third line should contain a list of white-space delimited integers, sorted in increasing order. This line corresponds to the indices of a maximum weight IS, using a 0-based offset. In the case there is more than one maximum weight IS, you can output an arbitrary one. Example : Input: 8 3 7 10 4 Output: 8 8 15 18 19 19 0 2 4 Explanation: There are 5 vertices, with weights 8, 3, 7, 10, 4. The maximum weight IS is given by choosing element 0 (whose weight is 8), element 2 (whose weight is 7), and element 4 (whose weight is 4). The total weight is 19. Testing: You are responsible for designing your own test cases to make sure your algorithm works. You should manually design test cases to test corner conditions of your program, and you should also use stress testing to test your algorithm. The grader will be using test cases with at least 1000 numbers and with values up to several tends of thousands. Submission and Grading: You may submit as many times prior to the deadline, but only the last submission will be graded. During submission, a very simple test case will be run. If your code does not pass this test case, you will need to fix your code before being able to submit. Grading will be done after the deadline using more exhaustive test cases. Note: If you receive a "Killed" error message, that means your program was taking too long to run and was killed by the server (maybe you had an infinite loop somewhere?)

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_2

Step: 3

blur-text-image_3

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

Database And Transaction Processing

Authors: Philip M. Lewis, Arthur Bernstein, Michael Kifer

1st Edition

0201708728, 978-0201708721

More Books

Students also viewed these Databases questions

Question

2. Enrolling employees in courses and programs.

Answered: 1 week ago

Question

1. Communicating courses and programs to employees.

Answered: 1 week ago

Question

6. Testing equipment that will be used in instruction.

Answered: 1 week ago