GATE Computer Science and Information Technology (GATE CS) · GATE
Programming, Data Structures, and Algorithms
16 practice questions covering 28% of the official GATE Computer Science and Information Technology (GATE CS) blueprint. Every item includes a worked explanation of the correct answer.
View all 4 domains in GATE Computer Science and Information Technology (GATE CS)
Syllabus Coverage & Domain Overview
Programming, Data Structures, and Algorithms accounts for ~28% of the GATE CS technical weightage and is the highest-scoring analytical section. Questions test C recursion and pointer semantics, asymptotic recurrences via the Master Theorem T(n) = aT(n/b) + f(n), AVL tree rotations and height bounds, binary min/max heap build-heap O(n) vs extract-min O(log n), hashing collision resolution, shortest paths (Dijkstra with non-negative weights vs Bellman-Ford with negative weights), minimum spanning trees (cut and cycle properties in Prim and Kruskal), and dynamic programming subproblem tables.
In the official GATE Computer Science and Information Technology (GATE CS) examination blueprint, Programming, Data Structures, and Algorithms carries a weightage of 28%. Out of the total examination duration of 3 hr, candidates should budget approximately 50 min for questions from this domain to maintain pace across the paper.
How to Master Programming, Data Structures, and Algorithms for GATE Computer Science and Information Technology (GATE CS)
Our 16 published questions in Programming, Data Structures, and Algorithms are written for PrepIQ Hub and checked as set out in our editorial policy. Each item is written to the hard difficulty level of the GATE exam:
- Targeted Topic Drills: Launch Topic Practice mode to work exclusively through Programming, Data Structures, and Algorithms items and review the step-by-step derivation after each submission.
- Negative Marking Discipline: The GATE Computer Science and Information Technology (GATE CS) deducts ⅓ of the question's marks for each incorrect response. Use the worked explanations in this topic drill to spot common conceptual traps before sitting a timed mock.
- Benchmark Target: Aim for at least 35% accuracy in Programming, Data Structures, and Algorithms drills before moving to full-paper simulations.
Programming, Data Structures, and Algorithms worked examples
Programming, Data Structures, and Algorithms questions from the GATE Computer Science and Information Technology (GATE CS) syllabus, answered in full. Try each one before opening the explanation.
Example 1 · Programming, Data Structures, and Algorithms · hard
Which two statements accurately compare Dijkstra's single-source shortest-path algorithm and the Bellman-Ford algorithm on a directed weighted graph G = (V, E)? (Select two.)
Show answer and explanation
Correct answers: B. Dijkstra's greedy relaxation requires non-negative edge weights for correctness; D. Bellman-Ford handles negative edge weights and detects negative cycles in O(|V||E|)
Why
Dijkstra's greedy relaxation assumes non-negative edge weights and can fail when negative-weight edges exist, whereas Bellman-Ford relaxes all |E| edges |V| - 1 times in O(|V||E|) time, correctly handles negative edge weights, and detects reachable negative-weight cycles on a |V|-th pass.
- A. Dijkstra's algorithm finds shortest paths even when negative-weight cycles exist — Shortest paths are undefined (-infinity) when a negative-weight cycle is reachable, and Dijkstra fails even on simple negative edges.
- C. Bellman-Ford runs in O(|V| + |E|) linear time on arbitrary dense graphs — Bellman-Ford relaxes |E| edges across |V| - 1 iterations, taking O(|V||E|) time.
Example 2 · Programming, Data Structures, and Algorithms · hard
A message uses five characters A, B, C, D, and E with frequencies 5, 9, 12, 13, and 16 respectively. Using optimal binary Huffman coding, what is the total number of bits (weighted external path length) required to encode the 55 characters?
Show answer and explanation
Correct answer: B. 124 bits with lengths of 3 bits for A, B and 2 bits for C, D, E
Why
Frequencies: {5, 9, 12, 13, 16}. Step 1: merge 5 + 9 = 14 -> set {12, 13, 14, 16}. Step 2: merge 12 + 13 = 25 -> set {14, 16, 25}. Step 3: merge 14 + 16 = 30 -> set {25, 30}. Step 4: merge 25 + 30 = 55. Total bits = sum of internal node weights = 14 + 25 + 30 + 55 = 124 bits (code lengths: A=3, B=3, C=2, D=2, E=2 -> 5*3 + 9*3 + 12*2 + 13*2 + 16*2 = 15 + 27 + 24 + 26 + 32 = 124 bits).
- A. 110 bits assuming each character is encoded with a fixed 2-bit codeword — Five distinct characters cannot all have 2-bit prefix-free codewords because 2^2 = 4 < 5 (Kraft inequality).
- C. 165 bits using a fixed-length 3-bit ASCII subset code across 55 characters — 165 bits (55 * 3) is the uncompressed fixed-length cost, not the optimal Huffman cost.
- D. 138 bits obtained by merging the highest frequencies first instead of lowest — Huffman's greedy choice always merges the two lowest-frequency trees first.
Every worked example on this page passed our independent verification before publication — how that works is set out in our editorial policy. Spotted an error? Tell us through the contact page and we will correct it.
All 2 Programming, Data Structures, and Algorithms questions with answers
All Syllabus Domains in GATE Computer Science and Information Technology (GATE CS)
Programming, Data Structures, and Algorithms (Current domain)
16 questions · 28%Operating Systems and Computer Networks
14 questions · 26%Databases, Theory of Computation, and Compiler Design
14 questions · 24%Digital Logic, Computer Organization, and Discrete Mathematics
16 questions · 22%
GATE is a mark of the Indian Institute of Science and the Indian Institutes of Technology. PrepIQ Hub is not affiliated with, endorsed by, or sponsored by the GATE Committee.