GateAI
Divide and Conquer

GATE CSE 2019 · Q25

NAT1 markMedium

Time

Consider a sequence of 14 elements: A=[−5,−10,6,3,−1,−2,13,4,−9,−1,4,12,−3,0]A = [-5, -10, 6, 3, -1, -2, 13, 4, -9, -1, 4, 12, -3, 0]. The subsequence sum S(i,j)=∑k=ijA[k]S(i,j) = \sum_{k=i}^j A[k] . Determine the maximum of S(i,j)S(i,j), where 0≤i≤j<140 \le i \le j < 14. (Divide and conquer approach may be used.) Answer: _______.

Your answerNumerical answer

Enter a value to check

Solution

Step-by-step verified solution

Official answer: 29 (±0)

Divide and Conquer

We need to find the maximum subarray sum of the array:

A=[−5,−10,6,3,−1,−2,13,4,−9,−1,4,12,−3,0]A = [-5, -10, 6, 3, -1, -2, 13, 4, -9, -1, 4, 12, -3, 0]

Using Kadane's algorithm (or the Divide-and-Conquer maximum subarray sum approach):

  1. At index 00 (A[0]=−5A[0] = -5): current_max=−5\text{current\_max} = -5, global_max=−5\text{global\_max} = -5

  2. At index 11 (A[1]=−10A[1] = -10): current_max=−10\text{current\_max} = -10, global_max=−5\text{global\_max} = -5

  3. At index 22 (A[2]=6A[2] = 6): current_max=6\text{current\_max} = 6, global_max=6\text{global\_max} = 6

  4. At index 33 (A[3]=3A[3] = 3): current_max=9\text{current\_max} = 9, global_max=9\text{global\_max} = 9

  5. At index 44 (A[4]=−1A[4] = -1): current_max=8\text{current\_max} = 8, global_max=9\text{global\_max} = 9

  6. At index 55 (A[5]=−2A[5] = -2): current_max=6\text{current\_max} = 6, global_max=9\text{global\_max} = 9

  7. At index 66 (A[6]=13A[6] = 13): current_max=19\text{current\_max} = 19, global_max=19\text{global\_max} = 19

  8. At index 77 (A[7]=4A[7] = 4): current_max=23\text{current\_max} = 23, global_max=23\text{global\_max} = 23

  9. At index 88 (A[8]=−9A[8] = -9): current_max=14\text{current\_max} = 14, global_max=23\text{global\_max} = 23

  10. At index 99 (A[9]=−1A[9] = -1): current_max=13\text{current\_max} = 13, global_max=23\text{global\_max} = 23

  11. At index 1010 (A[10]=4A[10] = 4): current_max=17\text{current\_max} = 17, global_max=23\text{global\_max} = 23

  12. At index 1111 (A[11]=12A[11] = 12): current_max=29\text{current\_max} = 29, global_max=29\text{global\_max} = 29

  13. At index 1212 (A[12]=−3A[12] = -3): current_max=26\text{current\_max} = 26, global_max=29\text{global\_max} = 29

  14. At index 1313 (A[13]=0A[13] = 0): current_max=26\text{current\_max} = 26, global_max=29\text{global\_max} = 29

The contiguous subarray giving this maximum is from index i=2i = 2 to j=11j = 11:

[6,3,−1,−2,13,4,−9,−1,4,12][6, 3, -1, -2, 13, 4, -9, -1, 4, 12]
Sum=6+3−1−2+13+4−9−1+4+12=29\text{Sum} = 6 + 3 - 1 - 2 + 13 + 4 - 9 - 1 + 4 + 12 = 29

Try the question first, then check your work.

Think the official key or this write-up is wrong?

Report error or challenge

Examiner trap

The misconception this question tests

This Divide and Conquer previous year question is Q25 of the GATE CSE 2019 paper. Find more GATE CSE PYQs on Divide and Conquer in Algorithms, or browse all GATE CSE PYQs.

Free diagnostic

Where do you stand for GATE?

Take the 20-minute diagnostic: the 3 topics that cost you the most marks, and a rank range. Or sit 1 related Divide and Conquer PYQs now with no account.

One GATE CSE PYQ every morning

An official question by email at 7 AM IST, with a link to its verified solution. Unsubscribe in one click.

Divide and Conquer in GATE CSE

GATE CSE 2019 Q25 is the only Divide and Conquer question in the GATE CSE papers so far.

How GATE tests Divide and Conquer

More from GATE CSE 2019

Share this solution

A plain-text card for WhatsApp or Telegram study groups.

GateAI solution cardGATE CSE 2019 · Q25 · NAT

Consider a sequence of 14 elements: A = [-5, -10, 6, 3, -1, -2, 13, 4, -9, -1, 4, 12, -3, 0]. The subsequence sum S(i,j) = Σk=ij A[k] . Determine the maximum of S(i,j), where 0 ≤ i ≤ j < 14. (Divide and conquer approach may be used.) Answer: …

Topic-wise GATE CS PYQs with verified steps

Independent practice explanation verified by the GateAI team. GATE is conducted by the IITs; question text follows the official paper.