List Processing and In-Place Mutation Previous Year Questions (PYQs) for GATE DA: 2+ Solved Questions with Step-by-Step Solutions

    Solve 2+ List Processing and In-Place Mutation previous year questions for GATE DA with answers and detailed solutions. Free sample questions below.

    Chapter Roadmap: List Processing and In-Place Mutation

    Chapter Roadmap

    Chapter journey

    1. Recursive List Processing and In-Place Mutation
      Current topic. High-importance tracing.
      • Single-index recursive scans
      • Adjacent-swap counting
      • Two-pointer reversal
    2. Chapter mastery
      • Track exact list state after every swap
      • Decide if call is scan or reversal
      • Predict final return value and list
    Weight hint: Core tracing topic. Small code pieces can carry good marks through careful step-by-step execution.

    Topic Hero: Recursion Meets Mutable Lists

    Topic Hero: Recursion Meets Mutable Lists

    A Python list is mutable. If a recursive function changes the list, the changed list is visible to all deeper recursive calls.

    Two core shapes appear repeatedly:

    Shape Indices used Typical operation
    Single-index scan i Compare and possibly swap L[i] and L[i+1]
    Two-pointer reversal s1, s2 Swap D[s1] and D[s2], then move inward
    Key idea: The list is shared, but the index variables are local to each recursive call.

    List Processing and In-Place Mutation: Solved Questions with Step-by-Step Explanations (2 Problems)

    Question 1 · Programming, Data Structures and Algorithms NAT
    Consider the given Python program.

    def fun(L, i=0):
        if i >= len(L)-1:
            return 0
        if L[i] > L[i+1]:
            L[i+1], L[i] = L[i], L[i+1]
            return 1+fun(L, i+1)
        else:
            return fun(L, i+1)

    data = [5, 3, 4, 1, 2]
    count = 0
    for _ in range(len(data)):
        count += fun(data)
    print(count)

    The output of the program is __________ . (Answer in integer)
    Question 2 · Programming, Data Structures and Algorithms MCQ
    Consider the following Python function:
    def fun(D, s1, s2):
    if s1 < s2:
    D[s1], D[s2] = D[s2], D[s1]
    fun(D, s1+1, s2-1)
    What does this Python function fun() do? Select the ONE appropriate option
    below.
    1. A.

      It finds the smallest element in D from index s1 to s2, both inclusive.

    2. B.

      It performs a merge sort in-place on this list D between indices s1 and s2, both inclusive.

    3. C.

      It reverses the list D between indices s1 and s2, both inclusive.

    4. D.

      It swaps the elements in D at indices s1 and s2, and leaves the remaining elements unchanged.

    More previous year questions (pyqs) in this unit

    chapter
    List Processing and In-Place Mutation Previous Year Questions (PYQs) for GATE DA: 2+ Solved Questions with Step-by-Step Solutions

    Solve 2+ List Processing and In-Place Mutation previous year questions for GATE DA with answers and detailed solutions. Free sample questions below.

    A question from this chapter

    Question 1
    Consider the given Python program.

    def fun(L, i=0):
        if i >= len(L)-1:
            return 0
        if L[i] > L[i+1]:
            L[i+1], L[i] = L[i], L[i+1]
            return 1+fun(L, i+1)
        else:
            return fun(L, i+1)

    data = [5, 3, 4, 1, 2]
    count = 0
    for _ in range(len(data)):
        count += fun(data)
    print(count)

    The output of the program is __________ . (Answer in integer)
    Question 2
    Consider the following Python function:
    def fun(D, s1, s2):
    if s1 < s2:
    D[s1], D[s2] = D[s2], D[s1]
    fun(D, s1+1, s2-1)
    What does this Python function fun() do? Select the ONE appropriate option
    below.
    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.