Implement a Dynamic Programming algorithm that finds a maximum weight independent set for a given tree in O(n)time.
You are given a tree T with n nodes. Each node has a non-negative weight assigned to it. Our goal is to
find a set S of nodes such that (i)no two nodes in S are adjacent, and (ii)the total weight of all vertices
in S is maximal. Such a set is called maximum weight independent set.
Assignment
Implement a Dynamic Programming algorithm that finds a maximum weight independent set for a given
tree in O(n)time. If there are multiple such sets, return a set with maximum number of nodes.
Implementation
You are given a file Lab5.java and a file Tree.java. The file Lab5.java contains a class Lab5 with the function problem. Implement your solutions in that function. You can add
private helper functions or classes directly above or below if it improves your runtime or code quality. Do
not output anything to the terminal.
The file Tree.java contains a class Tree which represents an undirected tree and stores it as adjacency list
(in the array edges). It also contains the functions dfs and bfs. Feel free to use them.
after the implementation run the file and if the implementation is correct you will get a prompt that the tests were successfully passed if not it will fail the tests. Please don’t change any of the code below the function problem().
