greedy algorithm
the method of greediness proposes that in each step in an algorithm, where we are presented with multiple choices, the choice with the biggest instantaneous gain is picked
using this method we can write algorithm that, while relatively simple, arent usually optimal
_input_: an array
_output_: a subarray (non-consecutive) whose sum is maximal which doesnt contain two consecutive elements
A
of positive numbers_output_: a subarray (non-consecutive) whose sum is maximal which doesnt contain two consecutive elements
the algorithm
picks the biggest number in the input array, adds it to the total sum, and discards the two neighboring elements
but is this algorithm correct?