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:
Let S be the sum of elements currently in the stack, and Q be the sum of elements currently in the queue. Which of the following correctly describes the relationship between S and Q?
Question 5
Level 1: Warm-up
In a binary search tree, let X be an internal node, Y be its immediate left child, and Z 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 m=10 slots. Under simple uniform hashing, the expected number of colliding pairs of keys is 19. How many keys n 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.
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.
One Solved Question from Each Programming and Data Structures Chapter
Question 1 · C Programming, Control Flow and Array AlgorithmsMCQ
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?
A.
y becomes 6 because y++ is always evaluated
B.
y remains 5 because short-circuit evaluation skips y++
C.
y becomes 4 because the && operator decrements the right operand
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 ManagementMCQ
Consider the following C declaration:
```c
char msg[] = "OK";
```
What is the numerical value of sizeof(msg)?
A.
2
B.
3
C.
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 AnalysisMCQ
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.
A.
Both A and R are true and R is the correct explanation of A.
B.
Both A and R are true but R is not the correct explanation of A.
C.
A is true but R is false.
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 ListsMCQ
An empty stack and an empty queue undergo the following operations:
Let S be the sum of elements currently in the stack, and Q be the sum of elements currently in the queue. Which of the following correctly describes the relationship between S and Q?
A.
S=Q
B.
S>Q
C.
S<Q
D.
S=2Q
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 S=10+30=40.
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 Q=20+30=50.
Step 3: Compare S and Q. 40<50, so S<Q.
Answer: S<Q
Question 5 · Binary Trees, Binary Search Trees and TraversalsMCQ
In a binary search tree, let X be an internal node, Y be its immediate left child, and Z be its immediate right child. Assuming all keys are distinct, which of the following represents the correct ascending order of their values?
A.
Z<X<Y
B.
Y<X<Z
C.
X<Y<Z
D.
Y<Z<X
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 X, all values in its left subtree must be strictly less than X. Therefore, Y<X.
Step 2: Similarly, all values in the right subtree must be strictly greater than X. Therefore, X<Z.
Step 3: Combine the inequalities: Y<X and X<Z gives Y<X<Z.
Step 4: Match this with the options. Option B matches exactly.
Answer: B
Question 6 · Heaps, Priority Queues and Data Structure OperationsNAT
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 ResolutionMCQ
A hash table has m=10 slots. Under simple uniform hashing, the expected number of colliding pairs of keys is 19. How many keys n were inserted into the table?
A.
19
B.
20
C.
21
D.
10
Correct Answer:
B
Step-by-Step Solution
Key idea: The expected number of colliding pairs is given by E[C]=2mn(n−1).
Step 1: Set up the equation using the given values: 19=2×10n(n−1).
Step 2: Simplify the equation: 19=20n(n−1)⟹n(n−1)=380.
Step 3: Solve for n. We need two consecutive integers whose product is 380.