chapter
    Programming and Data Structures Short Notes for GATE CS

    GATE CS Programming and Data Structures: 7 chapters, 66 previous year questions (100% of Programming and Data Structures), 563 practice questions and one solv

    A question from this chapter

    Question 1
    Level 3: Exam Standard

    Consider the following two statements regarding ANSI C evaluation:

    \textbf{Assertion (A):} The decimal value of the expression (char)( ('~' | 'a') + 50 ) is .

    \textbf{Reason (R):} The bitwise OR of '~' (126) and 'a' (97) yields 127. Adding 50 gives 177, which exceeds the maximum signed char value of 127. The explicit (char) cast truncates the integer result to 8 bits, wrapping around to due to two's complement representation.

    Which one of the following options is correct?

    Question 2
    Level 3: Exam Standard

    Consider the character array char s[30] = "GATE2024";. A programmer wishes to transform this string into "GATEGATE20242024" by performing in-place character assignments. The transformation is done in two steps:

    1. Shift the necessary existing characters to the right to create a gap.
    2. Copy the required characters into the gap.

    Assuming the programmer uses the most efficient sequence of single-character assignments (and avoids undefined behavior from overlapping reads/writes), what is the MINIMUM number of character assignments required to complete this transformation, including the final null terminator placement?

    Question 3
    Level 3: Exam Standard

    Consider a queue of size containing elements (with at the front). We wish to reverse the queue into an initially empty queue using only and operations, without any additional storage. During the complete execution of the standard optimal two-queue reversal algorithm, how many more operations are performed on than on ?

    Question 4
    Level 3: Exam Standard

    Consider a binary tree with nodes. Find the maximum possible number of leaf nodes in such a tree.

    Question 5
    Level 3: Exam Standard

    Consider a binary min-heap with -based indexing that stores distinct elements. The maximum number of elements in the heap that can be strictly greater than the element at index is

    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.

    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: 7 chapters, 66 previous year questions (100% of Programming and Data Structures), 563 practice questions and one solved question from each chapter.

    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.

    Programming and Data Structures Weightage in GATE CS

    Programming and Data Structures accounts for 66 of 66 Programming and Data Structures previous year questions in our bank (100%), about 6.6 per paper across 10 papers.

    Programming and Data Structures Chapter Matrix

    ChapterTopicsPYQsShare of unit PYQsPractice questions
    C Programming, Control Flow and Array AlgorithmsLoop Tracing and Iterative Computation, Function Calls, Evaluation Order and Static State, Bitwise and Character Expressions, Array Processing and Iterative Algorithms, Variable Scope, Shadowing and Compilation1320%193
    Pointers, Arrays, Strings and Memory ManagementPointer Assignment, Dereferencing and Arithmetic, Strings and Character Pointers, Multidimensional Arrays and Memory Layout, Runtime Memory and Dynamic Allocation1015%153
    Recursion and Recursive Program AnalysisRecursive Array and String Traversal, Recursive Arithmetic Algorithms, Nested Recursion and Return-Value Analysis69%0
    Stacks, Queues and Linked ListsStack Operations and Augmented Stacks, Queue Operations, Reversal and Stack-Queue Interaction, Linked List Manipulation, Recursion and Complexity1117%60
    Binary Trees, Binary Search Trees and TraversalsBinary Tree Structure, Height and Node Counts, Binary Search Tree Construction and Ordering Properties, Tree Traversals and Recursive Tree Processing, Complete Binary Search Trees in Array Representation1320%127
    Heaps, Priority Queues and Data Structure OperationsHeap Structure, Height and Leaf Positions, Heap Construction and Array Validation, Priority Queue Operations and Heap Extrema, Meld Operations and Data Structure Complexity812%30
    Hashing and Collision ResolutionOpen Addressing and Probe Sequences, Uniform Hashing and Expected Load, Dynamic Hashing and Collision Buckets, Separate Chaining and Chain Length58%0

    More from Programming and Data Structures

    One Solved Question from Each Programming and Data Structures Chapter

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

    Consider the following two statements regarding ANSI C evaluation:

    \textbf{Assertion (A):} The decimal value of the expression (char)( ('~' | 'a') + 50 ) is .

    \textbf{Reason (R):} The bitwise OR of '~' (126) and 'a' (97) yields 127. Adding 50 gives 177, which exceeds the maximum signed char value of 127. The explicit (char) cast truncates the integer result to 8 bits, wrapping around to due to two's complement representation.

    Which one of the following options is correct?

    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: Integer promotion occurs during arithmetic, but an explicit cast to char forces truncation to 8 bits, invoking signed overflow behavior.

    Step 1: Evaluate the bitwise OR. The ASCII value of '~' is 126 (0111 1110). The ASCII value of 'a' is 97 (0110 0001).

    .

    Step 2: Evaluate the addition. Due to integer promotion, the addition is performed as an int, yielding .

    Step 3: Apply the explicit cast. The expression casts the int 177 to char. In 8-bit two's complement, 177 is 1011 0001.

    Step 4: Interpret as signed char. The most significant bit is 1, indicating a negative number. The value is .

    Step 5: Verify the statements. Assertion (A) correctly states the final value is . Reason (R) correctly identifies the intermediate sum (177), the boundary limit (127), and the mechanism of two's complement wrap-around via casting. R perfectly explains A.

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

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

    Consider the character array char s[30] = "GATE2024";. A programmer wishes to transform this string into "GATEGATE20242024" by performing in-place character assignments. The transformation is done in two steps:

    1. Shift the necessary existing characters to the right to create a gap.
    2. Copy the required characters into the gap.

    Assuming the programmer uses the most efficient sequence of single-character assignments (and avoids undefined behavior from overlapping reads/writes), what is the MINIMUM number of character assignments required to complete this transformation, including the final null terminator placement?

    1. A.

      8

    2. B.

      9

    3. C.

      13

    4. D.

      16

    Correct Answer:

    B

    Step-by-Step Solution

    Key idea: When shifting a string to a higher address (rightward) in-place, you must copy backwards to avoid overwriting unread characters. Only the characters that actually need to move should be shifted.

    Step 1: Analyze the initial and target states.

    Initial: (Indices 0 to 8).

    Target: (Indices 0 to 16).

    Step 2: Identify what needs to move. The prefix (indices 0-3) is already in the correct position. The suffix (indices 4-8, exactly 5 bytes) must be shifted right by 4 positions to indices 8-12.

    Step 3: Execute the shift safely. Since the destination (8) is greater than the source (4), a forward copy would overwrite the null terminator before it is read. We must copy backwards:

    ()

    ('4')

    ('2')

    ('0')

    ('2')

    This requires exactly 5 assignments.

    Step 4: Fill the gap. The gap at indices 4-7 must be filled with .

    .

    This requires exactly 4 assignments.

    Step 5: Sum the operations. total assignments.

    Answer: B

    Question 3 · Stacks, Queues and Linked Lists MCQ

    Consider a queue of size containing elements (with at the front). We wish to reverse the queue into an initially empty queue using only and operations, without any additional storage. During the complete execution of the standard optimal two-queue reversal algorithm, how many more operations are performed on than on ?

    1. A.

      35

    2. B.

      45

    3. C.

      55

    4. D.

      -35

    Correct Answer:

    A

    Step-by-Step Solution

    Key idea: This is an operation counting problem. We must separately count the Dequeue operations on and and find their difference.

    Step 1: Every element is removed from exactly once. Thus, total Dequeue operations on = .

    Step 2: For the -th element (from to ), after it is moved to , the elements already in must be rotated. Each rotation requires 1 Dequeue from .

    Step 3: Total Dequeue operations on = .

    Step 4: For , Dequeue on = .

    Step 5: The difference (Dequeue on minus Dequeue on ) = .

    Answer: 35

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

    Consider a binary tree with nodes. Find the maximum possible number of leaf nodes in such a tree.

    Correct Answer:

    50.00

    Step-by-Step Solution

    Key idea: To maximize leaf nodes , we must minimize internal nodes. Use the constraint and optimize.

    Step 1: We want to maximize subject to:

    Step 2: Substitute :

    Step 3: Since , maximizing means maximizing .

    Step 4: From with :

    • Maximum occurs when is minimized
    • If : (not integer!)
    • If : ✓

    Step 5: With :

    Verification: , , . Total = ✓

    Answer: 50

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

    Consider a binary min-heap with -based indexing that stores distinct elements. The maximum number of elements in the heap that can be strictly greater than the element at index is

    1. A.

      1020

    2. B.

      1021

    3. C.

      1022

    4. D.

      1023

    Correct Answer:

    C

    Step-by-Step Solution

    Key idea: In a min-heap, is the minimum, so . When counting elements strictly greater than , we must exclude and itself.

    Step 1: . is the minimum, so . Thus is NOT strictly greater than .

    Step 2: itself is NOT strictly greater than .

    Step 3: All proper descendants of node are by the min-heap property. The subtree of node contains nodes (including node ), so there are proper descendants.

    Step 4: The subtree of node contains nodes (excluding node ). All of these can be if we arrange the heap appropriately (e.g., is the second smallest element).

    Step 5: Maximum elements .

    Answer: 1022