Slide 38
Slide 38 text
Maximum Sum
Given an array of numbers, how
would you compute which subset of
numbers has the maximum sum if
no two elements in the subset can
be adjacent in the original array?
Ex: [6, 4, 5, 7, 1, 12, 3, 2]
=> 27
So let’s move on to a more interesting example. How would you find the maximum sum returned by a subset of that array, if none of the elements in the
subset can be adjacent? So for example, in the case of the array [6, 4, 5, 7, 1, 12, 3, 2], the possible subsets would be [6, 5, 1], [6, 7, 12], [4, 7, 12], [4, 7, 3] ,
[4, 1, 3] and so on. The sub-array whose elements reduces to the maximum possible sum is [6,7,12, 2], with a sum of 27. So, does anyone have any ideas as
to how you’d approach this problem?