chapter
    Programming Fundamentals Practice Questions 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
    Level 3: Exam Standard

    Consider the following Python code snippet.

    a = [1, 2, 3]

    b = a

    c = a[:]

    a += [4]

    a = a + [5]

    b.append(6)

    What is the final value of c?

    Question 2
    Level 3: Exam Standard

    Consider the following Python function:

    ```python

    def f(n):

    if n <= 1:

    return n + 1

    return (f(n - 1) + f(n - 2)) % 10

    ```

    What is the maximum value returned by for in the range ?

    Question 3
    Level 3: Exam Standard

    Consider the following Python function:

    ```python

    def process(L, i=0):

    if i >= len(L) - 1:

    return 0

    count = 0

    if L[i] > L[i+1]:

    L[i], L[i+1] = L[i+1], L[i]

    count = 1

    return count + process(L, i+1)

    ```

    The function is called as process([4, 3, 2, 5, 1]). Consider the following statements about this call:

    I. The function returns .

    II. After the call completes, L[4] equals .

    III. After the call completes, the list L is sorted in non-decreasing order.

    Which of the above statements is/are correct?

    Question 4
    Level 3: Exam Standard

    Match the Python functions in List I with the length of their default argument's state after executing the calls f(2), f(4), f(6), f(8) in List II.

    <b>List I</b>

    P) def f(x, lst=[]):

    if len(lst) < 3: lst.append(x)

    return lst

    Q) def f(x, lst=[0]):

    if lst[0] < 10: lst[0] += x

    return lst

    R) def f(x, lst=[]):

    if x > 0: lst.append(x)

    else: lst = [x]

    return lst

    S) def f(x, lst=[]):

    lst.append(x)

    if len(lst) > 2: lst.pop(0)

    return lst

    <b>List II</b>

    1. 1
    2. 2
    3. 3
    4. 4
    Free preview ends here

    Login to view the complete practice 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 Practice Questions 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 Practice Questions

    474 practice questions for Programming Fundamentals in GATE DA, sorted chapter by chapter and graded from basic to exam level, each with a full solution.

    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 MCQ

    Consider the following Python code snippet.

    a = [1, 2, 3]

    b = a

    c = a[:]

    a += [4]

    a = a + [5]

    b.append(6)

    What is the final value of c?

    1. A.

      [1, 2, 3]

    2. B.

      [1, 2, 3, 4]

    3. C.

      [1, 2, 3, 4, 6]

    4. D.

      [1, 2, 3, 6]

    Correct Answer:

    A

    Step-by-Step Solution

    Key idea: This is a list aliasing and mutation question. The key is tracking which operations mutate the existing list versus creating a new one, and understanding that slicing creates a shallow copy.

    Step 1: Initial state

    • a = [1, 2, 3]
    • b = a (b points to the same list as a)
    • c = a[:] (c is a separate copy: [1, 2, 3])

    Step 2: a += [4]

    • The += operator mutates the list in place
    • Both a and b now point to [1, 2, 3, 4]
    • c remains [1, 2, 3]

    Step 3: a = a + [5]

    • The + operator creates a new list and rebinds a
    • a now points to [1, 2, 3, 4, 5]
    • b still points to [1, 2, 3, 4]
    • c remains [1, 2, 3]

    Step 4: b.append(6)

    • This mutates the list that b points to
    • b becomes [1, 2, 3, 4, 6]
    • a remains [1, 2, 3, 4, 5]
    • c remains [1, 2, 3]

    Final value of c: [1, 2, 3]

    Answer: A

    Question 2 · Python Functions and Recursion MCQ

    Consider the following Python function:

    ```python

    def f(n):

    if n <= 1:

    return n + 1

    return (f(n - 1) + f(n - 2)) % 10

    ```

    What is the maximum value returned by for in the range ?

    1. A.

      9

    2. B.

      8

    3. C.

      7

    4. D.

      5

    Correct Answer:

    A

    Step-by-Step Solution

    Key idea: This is a dual-branch recursion with modular arithmetic. We must trace the function for all from 0 to 20 and find the maximum return value. The modulo operation ensures values stay in .

    Step 1: Trace the function systematically:

    Step 2: Identify the maximum value from the traced results:

    • Values:
    • Maximum: at

    Answer: 9

    Question 3 · List Processing and In-Place Mutation MCQ

    Consider the following Python function:

    ```python

    def process(L, i=0):

    if i >= len(L) - 1:

    return 0

    count = 0

    if L[i] > L[i+1]:

    L[i], L[i+1] = L[i+1], L[i]

    count = 1

    return count + process(L, i+1)

    ```

    The function is called as process([4, 3, 2, 5, 1]). Consider the following statements about this call:

    I. The function returns .

    II. After the call completes, L[4] equals .

    III. After the call completes, the list L is sorted in non-decreasing order.

    Which of the above statements is/are correct?

    1. A.

      I and III only

    2. B.

      I and II only

    3. C.

      II and III only

    4. D.

      I, II and III

    Correct Answer:

    B

    Step-by-Step Solution

    Key idea: This is a single-pass adjacent-swap recursive scan. The list is shared across all recursive calls, so each swap is visible to later calls. One pass moves large elements rightward but does not guarantee a fully sorted list.

    Exam route: Trace the four comparisons (indices 0 through 3), count swaps, and inspect the final list.

    Step-by-step trace for L = [4, 3, 2, 5, 1]:

    | Call | | List at start | Comparison | Swap? | List after | count |

    |------|-----|---------------|------------|-------|------------|-------|

    | 1 | 0 | [4,3,2,5,1] | | Yes | [3,4,2,5,1] | 1 |

    | 2 | 1 | [3,4,2,5,1] | | Yes | [3,2,4,5,1] | 1 |

    | 3 | 2 | [3,2,4,5,1] | | No | [3,2,4,5,1] | 0 |

    | 4 | 3 | [3,2,4,5,1] | | Yes | [3,2,4,1,5] | 1 |

    | 5 | 4 | base case | — | — | [3,2,4,1,5] | 0 |

    Return value: . Statement I is true.

    Final list: . So L[4] = 5. Statement II is true.

    Sorted check: is not sorted (, ). Statement III is false.

    Trap path (overcounting): A student who assumes one left-to-right pass fully sorts the list will mark III as true and pick option D. A single pass only guarantees the largest element reaches the end; smaller elements may still be out of order.

    Answer: Statements I and II only.

    Question 4 · Function Scope, Closures and Default Arguments MCQ

    Match the Python functions in List I with the length of their default argument's state after executing the calls f(2), f(4), f(6), f(8) in List II.

    <b>List I</b>

    P) def f(x, lst=[]):

    if len(lst) < 3: lst.append(x)

    return lst

    Q) def f(x, lst=[0]):

    if lst[0] < 10: lst[0] += x

    return lst

    R) def f(x, lst=[]):

    if x > 0: lst.append(x)

    else: lst = [x]

    return lst

    S) def f(x, lst=[]):

    lst.append(x)

    if len(lst) > 2: lst.pop(0)

    return lst

    <b>List II</b>

    1. 1
    2. 2
    3. 3
    4. 4
    1. A.

      P-3, Q-1, R-4, S-2

    2. B.

      P-2, Q-4, R-4, S-2

    3. C.

      P-3, Q-1, R-1, S-4

    4. D.

      P-3, Q-4, R-4, S-2

    Correct Answer:

    A

    Step-by-Step Solution

    Key idea: This is a boundary-case question testing the distinction between mutation and reassignment, combined with conditional logic that alters the shared state.

    Step 1: Analyze P. The condition len(lst) < 3 allows appends until the list reaches length 3.

    • f(2): len 0 < 3. Appends 2. lst=[2].
    • f(4): len 1 < 3. Appends 4. lst=[2, 4].
    • f(6): len 2 < 3. Appends 6. lst=[2, 4, 6].
    • f(8): len 3 < 3 is False. No append. lst=[2, 4, 6].

    Final length for P is 3.

    Step 2: Analyze Q. The default is [0]. The condition lst[0] < 10 checks the first element. lst[0] += x mutates the element in place.

    • f(2): 0 < 10. lst[0] becomes 2. lst=[2].
    • f(4): 2 < 10. lst[0] becomes 6. lst=[6].
    • f(6): 6 < 10. lst[0] becomes 12. lst=[12].
    • f(8): 12 < 10 is False. No mutation. lst=[12].

    Final length for Q is 1.

    Step 3: Analyze R. All inputs (2, 4, 6, 8) are > 0, so the if branch is always taken. The else branch (reassignment) is never executed.

    • Each call appends to the shared list. After 4 calls, lst=[2, 4, 6, 8].

    Final length for R is 4.

    Step 4: Analyze S. The list appends first, then pops if length > 2.

    • f(2): Appends 2. lst=[2]. len > 2 is False.
    • f(4): Appends 4. lst=[2, 4]. len > 2 is False.
    • f(6): Appends 6. lst=[2, 4, 6]. len > 2 is True. Pops 0. lst=[4, 6].
    • f(8): Appends 8. lst=[4, 6, 8]. len > 2 is True. Pops 0. lst=[6, 8].

    Final length for S is 2.

    Matching: P-3, Q-1, R-4, S-2.

    Answer: A