GATEverse
← GATE CSE 1990

Q12b

NATMarks unknown

Consider the following problem. Given nn positive integers a1,a2…an,a_{1}, a_{2}\dots a_n, it is required to partition them in to two parts AA and BB such that, ∣∑i∈Aai−∑i∈Bai∣\displaystyle{}\left|\sum_{i \in A} a_{i} - \sum_{i \in B} a_{i}\right| is minimised Consider a greedy algorithm for solving this problem. The numbers are ordered so that a1≥a2≥…an,a_{1} \geq a_{2} \geq \dots a_{n}, and at ithi^{th} step, aia_i is placed in that part whose sum in smaller at that step. Give an example with n=5n=5 for which the solution produced by the greedy algorithm is not optimal.

Sign in to save attempts.

Loading…