Organised by IIT Kharagpur

GATE 2014 CS (Computer Science) Set 3 question paper with solutions

36 questions with the official answer key and a worked solution for each. Try a question before opening its answer.

Practise this paper with instant checking
Q1MCQ1 mark · -1/3· Easy

While trying to collect an envelope (I) from under the table (II), Mr. X fell down (III) and was losing consciousness (IV). (Underlined parts: I = "While trying to collect", II = "from under the table", III = "Mr. X fell down", IV = "was losing consciousness".) Which one of the above underlined parts of the sentence is NOT appropriate?

  1. (A)I
  2. (B)II
  3. (C)III
  4. (D)IV
Answer: D - show solution

The sentence narrates completed past events: he fell down and then lost consciousness. "Fell down" is simple past, so the parallel verb joined by "and" should also be simple past: "lost consciousness". The past continuous "was losing consciousness" breaks the sequence. Parts I, II and III are correct. Answer: (D) IV.

Concept: Tense consistency between verbs joined by 'and' in a narrative of completed events. The trap is 'from under the table', which looks odd but is a correct double preposition.

Q2MCQ1 mark · -1/3· Easy

If she _______________ how to calibrate the instrument, she _______________ done the experiment.

  1. (A)knows, will have
  2. (B)knew, had
  3. (C)had known, could have
  4. (D)should have known, would have
Answer: C - show solution

The main clause ends with "done", a past participle, so it needs "could/would have done": an unreal past (third) conditional. The third conditional takes the past perfect in the if-clause: "If she had known ..., she could have done the experiment." Answer: (C) had known, could have.

Concept: Third conditional: if + past perfect, could/would have + past participle. The trap is option D, which puts a modal ('should have known') inside the if-clause.

Q4MCQ1 mark · -1/3· Easy

Which number does not belong in the series below? 2, 5, 10, 17, 26, 37, 50, 64

  1. (A)17
  2. (B)37
  3. (C)64
  4. (D)26
Answer: C - show solution

The terms are n² + 1 for n = 1, 2, 3, ...: 2, 5, 10, 17, 26, 37, 50, 65. Equivalently the differences are 3, 5, 7, 9, 11, 13, 15. The last term should be 50 + 15 = 65, not 64. Answer: (C) 64.

Concept: Recognising n² + 1 (or successive odd differences). The trap is noticing that 64 is a perfect square and assuming it fits.

Q5MCQ1 mark · -1/3· Moderate

The table below has question-wise data on the performance of students in an examination. The marks for each question are also listed. There is no negative or partial marking in the examination. Q No. Marks Answered Correctly Answered Wrongly Not Attempted 1 2 21 17 6 2 3 15 27 2 3 2 23 18 3 What is the average of the marks obtained by the class in the examination?

  1. (A)1.34
  2. (B)1.74
  3. (C)3.02
  4. (D)3.91
Answer: C - show solution

Number of students = 21 + 17 + 6 = 44 (each row sums to 44). Total marks scored = 21 × 2 + 15 × 3 + 23 × 2 = 42 + 45 + 46 = 133. Average per student = 133 / 44 ≈ 3.02. Answer: (C) 3.02.

Concept: The class size is the row total, and the average is per student over the whole exam. The trap is averaging per question (133/132 or 133/3) or dividing by the number who answered correctly.

Q12MCQ1 mark · -1/3· Moderate

Let X and Y be finite sets and f: X → Y be a function. Which one of the following statements is TRUE?

  1. (A)For any subsets A and B of X, |f(A ∪ B)| = |f(A)| + |f(B)|
  2. (B)For any subsets A and B of X, f(A ∩ B) = f(A) ∩ f(B)
  3. (C)For any subsets A and B of X, |f(A ∩ B)| = min{|f(A)|, |f(B)|}
  4. (D)For any subsets S and T of Y, f⁻¹(S ∩ T) = f⁻¹(S) ∩ f⁻¹(T)
Answer: D - show solution

D: x ∈ f⁻¹(S ∩ T) ⇔ f(x) ∈ S and f(x) ∈ T ⇔ x ∈ f⁻¹(S) and x ∈ f⁻¹(T). So preimage always preserves intersection - true. Counter-example for the rest: X = {1, 2}, Y = {y}, f(1) = f(2) = y, A = {1}, B = {2}. Then A ∩ B = ∅, so f(A ∩ B) = ∅ but f(A) ∩ f(B) = {y} (B and C fail), and |f(A ∪ B)| = 1 ≠ 1 + 1 (A fails). Answer: (D).

Concept: Preimages commute with unions and intersections; images commute only with unions, and only when the function is injective for intersections. The trap is B, which holds only for one-to-one functions.

Q15NAT1 mark · no negative· Easy

If V₁ and V₂ are 4-dimensional subspaces of a 6-dimensional vector space V, then the smallest possible dimension of V₁ ∩ V₂ is ______.

Answer: 2 - show solution

dim(V₁ + V₂) = dim V₁ + dim V₂ - dim(V₁ ∩ V₂). Since V₁ + V₂ ⊆ V, dim(V₁ + V₂) ≤ 6, so 4 + 4 - dim(V₁ ∩ V₂) ≤ 6, giving dim(V₁ ∩ V₂) ≥ 2. The value 2 is attained, e.g. V₁ = span(e₁..e₄), V₂ = span(e₃..e₆). Answer: 2.

Concept: Dimension formula for the sum of subspaces. The trap is answering 0, forgetting that two large subspaces of a small space must overlap.

Q16NAT1 mark · no negative· Moderate

If ∫ from 0 to 2π of |x sin x| dx = kπ, then the value of k is equal to ______ .

Answer: 4 - show solution

On [0, 2π], x ≥ 0, so |x sin x| = x|sin x|. sin x ≥ 0 on [0, π] and ≤ 0 on [π, 2π]. An antiderivative of x sin x is sin x - x cos x. ∫ from 0 to π of x sin x dx = [sin x - x cos x] from 0 to π = π. ∫ from π to 2π of -x sin x dx = -[sin x - x cos x] from π to 2π = -(-2π - π) = 3π. Total = 4π, so k = 4. Answer: 4.

Concept: Split an absolute-value integrand at the sign changes, then integrate by parts. The trap is integrating x sin x over [0, 2π] directly, which gives -2π.

Q17MCQ1 mark · -1/3· Easy

Consider the following minterm expression for F: F(P, Q, R, S) = Σ 0, 2, 5, 7, 8, 10, 13, 15 The minterms 2, 7, 8 and 13 are 'do not care' terms. The minimal sum-of-products form for F is

  1. (A)QS̄ + Q̄S
  2. (B)Q̄S̄ + QS
  3. (C)Q̄R̄S̄ + Q̄RS̄ + QR̄S + QRS
  4. (D)P̄Q̄S̄ + P̄QS + PQS + PQ̄S̄
Answer: B - show solution

Required 1s: 0, 5, 10, 15; don't cares: 2, 7, 8, 13. Q̄S̄ (Q = 0, S = 0) is minterms 0, 2, 8, 10 - covers 0 and 10 using don't cares 2 and 8. QS (Q = 1, S = 1) is minterms 5, 7, 13, 15 - covers 5 and 15 using don't cares 7 and 13. Two quads cover everything. Answer: (B) Q̄S̄ + QS.

Concept: Using don't cares to enlarge groups in a K-map (the corner quad here). The trap is option C or D, which ignore the don't cares and leave four-literal or three-literal terms.

Q19MCQ1 mark · -1/3· Easy

Consider the following processors (ns stands for nanoseconds). Assume that the pipeline registers have zero latency. P1: Four-stage pipeline with stage latencies 1 ns, 2 ns, 2 ns, 1 ns. P2: Four-stage pipeline with stage latencies 1 ns, 1.5 ns, 1.5 ns, 1.5 ns. P3: Five-stage pipeline with stage latencies 0.5 ns, 1 ns, 1 ns, 0.6 ns, 1 ns. P4: Five-stage pipeline with stage latencies 0.5 ns, 0.5 ns, 1 ns, 1 ns, 1.1 ns. Which processor has the highest peak clock frequency?

  1. (A)P1
  2. (B)P2
  3. (C)P3
  4. (D)P4
Answer: C - show solution

The clock period of a pipeline is the slowest stage latency. P1: 2 ns (500 MHz). P2: 1.5 ns (667 MHz). P3: 1 ns (1 GHz). P4: 1.1 ns (909 MHz). P3 has the shortest period and hence the highest frequency. Answer: (C) P3.

Concept: Pipeline clock is set by the bottleneck stage. The trap is summing stage latencies or picking P4 for having many short stages.

Q20MCQ1 mark · -1/3· Easy

Let A be a square matrix of size n × n. Consider the following pseudocode. What is the expected output?

C = 100;
for i = 1 to n do
  for j = 1 to n do
    {
      Temp = A[i][j] + C;
      A[i][j] = A[j][i];
      A[j][i] = Temp - C;
    }
for i = 1 to n do
  for j = 1 to n do
    output(A[i][j]);
  1. (A)The matrix A itself
  2. (B)Transpose of the matrix A
  3. (C)Adding 100 to the upper diagonal elements and subtracting 100 from lower diagonal elements of A
  4. (D)None of the above
Answer: A - show solution

The body swaps A[i][j] and A[j][i] (Temp holds A[i][j] + 100, and Temp - 100 restores the original value, so C has no net effect). Both loops run over all (i, j), so each off-diagonal pair is visited twice: once as (i, j) and once as (j, i). The second swap undoes the first. Diagonal elements are swapped with themselves. The matrix is unchanged, and the output is A itself. Answer: (A).

Concept: Transposing in place must iterate only over j > i (or j < i). The trap is answering 'transpose' without noticing the full double loop swaps every pair twice.

Q21NAT1 mark · no negative· Moderate

The minimum number of arithmetic operations required to evaluate the polynomial P(X) = X⁵ + 4X³ + 6X + 5 for a given value of X, using only one temporary variable is ______.

Answer: 7 - show solution

Rewrite in nested (Horner-like) form: P(X) = ((X² + 4)·X² + 6)·X + 5. With one temporary t: t = X * X (1) t = t + 4 (2) t = t * X (3) t = t * X (4) now t = X⁴ + 4X² t = t + 6 (5) t = t * X (6) t = t + 5 (7) Seven operations. Fewer is not possible with one temporary, since X² cannot be kept while t is reused. Answer: 7.

Concept: Horner-style factoring to minimise operations. The trap is computing X² once and reusing it, which needs a second temporary (giving 6 with two variables).

Q22MCQ1 mark · -1/3· Moderate

Consider the following rooted tree with the vertex labeled P as the root. P has children Q and R (in that order). Q has one child S. R has children T, U and V (in that order). U has one child W. The order in which the nodes are visited during an in-order traversal of the tree is

  1. (A)SQPTRWUV
  2. (B)SQPTUWRV
  3. (C)SQPTWUVR
  4. (D)SQPTRUWV
Answer: A - show solution

For a general (ordered) tree, in-order visits the first subtree, then the node, then the remaining subtrees left to right. At P: in-order(Q), P, in-order(R). in-order(Q) = in-order(S), Q = S Q. in-order(R) = in-order(T), R, in-order(U), in-order(V) = T R W U V (U's first subtree is W, then U). Result: S Q P T R W U V. Answer: (A) SQPTRWUV.

Concept: In-order on a non-binary tree: first child subtree, root, then the other children. The trap is visiting R only after all its children, as in post-order.

Q23NAT1 mark · no negative· Hard

Suppose depth first search is executed on the graph below starting at some unknown vertex. Assume that a recursive call to visit a vertex is made only after first checking that the vertex has not been visited earlier. Then the maximum possible recursion depth (including the initial call) is _________. The graph: a left block that is a 3 × 3 grid of vertices L(r,c), r, c ∈ {1, 2, 3} with row 1 on top, each vertex adjacent to its horizontal and vertical neighbours; a right block that is an identical 3 × 3 grid R(r,c). A vertex X is adjacent to L(3,3) and R(3,1). A vertex Y is adjacent only to X. A vertex Z is adjacent only to R(2,3). (21 vertices in all.)

Answer: 19 - show solution

Recursion depth = number of vertices on the DFS stack = length of a simple path DFS can follow, and DFS can be steered along any simple path. So find the longest simple path. Colour each 3 × 3 grid like a chessboard: corners and centre (5) versus edge-middles (4). A path through all 9 vertices must start and end on corners/centre. Path: snake through all 9 of the left grid ending at corner L(3,3) (9), go to X (10), enter R(3,1), a corner, and snake through all 9 of the right grid ending at a corner (19). To also reach Z the path would have to end the right grid at R(2,3), an edge-middle, which forces skipping a grid vertex, so still 19. Y is a dead end beside X. Answer: 19.

Concept: DFS recursion depth equals the longest simple path DFS can be steered along. The trap is counting all 21 vertices, ignoring the pendant vertices and the grid parity constraint.

Q24MCQ1 mark · -1/3· Easy

You have an array of n elements. Suppose you implement quicksort by always choosing the central element of the array as the pivot. Then the tightest upper bound for the worst case performance is

  1. (A)O(n²)
  2. (B)O(n log n)
  3. (C)Θ(n log n)
  4. (D)O(n³)
Answer: A - show solution

Any fixed pivot rule (first, last or middle element) has an adversarial input where the chosen pivot is always the smallest or largest remaining element. Each partition then removes only one element, giving n + (n - 1) + ... = Θ(n²) comparisons. Choosing the middle position is not the same as choosing the median value. Answer: (A) O(n²).

Concept: Worst-case quicksort with a deterministic pivot position is quadratic. The trap is confusing 'central element' with the median, which would give O(n log n).

Q25NAT1 mark · no negative· Moderate

The length of the shortest string NOT in the language (over Σ = {a, b}) of the following regular expression is ______________. a*b*(ba)*a*

Answer: 3 - show solution

Length 0: ε is in. Length 1: a, b are in. Length 2: aa (a*), ab (a*b*), ba ((ba)*), bb (b*) are all in. Length 3: try bab. After any a* (none here) and b* = b, the remainder ab must match (ba)*a*, which it cannot (it would need to start with b or be all a's). With b* = ε, (ba) consumes ba and the leftover b cannot match a*. So bab is not in the language. Shortest missing string has length 3. Answer: 3.

Concept: Systematic enumeration of short strings against a regular expression. The trap is stopping at length 2 and concluding every short string is covered.

Q27MCQ1 mark · -1/3· Easy

One of the purposes of using intermediate code in compilers is to

  1. (A)make parsing and semantic analysis simpler.
  2. (B)improve error recovery and error reporting.
  3. (C)increase the chances of reusing the machine-independent code optimizer in other compilers.
  4. (D)improve the register allocation.
Answer: C - show solution

Intermediate code separates the front end (language-specific) from the back end (machine-specific). Optimisations written on the intermediate representation are independent of both the source language and the target machine, so the same optimiser can be reused across compilers. Parsing and error reporting happen before IR generation, and register allocation is a back-end concern. Answer: (C).

Concept: Purpose of an IR: retargetability and reuse of machine-independent optimisation. The trap is option D; register allocation is done on target code, not because of the IR.

Q28MCQ1 mark · -1/3· Easy

Which of the following statements are CORRECT? 1) Static allocation of all data areas by a compiler makes it impossible to implement recursion. 2) Automatic garbage collection is essential to implement recursion. 3) Dynamic allocation of activation records is essential to implement recursion. 4) Both heap and stack are essential to implement recursion.

  1. (A)1 and 2 only
  2. (B)2 and 3 only
  3. (C)3 and 4 only
  4. (D)1 and 3 only
Answer: D - show solution

Recursion needs a fresh activation record for each active call. With purely static allocation there is one record per procedure, so recursion is impossible (1 true) and dynamic allocation of activation records is required (3 true). A stack alone suffices; no heap or garbage collector is needed (2 and 4 false). Answer: (D) 1 and 3 only.

Concept: Run-time storage organisation for recursion. The trap is statement 4: a heap is needed for dynamic data, not for recursion.

Q32MCQ1 mark · -1/3· Easy

A prime attribute of a relation scheme R is an attribute that appears

  1. (A)in all candidate keys of R.
  2. (B)in some candidate key of R.
  3. (C)in a foreign key of R.
  4. (D)only in the primary key of R.
Answer: B - show solution

By definition an attribute is prime if it is a member of at least one candidate key of R; otherwise it is non-prime. This is the notion 3NF uses. Answer: (B) in some candidate key of R.

Concept: Definition of prime attribute, used in 2NF and 3NF tests. The trap is option A (all candidate keys) or D (primary key only); any candidate key suffices.

Q33MCQ1 mark · -1/3· Easy

In the following pairs of OSI protocol layer/sub-layer and its functionality, the INCORRECT pair is

  1. (A)Network layer and Routing
  2. (B)Data Link Layer and Bit synchronization
  3. (C)Transport layer and End-to-end process communication
  4. (D)Medium Access Control sub-layer and Channel sharing
Answer: B - show solution

Routing is a network layer function, end-to-end process communication is the transport layer's job, and channel sharing (multiple access) is the MAC sub-layer's job. Bit synchronization - agreeing on bit timing on the medium - belongs to the physical layer; the data link layer handles framing and frame-level error control. Answer: (B).

Concept: Mapping functions to OSI layers. The trap is confusing bit synchronization (physical layer) with frame synchronization (data link layer).

Q35MCQ1 mark · -1/3· Moderate

Host A (on TCP/IP v4 network A) sends an IP datagram D to host B (also on TCP/IP v4 network B). Assume that no error occurred during the transmission of D. When D reaches B, which of the following IP header field(s) may be different from that of the original datagram D? (i) TTL (ii) Checksum (iii) Fragment Offset

  1. (A)(i) only
  2. (B)(i) and (ii) only
  3. (C)(ii) and (iii) only
  4. (D)(i), (ii) and (iii)
Answer: D - show solution

Every router decrements TTL, so TTL changes. Because the header changed, each router recomputes the header checksum, so the checksum changes. If a link on the path has a smaller MTU, a router fragments D, and the fragments that reach B carry non-zero fragment offsets. All three may differ. Answer: (D) (i), (ii) and (iii).

Concept: Which IPv4 header fields routers rewrite. The trap is forgetting fragmentation along the path, which changes the fragment offset (the question says 'may').

Q37NAT2 marks · no negative· Moderate

Every host in an IPv4 network has a 1-second resolution real-time clock with battery backup. Each host needs to generate up to 1000 unique identifiers per second. Assume that each host has a globally unique IPv4 address. Design a 50-bit globally unique ID for this purpose. After what period (in seconds) will the identifiers generated by a host wrap around?

Answer: 256 - show solution

Use the 32-bit IPv4 address to make IDs unique across hosts. To distinguish up to 1000 IDs within one second needs ⌈log₂ 1000⌉ = 10 bits. That leaves 50 - 32 - 10 = 8 bits for the clock (seconds counter). An 8-bit counter covers 2⁸ = 256 distinct seconds before repeating, so the IDs wrap around after 256 seconds. Answer: 256.

Concept: Bit budgeting for a unique ID: host part + per-second sequence + time part. The trap is using all 18 non-address bits for time and forgetting the per-second counter.

Q40MCQ2 marks · -2/3· Moderate

Consider the relational schema given below, where eId of the relation dependent is a foreign key referring to empId of the relation employee. Assume that every employee has at least one associated dependent in the dependent relation. employee (empId, empName, empAge) dependent (depId, eId, depName, depAge) Consider the following relational algebra query: π_empId(employee) - π_empId(employee ⋈_(empId = eId) ∧ (empAge ≤ depAge) dependent) The above query evaluates to the set of empIds of employees whose age is greater than that of

  1. (A)some dependent.
  2. (B)all dependents.
  3. (C)some of his/her dependents.
  4. (D)all of his/her dependents.
Answer: D - show solution

The join pairs each employee with his/her own dependents (empId = eId) whose age is at least the employee's age. Its projection is the set of employees having at least one own dependent at least as old as themselves. Subtracting this from all employees leaves those for whom no own dependent has depAge ≥ empAge, i.e. the employee is older than every one of his/her dependents. Answer: (D) all of his/her dependents.

Concept: Set difference turns 'exists a counterexample' into 'for all'. The trap is option B: the join condition empId = eId restricts the comparison to the employee's own dependents, not all dependents.

Q41NAT2 marks · no negative· Easy

A system contains three programs and each requires three tape units for its operation. The minimum number of tape units which the system must have such that deadlocks never arise is _________.

Answer: 7 - show solution

Worst case: each program holds one fewer unit than it needs, i.e. 2 units each, and waits for one more. With 3 × 2 = 6 units that state is a deadlock. With one more unit (7), at least one program can get its third unit, finish and release its units, so the others can proceed. Minimum = 3 × (3 - 1) + 1 = 7. Answer: 7.

Concept: Deadlock-free resource count: Σ(maxᵢ - 1) + 1. The trap is answering 9 (enough for all at once) or 6.

Q42NAT2 marks · no negative· Moderate

An operating system uses shortest remaining time first scheduling algorithm for pre-emptive scheduling of processes. Consider the following set of processes with their arrival times and CPU burst times (in milliseconds): Process Arrival Time Burst Time P1 0 12 P2 2 4 P3 3 6 P4 8 5 The average waiting time (in milliseconds) of the processes is _________.

Answer: 5.5 - show solution

Timeline: 0-2 P1 (remaining 10). At 2, P2 (4) preempts. 2-6 P2 completes. At 6, P3 (6) is shortest. At 8, P4 arrives with 5 but P3 has 4 left, so P3 continues: 6-12 P3 completes. 12-17 P4. 17-27 P1. Waiting = completion - arrival - burst: P1 27 - 0 - 12 = 15, P2 6 - 2 - 4 = 0, P3 12 - 3 - 6 = 3, P4 17 - 8 - 5 = 4. Average = 22 / 4 = 5.5. Answer: 5.5.

Concept: SRTF compares the newcomer's burst with the running process's remaining time. The trap is preempting P3 at time 8 by comparing P4's 5 with P3's original 6.

Q43NAT2 marks · no negative· Easy

Consider a paging hardware with a TLB. Assume that the entire page table and all the pages are in the physical memory. It takes 10 milliseconds to search the TLB and 80 milliseconds to access the physical memory. If the TLB hit ratio is 0.6, the effective memory access time (in milliseconds) is _________.

Answer: 122 - show solution

TLB hit: TLB search + one memory access = 10 + 80 = 90. TLB miss: TLB search + page table access + memory access = 10 + 80 + 80 = 170. EMAT = 0.6 × 90 + 0.4 × 170 = 54 + 68 = 122. Answer: 122.

Concept: Effective access time with a TLB and a single-level page table. The trap is omitting the TLB search time on a miss, which gives 118.

Q46MCQ2 marks · -2/3· Moderate

Consider the following languages over the alphabet Σ = {0, 1, c}: L₁ = {0ⁿ1ⁿ | n ≥ 0} L₂ = {wcwʳ | w ∈ {0,1}*} L₃ = {wwʳ | w ∈ {0,1}*} Here, wʳ is the reverse of the string w. Which of these languages are deterministic Context-free languages?

  1. (A)None of the languages
  2. (B)Only L₁
  3. (C)Only L₁ and L₂
  4. (D)All the three languages
Answer: C - show solution

L₁: a DPDA pushes on 0s and pops on 1s, accepting on empty count - deterministic. L₂: push symbols of w until the marker c, then pop and match; the marker tells the machine exactly where the middle is - deterministic. L₃: even-length palindromes have no middle marker, so the PDA must guess the midpoint; this language is context-free but not deterministic CF. Answer: (C) Only L₁ and L₂.

Concept: Deterministic vs non-deterministic CFLs: a centre marker makes palindromes deterministic. The trap is treating wwʳ like wcwʳ.

Q47NAT2 marks · no negative· Easy

Suppose you want to move from 0 to 100 on the number line. In each step, you either move right by a unit distance or you take a shortcut. A shortcut is simply a pre-specified pair of integers i, j with i < j. Given a shortcut i, j if you are at position i on the number line, you may directly move to j. Suppose T(k) denotes the smallest number of steps needed to move from k to 100. Suppose further that there is at most 1 shortcut involving any number, and in particular from 9 there is a shortcut to 15. Let y and z be such that T(9) = 1 + min(T(y), T(z)). Then the value of the product yz is _____.

Answer: 150 - show solution

From position 9 there are exactly two possible moves: a unit step to 10, or the shortcut to 15 (9 is involved in only this one shortcut). Each costs one step, so T(9) = 1 + min(T(10), T(15)). Hence {y, z} = {10, 15} and yz = 150. Answer: 150.

Concept: Writing the DP recurrence from the available transitions. The trap is overthinking other shortcuts; 'at most one shortcut involving any number' rules them out at 9.

Q49NAT2 marks · no negative· Moderate

Suppose we have a balanced binary search tree T holding n numbers. We are given two numbers L and H and wish to sum up all the numbers in T that lie between L and H. Suppose there are m such numbers in T. If the tightest upper bound on the time to compute the sum is O(nᵃ logᵇ n + mᶜ logᵈ n), the value of a + 10b + 100c + 1000d is ____.

Answer: 110 - show solution

Search down the tree for L: O(log n) since the tree is balanced. Then do an in-order walk from there, adding each key until a key exceeds H. The walk visits the m keys in range plus O(log n) boundary nodes, so the total is O(log n + m). Match O(nᵃ logᵇ n + mᶜ logᵈ n): a = 0, b = 1, c = 1, d = 0. a + 10b + 100c + 1000d = 0 + 10 + 100 + 0 = 110. Answer: 110.

Concept: Range queries on a balanced BST cost O(log n + m). The trap is O(m log n), from searching for each in-range key separately.

Q50MCQ2 marks · -2/3· Easy

Consider a hash table with 100 slots. Collisions are resolved using chaining. Assuming simple uniform hashing, what is the probability that the first 3 slots are unfilled after the first 3 insertions?

  1. (A)(97 × 97 × 97)/100³
  2. (B)(99 × 98 × 97)/100³
  3. (C)(97 × 96 × 95)/100³
  4. (D)(97 × 96 × 95)/(3! × 100³)
Answer: A - show solution

With simple uniform hashing each key independently lands in any of the 100 slots with equal probability, and chaining lets several keys share a slot. For the first 3 slots to stay empty each insertion must land in one of the other 97 slots: probability 97/100 each, independently. Total = (97 × 97 × 97)/100³. Answer: (A).

Concept: Independence of insertions under uniform hashing with chaining. The trap is option C, which assumes later keys cannot reuse an occupied slot (as with open addressing).

Q52MCQ2 marks · -2/3· Moderate

Consider the C function given below. Assume that the array listA contains n (> 0) elements, sorted in ascending order. Which one of the following statements about the function ProcessArray is CORRECT?

int ProcessArray(int *listA, int x, int n)
{
  int i, j, k;
  i = 0;
  j = n-1;
  do {
      k = (i+j)/2;
      if (x <= listA[k])
          j = k-1;
      if (listA[k] <= x)
          i = k+1;
     }while (i <= j);

  if (listA[k] == x)
      return(k);
  else
      return -1;
}
  1. (A)It will run into an infinite loop when x is not in listA.
  2. (B)It is an implementation of binary search.
  3. (C)It will always find the maximum element in listA.
  4. (D)It will return -1 even when x is present in listA.
Answer: B - show solution

Each iteration takes the midpoint k. If x < listA[k] only j = k - 1 runs; if x > listA[k] only i = k + 1 runs; the range shrinks every time, so the loop terminates (A false). If x == listA[k], both conditions hold: j = k - 1 and i = k + 1, so i > j and the loop exits with k pointing at x, and the function returns k. So it finds x when present (D false) and returns -1 otherwise. This is binary search; it searches for x, not the maximum (C false). Answer: (B).

Concept: Tracing a binary search with two non-exclusive ifs. The trap is thinking the equality case causes an extra step that loses k; both updates fire together and end the loop at the right index.

Q53NAT2 marks · no negative· Hard

An instruction pipeline has five stages, namely, instruction fetch (IF), instruction decode and register fetch (ID/RF), instruction execution (EX), memory access (MEM), and register writeback (WB) with stage latencies 1 ns, 2.2 ns, 2 ns, 1 ns, and 0.75 ns, respectively (ns stands for nanoseconds). To gain in terms of frequency, the designers have decided to split the ID/RF stage into three stages (ID, RF1, RF2) each of latency 2.2/3 ns. Also, the EX stage is split into two stages (EX1, EX2) each of latency 1 ns. The new design has a total of eight pipeline stages. A program has 20% branch instructions which execute in the EX stage and produce the next instruction pointer at the end of the EX stage in the old design and at the end of the EX2 stage in the new design. The IF stage stalls after fetching a branch instruction until the next instruction pointer is computed. All instructions other than the branch instruction have an average CPI of one in both the designs. The execution times of this program on the old and the new design are P and Q nanoseconds, respectively. The value of P/Q is __________.

Answer: 1.5 to 1.6 - show solution

Old design: clock = slowest stage = 2.2 ns. A branch resolves at the end of EX (stage 3), so the next fetch waits 2 extra cycles. CPI = 0.8 × 1 + 0.2 × 3 = 1.4. Time per instruction = 1.4 × 2.2 = 3.08 ns. New design: stages IF 1, ID 0.733, RF1 0.733, RF2 0.733, EX1 1, EX2 1, MEM 1, WB 0.75; clock = 1 ns. A branch resolves at the end of EX2 (stage 6), a 5-cycle stall. CPI = 0.8 × 1 + 0.2 × 6 = 2.0. Time per instruction = 2.0 ns. P/Q = 3.08 / 2.0 = 1.54. Answer: 1.54 (official range 1.50 to 1.60).

Concept: Deeper pipelines raise frequency but enlarge the branch penalty. The trap is counting the penalty as the branch's stage number instead of stage number minus one.

Q54NAT2 marks · no negative· Moderate

The memory access time is 1 nanosecond for a read operation with a hit in cache, 5 nanoseconds for a read operation with a miss in cache, 2 nanoseconds for a write operation with a hit in cache and 10 nanoseconds for a write operation with a miss in cache. Execution of a sequence of instructions involves 100 instruction fetch operations, 60 memory operand read operations and 40 memory operand write operations. The cache hit-ratio is 0.9. The average memory access time (in nanoseconds) in executing the sequence of instructions is __________.

Answer: 1.68 - show solution

Instruction fetches are reads: 100 + 60 = 160 reads, 40 writes, 200 accesses in all. Average read time = 0.9 × 1 + 0.1 × 5 = 1.4 ns. Average write time = 0.9 × 2 + 0.1 × 10 = 2.8 ns. Total = 160 × 1.4 + 40 × 2.8 = 224 + 112 = 336 ns. Average = 336 / 200 = 1.68 ns. Answer: 1.68.

Concept: Weighted average memory access time over reads and writes. The trap is forgetting that instruction fetches are read operations, or averaging the read and write times without weighting.

Q55MCQ2 marks · -2/3· Moderate

The synchronous sequential circuit below is built using three JK flip-flops with outputs Q₂, Q₁, Q₀, all driven by the same clock C. Its connections are: J₂ = Q̄₁, K₂ = Q₀ J₁ = Q₂, K₁ = Q̄₂ J₀ = Q₁, K₀ = Q̄₀ The circuit is initialized with Q₂Q₁Q₀ = 000. The state sequence for this circuit for the next 3 clock cycles is

  1. (A)001, 010, 011
  2. (B)111, 110, 101
  3. (C)100, 110, 111
  4. (D)100, 011, 001
Answer: C - show solution

JK rules: J=1,K=0 sets; J=0,K=1 resets; J=K=1 toggles; J=K=0 holds. From 000: J₂=Q̄₁=1, K₂=Q₀=0 -> Q₂=1. J₁=Q₂=0, K₁=1 -> Q₁=0. J₀=Q₁=0, K₀=Q̄₀=1 -> Q₀=0. State 100. From 100: J₂=1, K₂=0 -> 1. J₁=1, K₁=0 -> 1. J₀=0, K₀=1 -> 0. State 110. From 110: J₂=0, K₂=0 -> hold 1. J₁=1, K₁=0 -> 1. J₀=1, K₀=1 -> toggle to 1. State 111. Answer: (C) 100, 110, 111.

Concept: Next-state analysis of JK flip-flops using the present state for every input simultaneously. The trap is updating one flip-flop and then using its new value for the next one within the same clock.

Q58NAT2 marks · no negative· Easy

Let S be a sample space and two mutually exclusive events A and B be such that A ∪ B = S. If P(·) denotes the probability of the event, the maximum value of P(A)P(B) is __________.

Answer: 0.25 - show solution

Mutually exclusive and exhaustive: P(A) + P(B) = P(S) = 1. Let P(A) = p, so P(B) = 1 - p and the product is p(1 - p). This is maximised at p = 1/2 (derivative 1 - 2p = 0), giving 1/4. Answer: 0.25.

Concept: Complementary events and maximising p(1 - p). The trap is treating A and B as independent, which contradicts their being mutually exclusive with positive probabilities.

Q63MCQ2 marks · -2/3· Easy

The CORRECT formula for the sentence, "not all rainy days are cold" is

  1. (A)∀d (Rainy(d) ∧ ¬Cold(d))
  2. (B)∀d (¬Rainy(d) → Cold(d))
  3. (C)∃d (¬Rainy(d) → Cold(d))
  4. (D)∃d (Rainy(d) ∧ ¬Cold(d))
Answer: D - show solution

"All rainy days are cold" is ∀d (Rainy(d) → Cold(d)). Negating it: ¬∀d (Rainy(d) → Cold(d)) ≡ ∃d ¬(Rainy(d) → Cold(d)) ≡ ∃d (Rainy(d) ∧ ¬Cold(d)): there is a rainy day that is not cold. Answer: (D).

Concept: Negation of a universally quantified implication. The trap is option A, which says every day is rainy and not cold.

Q64MCQ2 marks · -2/3· Easy

Consider the following relational schema: employee(empId, empName, empDept) customer(custId, custName, salesRepId, rating) salesRepId is a foreign key referring to empId of the employee relation. Assume that each employee makes a sale to at least one customer. What does the following query return?

SELECT empName
FROM employee E
WHERE NOT EXISTS (SELECT custId
                  FROM customer C
                  WHERE C.salesRepId = E.empId
                  AND C.rating <> 'GOOD');
  1. (A)Names of all the employees with at least one of their customers having a 'GOOD' rating.
  2. (B)Names of all the employees with at most one of their customers having a 'GOOD' rating.
  3. (C)Names of all the employees with none of their customers having a 'GOOD' rating.
  4. (D)Names of all the employees with all their customers having a 'GOOD' rating.
Answer: D - show solution

For each employee E, the subquery lists E's customers whose rating is not 'GOOD'. NOT EXISTS keeps E only when that list is empty, i.e. E has no customer with a non-GOOD rating. Since every employee has at least one customer, this means all of E's customers are rated 'GOOD'. Answer: (D).

Concept: NOT EXISTS over a negated condition expresses universal quantification. The trap is option C, which ignores the <> in the subquery.

Answers are the official GATE answer key. Questions that depend on a figure are left out until they can be shown faithfully.