chapter
    Programming Fundamentals PYQs for GATE DA

    GATE DA Programming Fundamentals: 4 chapters, 9 previous year questions (29% of Programming, Data Structures and Algorithms), 474 practice questions and one s

    A question from this chapter

    Question 1
    2025 PYQ
    Level 3: Exam Standard
    Consider the following Python declarations of two lists.

    A=[1,2,3]
    B=[4,5,6]

    Which one of the following statements results in ?
    Question 2
    2026 PYQ
    Level 3: Exam Standard
    A recursive function in Python is given.

    def mystery(n):
        if n <= 0:
            return 1
        else:
            return mystery(n-1) + mystery(n-2)

    Now, consider the following function call:

    mystery(4)

    Assume that a typical runtime stack is used to manage function calls. Each function call is pushed onto the stack and removed only after it finishes execution.

    Which of the following options denotes the total number of function calls (i.e., the total number of stack activations), including the initial call, to compute mystery(4)?
    Question 3
    2026 PYQ
    Level 3: Exam Standard
    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 4
    2026 PYQ
    Level 3: Exam Standard
    Consider the given Python program.

    def outer():
        x = []
        def inner(val):
            x.append(val)
            return x
        return inner

    f1 = outer()
    f2 = outer()
    print(f1(10)) # Line P
    print(f1(20)) # Line Q
    print(f2(30)) # Line R
    print(f1(40)) # Line S

    Which of the following options is/are correct?
    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.

    Programming Fundamentals PYQs for GATE DA

    GATE DA Programming Fundamentals: 4 chapters, 9 previous year questions (29% of Programming, Data Structures and Algorithms), 474 practice questions and one solved question from each chapter.

    About Programming Fundamentals Previous Year Questions (PYQs)

    9 previous year questions from Programming Fundamentals in GATE DA, grouped by chapter with the exam year, answer key and step-by-step solution for each.

    Programming Fundamentals Weightage in GATE DA

    Programming Fundamentals accounts for 9 of 31 Programming, Data Structures and Algorithms previous year questions in our bank (29%), about 3 per paper across 3 papers.

    Programming Fundamentals Chapter Matrix

    ChapterTopicsPYQsShare of unit PYQsPractice questions
    Python Data Structures: Lists, Sets and DictionariesPython List Operations and In-Place Updates, Python Set Operations and Membership Tracing222%112
    Python Functions and RecursionRecursive Function Tracing and Return Values333%155
    List Processing and In-Place MutationRecursive List Processing and In-Place Mutation222%103
    Function Scope, Closures and Default ArgumentsMutable Default Arguments, Closures and Enclosed State222%104

    More from Programming, Data Structures and Algorithms

    One Solved Question from Each Programming Fundamentals Chapter

    Question 1 · Python Data Structures: Lists, Sets and Dictionaries · 2025 MCQ
    Consider the following Python declarations of two lists.

    A=[1,2,3]
    B=[4,5,6]

    Which one of the following statements results in ?
    1. A.

      A.extend(B)

    2. B.

      A.append(B)

    3. C.

      A.update(B)

    4. D.

      A.insert(B)

    Correct Answer:

    A

    Step-by-Step Solution

    Insight: The question tests the difference between adding an iterable as a single nested object versus flattening its elements into the existing list.

    Exam route: Eliminate options that use non-existent list methods or wrong argument counts. Between the remaining two, recall that extend flattens while append nests.

    Learning route:

    1. A.extend(B): The extend method iterates over the argument B and adds each element (4, 5, 6) one by one to A. The final list is [1, 2, 3, 4, 5, 6]. This matches the requirement.
    2. A.append(B): The append method adds the entire object B as a single element at the end of A. The final list becomes [1, 2, 3, [4, 5, 6]]. This does not match.
    3. A.update(B): The update method is not defined for Python lists (it is used for sets and dictionaries). Calling this raises an AttributeError.
    4. A.insert(B): The insert method requires exactly two arguments: an index and an element. Providing only one argument raises a TypeError.

    Therefore, A.extend(B) is the only statement that produces the desired flat list.

    Question 2 · Python Functions and Recursion · 2026 MCQ
    A recursive function in Python is given.

    def mystery(n):
        if n <= 0:
            return 1
        else:
            return mystery(n-1) + mystery(n-2)

    Now, consider the following function call:

    mystery(4)

    Assume that a typical runtime stack is used to manage function calls. Each function call is pushed onto the stack and removed only after it finishes execution.

    Which of the following options denotes the total number of function calls (i.e., the total number of stack activations), including the initial call, to compute mystery(4)?
    1. A.

      5

    2. B.

      9

    3. C.

      15

    4. D.

      17

    Correct Answer:

    C

    Step-by-Step Solution

    Insight: The total number of function calls follows a recurrence relation , where the accounts for the current function call itself.

    Exam route: Compute iteratively from base cases. . Then , , , .

    Learning route: Draw the recursion tree for mystery(4). The root is 1 call. It branches to mystery(3) and mystery(2). Count all nodes in this call tree. Total nodes = 15. Note that mystery(0) and mystery(-1) are base cases that make 1 call each and return immediately without further branching.

    Question 3 · List Processing and In-Place Mutation · 2026 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)
    Correct Answer:

    8.00

    Step-by-Step Solution

    Insight: The inner function fun performs one left-to-right pass of adjacent swaps, returning the number of swaps. The outer loop calls it n times, which is exactly the Bubble Sort algorithm. The total number of swaps in Bubble Sort equals the number of inversions in the initial array.

    Exam route: Count the inversions in [5, 3, 4, 1, 2]. 5 is greater than 3, 4, 1, 2 (4 inversions). 3 is greater than 1, 2 (2 inversions). 4 is greater than 1, 2 (2 inversions). Total = 4 + 2 + 2 = 8.

    Learning route:

    Pass 1: [5, 3, 4, 1, 2] -> 5 bubbles to the end. Swaps: (5,3), (5,4), (5,1), (5,2). Count = 4. Array: [3, 4, 1, 2, 5].

    Pass 2: [3, 4, 1, 2, 5] -> 4 bubbles to index 3. Swaps: (4,1), (4,2). Count = 2. Array: [3, 1, 2, 4, 5].

    Pass 3: [3, 1, 2, 4, 5] -> 3 bubbles to index 2. Swaps: (3,1), (3,2). Count = 2. Array: [1, 2, 3, 4, 5].

    Pass 4 & 5: Already sorted, 0 swaps.

    Total count = 4 + 2 + 2 + 0 + 0 = 8.

    Question 4 · Function Scope, Closures and Default Arguments · 2026 MSQ
    Consider the given Python program.

    def outer():
        x = []
        def inner(val):
            x.append(val)
            return x
        return inner

    f1 = outer()
    f2 = outer()
    print(f1(10)) # Line P
    print(f1(20)) # Line Q
    print(f2(30)) # Line R
    print(f1(40)) # Line S

    Which of the following options is/are correct?
    1. A.

      f1 and f2 share the same list x

    2. B.

      Output of Line Q is [10, 20]

    3. C.

      Output of Line R is [10, 20, 30]

    4. D.

      Output of Line S is [10, 20, 40]

    Correct Answer:

    ["B","D"]

    Step-by-Step Solution

    Insight: Each call to the outer function creates a completely independent closure with its own isolated cell objects for enclosed variables.

    Exam route: f1 and f2 are created by separate calls to outer(), so they have separate x lists. f1(10) -> [10], f1(20) -> [10, 20] (Line Q). f2(30) -> [30] (Line R). f1(40) -> [10, 20, 40] (Line S).

    Learning route: This is a closure instance isolation question, recognizable by the nested function returning an inner function that modifies an enclosed mutable variable.

    Step 1: When f1 = outer() is executed, a new list x is created in outer's local scope. The inner function captures this specific list in its closure cell. f1 now points to this specific inner function instance.

    Step 2: When f2 = outer() is executed, a completely new list x is created. A new inner function instance is created, capturing this new list. f2 points to this second instance. f1 and f2 do not share any state.

    Step 3: Line P: f1(10) appends 10 to f1's list. Returns [10].

    Step 4: Line Q: f1(20) appends 20 to f1's list. Returns [10, 20]. Option B is correct.

    Step 5: Line R: f2(30) appends 30 to f2's list. Since f2's list is independent and starts empty, it returns [30]. Option C is incorrect.

    Step 6: Line S: f1(40) appends 40 to f1's list. Returns [10, 20, 40]. Option D is correct.

    Answer: Options B and D.