chapter

    Programming and Data Structures Short Notes 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

    Assertion (A): A recursive function that calls itself before printing the current character will output the string in reverse order.

    Reason (R): The print statement is deferred until the call stack unwinds, causing the last character processed to be printed first.

    Question 4
    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 5
    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 6
    Level 1: Warm-up

    In a binary min-heap containing $15$ distinct elements stored in a $1$-based array, the second smallest element must be located at one of the child nodes of the root. The number of possible indices where the second smallest element can be stored is _____________.

    Question 7
    Level 1: Warm-up

    A hash table has slots. Under simple uniform hashing, the expected number of colliding pairs of keys is 19. How many keys were inserted into the table?

    Free preview ends here

    Login to view the complete short notes

    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.

    Explore complete test series, official past papers, and chapter-wise study tools.

    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 Short Notes 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 1831 practice questions.

    About Programming and Data Structures Short Notes

    Quick revision sheets for Programming and Data Structures in GATE CS. Every chapter is condensed into key formulas, shortcuts and common traps so you can revise 7 chapters fast before the exam.

    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 · Recursion and Recursive Program Analysis MCQ

    Assertion (A): A recursive function that calls itself before printing the current character will output the string in reverse order.

    Reason (R): The print statement is deferred until the call stack unwinds, causing the last character processed to be printed first.

    1. A.

      Both A and R are true and R is the correct explanation of A.

    2. B.

      Both A and R are true but R is not the correct explanation of A.

    3. C.

      A is true but R is false.

    4. D.

      A is false but R is true.

    Correct Answer:

    A

    Step-by-Step Solution

    Key idea: This is an assertion-reason question about string reversal using recursion.

    Step 1: Evaluate Assertion (A). Calling the function before printing defers the print to the ascent phase, reversing the string. (A is true).

    Step 2: Evaluate Reason (R). The print is indeed deferred until the stack unwinds, meaning the deepest call (last character) prints first. (R is true).

    Step 3: Check if R explains A. Yes, the deferred execution on the unwinding stack is exactly why the string is reversed.

    Answer: Both A and R are true and R is the correct explanation of A.

    Question 4 · 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 5 · 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 6 · Heaps, Priority Queues and Data Structure Operations NAT

    In a binary min-heap containing $15$ distinct elements stored in a $1$-based array, the second smallest element must be located at one of the child nodes of the root. The number of possible indices where the second smallest element can be stored is _____________.

    Correct Answer:

    2.00

    Step-by-Step Solution

    Key idea: This is a direct concept recall question on secondary extrema location.

    Step 1: In a min-heap, the smallest element is always at the root (index 1).

    Step 2: The second smallest element must be greater than the root but smaller than or equal to all other elements.

    Step 3: Because of the min-heap property (parent child), the second smallest cannot be a grandchild or deeper descendant, as its parent would be smaller than it, contradicting that it is the second smallest.

    Step 4: Therefore, the second smallest must be a direct child of the root.

    Step 5: In a 1-based array, the children of the root (index 1) are at indices 2 and 3.

    Step 6: Thus, there are exactly 2 possible indices.

    Answer: 2.00

    Question 7 · Hashing and Collision Resolution MCQ

    A hash table has slots. Under simple uniform hashing, the expected number of colliding pairs of keys is 19. How many keys were inserted into the table?

    1. A.

      19

    2. B.

      20

    3. C.

      21

    4. D.

      10

    Correct Answer:

    B

    Step-by-Step Solution

    Key idea: The expected number of colliding pairs is given by .

    Step 1: Set up the equation using the given values: .

    Step 2: Simplify the equation: .

    Step 3: Solve for . We need two consecutive integers whose product is 380.

    Step 4: Notice that . Thus, .

    Answer: 20