chapter
    Dynamic Programming and Sequence Processing PYQs for GATE DA

    Solve 1+ Dynamic Programming and Sequence Processing previous year questions for GATE DA with answers and detailed solutions. Free sample questions below.

    Try a question

    Answer it here to see how it works. Nothing is recorded until you sign in.

    Question 1
    2024 PYQ
    Level 3: Exam Standard
    Consider the function computeS(X) whose pseudocode is given below:

    computeS(X)

    for to

    if

    end if
    end for
    return S

    Which ONE of the following values is returned by the function computeS(X)
    for X = [6, 3, 5, 4, 10]?
    Free preview ends here

    Login to view the complete previous-year questions and solutions

    Creating an account is free. You get the rest of this chapter, step-by-step solutions, and a study plan built around the topics you are actually weak at.

    Why MastersUp

    Personalised first. High quality throughout.

    Most platforms hand everyone the same content. Here the content moves with your performance, topic by topic.

    Built around you, not around a syllabus PDF

    Every answer you give moves your topic-level intelligence rate. The next question, the next revision card and tomorrow's plan all change with it.

    Revision that hits your weak spots

    We only revise topics you have actually attempted and are still below the safe bar on — never the same chapter on repeat.

    Questions calibrated to the real exam

    Each question carries a measured toughness. You are served a rung above your current level, so practice keeps stretching you.

    Notes written for recall, not for volume

    Full lesson cards for first study, curated short-note cards for the last mile — with derivations, traps and exam patterns marked.

    One place for everything

    Notes, chapter practice, previous-year questions, test series and full-length papers — all feeding one picture of your preparation.

    Honest progress

    No vanity streaks. Progress here means chapters mastered and accuracy that held up on harder questions.

    Unlock the whole course

    Full notes and short notes, the complete question bank with worked solutions, mock tests, full-length papers, and an adaptive plan that rebuilds itself as you improve.

    Dynamic Programming and Sequence Processing PYQs for GATE DA

    Solve 1+ Dynamic Programming and Sequence Processing previous year questions for GATE DA with answers and detailed solutions. Free sample questions below.

    Chapter Roadmap: Dynamic Programming and Sequence Processing

    Chapter Roadmap

    Your journey to mastering sequence-based dynamic programming.

    1. Consecutive Sequence Lengths

    Finding the longest contiguous subarray satisfying a condition.

    2. Subsequence Lengths

    Tackling non-contiguous sequences like LIS and LCS.

    3. Advanced Variations

    Matrix chain multiplication, edit distance, and complex states.

    What you will master

    • Defining precise DP states for sequence problems.
    • Formulating correct recurrence relations.
    • Optimizing space complexity from to .
    • Avoiding common traps in boundary conditions.

    Topic Hero: Dynamic Programming for Consecutive Sequence Lengths

    Topic Hero: Consecutive Sequence Lengths

    Focuses on finding the longest contiguous segment that satisfies a specific condition.

    Extend

    If condition met with previous element, add to previous segment.

    Reset

    If condition broken, start a new segment of length .

    This local decision builds a global solution in time.

    Dynamic Programming and Sequence Processing: Solved Questions with Step-by-Step Explanations (1 Problems)

    Question 1 · Programming, Data Structures and Algorithms · 2024 MCQ
    Consider the function computeS(X) whose pseudocode is given below:

    computeS(X)

    for to

    if

    end if
    end for
    return S

    Which ONE of the following values is returned by the function computeS(X)
    for X = [6, 3, 5, 4, 10]?
    1. A.

      [1, 1, 2, 3, 4]

    2. B.

      [1, 1, 2, 3, 3]

    3. C.

      [1, 1, 2, 1, 2]

    4. D.

      [1, 1, 2, 1, 5]

    Correct Answer:

    C

    Step-by-Step Solution

    Insight: This is a consecutive sequence DP question where S[i] represents the length of the longest non-decreasing contiguous subarray ending at index i. The pseudocode implements the standard "extend or reset" pattern.

    Exam route: Trace the pseudocode step by step for the given array X = [6, 3, 5, 4, 10].

    Learning route:

    • i=1: S[1] = 1 (base case, single element is always valid).
    • i=2: X[1]=6, X[2]=3. Check 6 <= 3: false. So S[2] remains 1 (reset).
    • i=3: X[2]=3, X[3]=5. Check 3 <= 5: true. So S[3] = 1 + S[2] = 1 + 1 = 2 (extend).
    • i=4: X[3]=5, X[4]=4. Check 5 <= 4: false. So S[4] remains 1 (reset).
    • i=5: X[4]=4, X[5]=10. Check 4 <= 10: true. So S[5] = 1 + S[4] = 1 + 1 = 2 (extend).

    Final array: S = [1, 1, 2, 1, 2].

    Verification: The longest non-decreasing contiguous subarrays ending at each index are: [6] (length 1), [3] (length 1), [3, 5] (length 2), [4] (length 1), [4, 10] (length 2). This matches S = [1, 1, 2, 1, 2].

    More previous year questions (pyqs) in this unit