chapter
    Programming and Data Structures Practice Questions for GATE CS

    GATE CS Programming and Data Structures: 1 units and 7 chapters, weightage from 66 previous year questions across 10 papers, a study order by exam weight and

    A question from this chapter

    Question 1
    Level 1: Warm-up

    Consider the C expression (x > 0) && (y++). If x is -1 and y is 5 before the expression is evaluated, what is the value of y immediately after?

    Question 2
    Level 1: Warm-up

    Consider the following C declaration:

    ```c

    char msg[] = "OK";

    ```

    What is the numerical value of sizeof(msg)?

    Question 3
    Level 1: Warm-up

    An empty stack and an empty queue undergo the following operations:

    Stack: push(10), push(20), pop(), push(30)

    Queue: enqueue(10), enqueue(20), dequeue(), enqueue(30)

    Let be the sum of elements currently in the stack, and be the sum of elements currently in the queue. Which of the following correctly describes the relationship between and ?

    Question 4
    Level 1: Warm-up

    In a binary search tree, let be an internal node, be its immediate left child, and be its immediate right child. Assuming all keys are distinct, which of the following represents the correct ascending order of their values?

    Question 5
    Level 1: Warm-up

    A binary min-heap contains distinct elements. The maximum element can be stored at most in _____________ different positions in the underlying array.

    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 and Data Structures Practice Questions for GATE CS

    GATE CS Programming and Data Structures: 1 units and 7 chapters, weightage from 66 previous year questions across 10 papers, a study order by exam weight and 563 practice questions.

    About Programming and Data Structures Practice Questions

    563 practice questions for Programming and Data Structures in GATE CS, sorted chapter by chapter and graded from basic to exam level, each with a full solution.

    GATE CS Programming and Data Structures Unit-wise Weightage from Past Papers

    We counted every GATE CS Programming and Data Structures previous year question in our bank (66 questions from 10 papers) and grouped them by unit.

    UnitChaptersPYQsShare of sectionAvg per paper
    Programming and Data Structures766100%6.6

    Suggested Programming and Data Structures Study Order for GATE CS

    1. Programming and Data Structures: 100% of past Programming and Data Structures questions, about 6.6 per paper.

    Start where the marks are. Units at the top of this list have appeared most often in past GATE CS papers.

    Units in GATE CS Programming and Data Structures

    All Programming and Data Structures chapters

    One Solved Question from Each Programming and Data Structures Chapter

    Question 1 · C Programming, Control Flow and Array Algorithms MCQ

    Consider the C expression (x > 0) && (y++). If x is -1 and y is 5 before the expression is evaluated, what is the value of y immediately after?

    1. A.

      y becomes 6 because y++ is always evaluated

    2. B.

      y remains 5 because short-circuit evaluation skips y++

    3. C.

      y becomes 4 because the && operator decrements the right operand

    4. D.

      The expression results in a compilation error due to side effects

    Correct Answer:

    B

    Step-by-Step Solution

    Key idea: Logical AND (&&) short-circuits if the left operand is false.

    Step 1: Evaluate the left operand: x > 0. Since x = -1, this is false.

    Step 2: Because the left operand is false, the entire && expression is false regardless of the right side.

    Step 3: C short-circuits, meaning the right operand (y++) is never evaluated.

    Step 4: y is not incremented and remains 5.

    Answer: y remains 5.

    Question 2 · Pointers, Arrays, Strings and Memory Management MCQ

    Consider the following C declaration:

    ```c

    char msg[] = "OK";

    ```

    What is the numerical value of sizeof(msg)?

    1. A.

      2

    2. B.

      3

    3. C.

      4

    4. D.

      8

    Correct Answer:

    B

    Step-by-Step Solution

    Key idea: This is an estimation question testing the difference between the sizeof operator and the strlen function for character arrays.

    Step 1: Identify the declaration. msg is a character array initialized with a string literal.

    Step 2: Determine the contents. The string "OK" consists of two visible characters: 'O' and 'K'.

    Step 3: Apply the string literal rule. The compiler automatically appends a null terminator (\0) to the end of the string literal.

    Step 4: Calculate the total size. The array contains 'O' (1 byte), 'K' (1 byte), and '\0' (1 byte). Total = 3 bytes.

    Answer: B.

    Question 3 · Stacks, Queues and Linked Lists MCQ

    An empty stack and an empty queue undergo the following operations:

    Stack: push(10), push(20), pop(), push(30)

    Queue: enqueue(10), enqueue(20), dequeue(), enqueue(30)

    Let be the sum of elements currently in the stack, and be the sum of elements currently in the queue. Which of the following correctly describes the relationship between and ?

    1. A.

    2. B.

    3. C.

    4. D.

    Correct Answer:

    C

    Step-by-Step Solution

    Key idea: This is a bounding question testing the fundamental difference between LIFO (stack) and FIFO (queue) removal constraints.

    Step 1: Trace the Stack (LIFO).

    • push(10) [10]
    • push(20) [10, 20]
    • pop() removes 20 (top). Stack is [10]
    • push(30) [10, 30]
    • Sum .

    Step 2: Trace the Queue (FIFO).

    • enqueue(10) [10]
    • enqueue(20) [10, 20]
    • dequeue() removes 10 (front). Queue is [20]
    • enqueue(30) [20, 30]
    • Sum .

    Step 3: Compare and . , so .

    Answer:

    Question 4 · Binary Trees, Binary Search Trees and Traversals MCQ

    In a binary search tree, let be an internal node, be its immediate left child, and be its immediate right child. Assuming all keys are distinct, which of the following represents the correct ascending order of their values?

    1. A.

    2. B.

    3. C.

    4. D.

    Correct Answer:

    B

    Step-by-Step Solution

    Key idea: This is a language-to-math translation question testing the strict definition of the BST invariant.

    Step 1: Translate the BST property into mathematical inequalities. For any node , all values in its left subtree must be strictly less than . Therefore, .

    Step 2: Similarly, all values in the right subtree must be strictly greater than . Therefore, .

    Step 3: Combine the inequalities: and gives .

    Step 4: Match this with the options. Option B matches exactly.

    Answer: B

    Question 5 · Heaps, Priority Queues and Data Structure Operations NAT

    A binary min-heap contains distinct elements. The maximum element can be stored at most in _____________ different positions in the underlying array.

    Correct Answer:

    10

    Step-by-Step Solution

    Key idea: In a min-heap, the maximum element must be at a leaf node. The number of leaves in a complete binary tree with nodes is .

    Step 1: Identify that in a min-heap, the maximum cannot be at an internal node (it would violate the heap property since children must be parent).

    Step 2: Therefore, the maximum must be at a leaf.

    Step 3: Count the leaves: .

    Answer: 10

    Common trap: Using gives the same answer for even , but for odd it would be wrong. Always use for leaf count.