Question: In this problem, you will be considering a binary tree with a score assigned to each node. Given a subset of the tree nodes,
In this problem, you will be considering a binary tree with a score assigned to each node. Given a subset of the tree nodes, the score of that subset is the sum of the score of the nodes in the subset that do not also have a parent inside the subset. For example, in the tree below, the highlighted nodes have a score of 8+1=9 because the nodes 8 and 1 do not have parents in the subset, whereas -5 and 2 do not count because their parents are selected. 8 -9 -6 1 2 -5 -1 Design and analyze an efficient algorithm that, given a tree T, the scores at each node, and a number k, finds maximum score of any subset of size k.
Step by Step Solution
3.37 Rating (147 Votes )
There are 3 Steps involved in it
Aim is to find a subset of size k with the maximum sum but subject to a condition that a node value is to be counted only if its parent is not include... View full answer
Get step-by-step solutions from verified subject matter experts
