GATE CS 2021 Set 2 — All 65 Questions with Solutions

Computer Science (CS). Every question from this paper with the official answer key and a step-by-step solution. 100 marks total.

  1. Question 1General Aptitudemcq1 mark
    Gauri said that she can play the keyboard ______ her sister. Which one of the following options fills the blank correctly?
    • A.
      as well as
      ✓
    • B.
      as better as
    • C.
      as nicest as
    • D.
      as worse as

    Answer: A

    Solution

    The correct comparative idiom for equal ability is "as well as".
  2. Question 2General Aptitudemcq1 mark
    A transparent square sheet (shown in the figure) is folded along the dotted line. The folded sheet will look like ______. (See the figure for the sheet and options (A)–(D).)
    GATE CS 2021 Set 2 Question 2 figure
    • A.
      (A)
    • B.
      (B)
      ✓
    • C.
      (C)
    • D.
      (D)

    Answer: B

    Solution

    Folding the transparent sheet along the vertical dotted line superimposes the pattern of the right half onto the left; the resulting overlapped figure matches option (B).
  3. Question 3General Aptitudemcq1 mark
    The longest diagonal of a cube makes an angle with an edge of the cube that meets it at a vertex. The value of is ______.
    • A.
    • B.
      ✓
    • C.
    • D.

    Answer: B

    Solution

    For a unit cube, an edge vector is and the body diagonal is of length . .
  4. Question 4General Aptitudemcq1 mark
    Consider the following equation.
    The value of is ______.
    • A.
      2
    • B.
      4
      ✓
    • C.
      6
    • D.
      8

    Answer: B

    Solution

    Using with : .
  5. Question 5General Aptitudemcq1 mark
    Pen : Write :: Knife : ______ Which one of the following options maintains a similar logical relation in the above?
    • A.
      Vegetables
    • B.
      Sharp
    • C.
      Cut
      ✓
    • D.
      Blunt

    Answer: C

    Solution

    A pen is used to write; a knife is used to cut. The relation is tool : function, so the answer is "Cut".
  6. Question 6General Aptitudemcq2 marks
    Listening to music during exercise improves exercise performance and reduces discomfort. Scientists researched whether listening to music while studying can improve learning. They compared learning in two groups: one studied with music and the other without. Which one of the following options is the CORRECT inference of this experiment?
    • A.
      Listening to music has no effect on learning and a positive effect on physical exercise performance.
    • B.
      Listening to music has a clear positive effect both on physical exercise and on learning.
    • C.
      Listening to music has a clear positive effect on physical exercise performance. Music has an effect on learning, but it is not clear from the given information whether the effect is positive or negative.
      ✓
    • D.
      Listening to music has a clear positive effect on learning, but not on physical exercise performance.

    Answer: C

    Solution

    The passage states music clearly helps exercise performance, but the study on learning only compares two groups without stating the direction of the result, so the effect on learning cannot be determined as positive or negative — option (C).
  7. Question 7General Aptitudemcq2 marks
    A jigsaw puzzle has 2 pieces. One of the pieces is shown in the figure. Which one of the given options for the missing piece, when assembled, will form a rectangle? The piece can be moved, rotated or flipped to assemble with the shown piece. (See the figure for the given piece and options (A)–(D).)
    GATE CS 2021 Set 2 Question 7 figure
    • A.
      (A)
      ✓
    • B.
      (B)
    • C.
      (C)
    • D.
      (D)

    Answer: A

    Solution

    The missing piece must be the complement of the shown piece so that the two interlock into a rectangle. Matching every notch and tab (allowing rotation/flip) selects option (A).
  8. Question 8General Aptitudemcq2 marks
    The number of students in three classes is in the ratio . If 18 students are added to each class, the ratio changes to . The total number of students in all the three classes in the beginning was:
    • A.
      22
    • B.
      66
    • C.
      88
      ✓
    • D.
      110

    Answer: C

    Solution

    Let the counts be . From : . Total .
  9. Question 9General Aptitudemcq2 marks
    The number of units of a product sold in three different years and the respective net profits are presented in the figure. The cost/unit in Year 3 was Rs 1, which was half the cost/unit in Year 2. The cost/unit in Year 3 was one-third of the cost/unit in Year 1. Taxes were paid on the selling price at 10%, 13% and 15% respectively for the three years. Net profit is calculated as the difference between the selling price and the sum of cost and taxes paid in that year. The ratio of the selling price in Year 2 to the selling price in Year 3 is ______.
    GATE CS 2021 Set 2 Question 9 figure
    • A.
      ✓
    • B.
    • C.
    • D.

    Answer: A

    Solution

    Selling price = cost + taxes + net profit, with tax a fixed fraction of selling price. Computing SP for Year 2 and Year 3 from the chart values (units, net profit) and the given per-unit costs and tax rates gives the ratio .
  10. Question 10General Aptitudemcq2 marks
    Six students P, Q, R, S, T and U, with distinct heights, compare their heights and make the following observations. Observation I: S is taller than R. Observation II: Q is the shortest of all. Observation III: U is taller than only one student. Observation IV: T is taller than S but is not the tallest. The number of students that are taller than R is the same as the number of students shorter than ______.
    • A.
      T
    • B.
      R
    • C.
      S
      ✓
    • D.
      P

    Answer: C

    Solution

    From the observations the order (tallest to shortest) is P, T, S, R, U, Q. The number taller than R is 3 (P, T, S); the number shorter than S is also 3 (R, U, Q). So the answer is S.
  11. Question 11Algorithmsmcq1 mark
    Let be a connected undirected weighted graph. Consider the following two statements. : There exists a minimum weight edge in which is present in every minimum spanning tree of . : If every edge in has distinct weight, then has a unique minimum spanning tree. Which one of the following options is correct?
    • A.
      Both and are true
    • B.
      is true and is false
    • C.
      is false and is true
      ✓
    • D.
      Both and are false

    Answer: C

    Solution

    If several edges share the minimum weight (e.g. a triangle of equal weights), no single minimum-weight edge lies in every MST, so is false. Distinct edge weights force a unique MST, so is true.
  12. Question 12Programming & Data Structuresmcq1 mark
    Consider a binary min-heap containing distinct elements stored as an array. What is the worst-case time complexity to find the maximum element in the heap?
    • A.
    • B.
    • C.
      ✓
    • D.

    Answer: C

    Solution

    In a min-heap the maximum can be any of the leaves, so all leaves must be examined, requiring time.
  13. Question 13Compiler Designmcq1 mark
    Consider the following ANSI C program.
    int main() {
        Integer x;
        return 0;
    }
    Which one of the following phases of a compiler will detect the error (if any) in the above program?
    • A.
      Lexical analyzer
    • B.
      Syntax analyzer
    • C.
      Semantic analyzer
      ✓
    • D.
      Machine dependent code optimizer

    Answer: C

    Solution

    Integer is a valid identifier token (passes lexical analysis) and Integer x; is syntactically a valid declaration form (passes parsing). The error — that Integer is not a declared type — is caught during semantic analysis.
  14. Question 14Digital Logicmcq1 mark
    Consider a single-precision floating point format (IEEE 754) with 1 sign bit, 8 exponent bits (bias 127), and 23 mantissa bits. Which one of the following choices gives the representation of the smallest positive normalized number?
    • A.
      Exponent all zeros, mantissa all zeros
    • B.
      Exponent all zeros, mantissa all ones
    • C.
      Exponent = 00000001, mantissa all zeros
      ✓
    • D.
      Exponent = 11111110, mantissa all ones

    Answer: C

    Solution

    The smallest positive normalized number uses the smallest valid normalized exponent field with the mantissa all zeros, giving .
  15. Question 15Digital Logicmcq1 mark
    Which one of the following circuits implements the Boolean function given below, where is the minterm?
    (See the figure for the 4x1 MUX options (A)–(D); the select lines are , .)
    GATE CS 2021 Set 2 Question 15 figure
    • A.
      (A)
      ✓
    • B.
      (B)
    • C.
      (C)
    • D.
      (D)

    Answer: A

    Solution

    With on the select lines, the four data inputs (for ) must each be the residue of in terms of : . Only option (A) wires the inputs as .
  16. Question 16Databasesmcq1 mark
    Consider the following statements and about the relational data model. : A relation scheme can have at most one foreign key. : A foreign key in a relation scheme cannot be used to refer to tuples of . Which one of the following choices is correct?
    • A.
      Both and are true
    • B.
      is true and is false
    • C.
      is false and is true
    • D.
      Both and are false
      ✓

    Answer: D

    Solution

    A relation can declare several foreign keys, so is false. A foreign key may be self-referencing (refer to tuples of the same relation ), so is false.
  17. Question 17Computer Networksmcq1 mark
    Consider the three-way handshake mechanism followed during TCP connection establishment between hosts P and Q. Let X and Y be two random 32-bit starting sequence numbers chosen by P and Q respectively. Suppose P sends a TCP connection request message with the SYN bit set, SEQ number X, and ACK bit set to 0 to Q. Suppose Q accepts the connection request. Which one of the following choices represents the information present in the TCP segment header that is sent by Q to P?
    • A.
      The ACK bit is set to 0, SYN bit is set to 1, SEQ number is Y, and ACK number is X.
    • B.
      The ACK bit is set to 0, SYN bit is set to 0, SEQ number is Y, and ACK number is X.
    • C.
      The ACK bit is set to 1, SYN bit is set to 1, SEQ number is Y, and ACK number is X+1.
      ✓
    • D.
      The ACK bit is set to 1, SYN bit is set to 0, SEQ number is Y+1, and ACK number is X.

    Answer: C

    Solution

    The second handshake segment (SYN-ACK) has SYN=1 and ACK=1, carries Q's own initial sequence number Y, and acknowledges P's SYN with ACK number .
  18. Question 18Algorithmsmcq1 mark
    Consider a standard recursive binary search on a sorted array of elements. In the worst case, the number of comparison operations performed is:
    • A.
    • B.
      ✓
    • C.
    • D.

    Answer: B

    Solution

    Binary search halves the search range each step, performing operations in the worst case.
  19. Question 19Theory of Computationmcq1 mark
    Let be a regular language whose minimal DFA has exactly states. Which one of the following languages is guaranteed to have a minimal DFA with exactly states?
    • A.
    • B.
    • C.
      (the complement of )
      ✓
    • D.

    Answer: C

    Solution

    Complementing a DFA only swaps accepting and non-accepting states, keeping the same (already minimal) set of states, so the complement also has exactly states.
  20. Question 20Programming & Data Structuresmcq1 mark
    Consider the following ANSI C program.
    #include <stdio.h>
    int main() {
        int arr[4][5];
        int i, j;
        for (i = 0; i < 4; i++)
            for (j = 0; j < 5; j++)
                arr[i][j] = 10 * i + j;
        printf("%d", *(arr[1] + 9));
        return 0;
    }
    The output of the program is ______.
    • A.
      14
    • B.
      20
    • C.
      24
      ✓
    • D.
      30

    Answer: C

    Solution

    arr[1] points to arr[1][0]. Adding 9 (row-major) reaches element at offset 9, i.e. arr[2][4] (row length 5: ). Its value is .
  21. Question 21Discrete Mathematicsmsq1 mark
    Let be the set of all matrices whose entries are from the set , and let be the set of all functions from the set to the set . Which of the following choices is/are correct?
    • A.
      There does not exist a bijection from to .
    • B.
      There exists a surjection from to .
      ✓
    • C.
      There exists a bijection from to .
      ✓
    • D.
      There does not exist an injection from to .

    Answer: B, C

    Solution

    Both sets have cardinality (: three choices for each of entries; : three choices for each of inputs). Equal finite cardinalities give a bijection (C) and hence also a surjection (B).
  22. Question 22Theory of Computationmsq1 mark
    Let be a regular language and be a context-free language. Which of the following languages is/are context-free?
    • A.
    • B.
      ✓
    • C.
      ✓
    • D.
      ✓

    Answer: B, C, D

    Solution

    , so (C) is — regular, hence context-free. In (D), and are each (regular CFL) = CFL, and the union of CFLs is a CFL. Per the official GATE key, (B) is also accepted. Option (A) () need not be context-free.
  23. Question 23Compiler Designmsq1 mark
    In the context of compilers, which of the following is/are NOT an intermediate representation of the source program?
    • A.
      Three address code
    • B.
      Abstract Syntax Tree (AST)
    • C.
      Control Flow Graph (CFG)
    • D.
      Symbol table
      ✓

    Answer: D

    Solution

    Three-address code, the AST and the CFG are all intermediate representations of the program. The symbol table is an auxiliary data structure storing identifier information, not an intermediate representation of the source program.
  24. Question 24Operating Systemsmsq1 mark
    Which of the following statement(s) is/are correct in the context of CPU scheduling?
    • A.
      Turnaround time includes waiting time.
      ✓
    • B.
      The goal is to only maximize CPU utilization and minimize throughput.
    • C.
      Round-robin policy can be used even when the CPU time required by each of the processes is not known apriori.
      ✓
    • D.
      Implementing preemptive scheduling needs hardware support.
      ✓

    Answer: A, C, D

    Solution

    Turnaround time = waiting + burst (+ I/O) time, so (A) is true. The goal is to maximize throughput, not minimize it, so (B) is false. Round-robin needs no prior knowledge of burst lengths (C true). Preemption relies on a timer interrupt, i.e. hardware support (D true).
  25. Question 25Discrete Mathematicsmsq1 mark
    Choose the correct choice(s) regarding the following propositional logic assertion :
    • A.
      is neither a tautology nor a contradiction.
    • B.
      is a tautology.
      ✓
    • C.
      is a contradiction.
    • D.
      The antecedent of is logically equivalent to the consequent of .
      ✓

    Answer: B, D

    Solution

    When is true, both and reduce to ; when is false, both are true. So the antecedent and consequent are logically equivalent (D), making of the form , a tautology (B).
  26. Question 26Programming & Data Structuresnat1 mark
    Consider a complete binary tree with 7 nodes. Let denote the set of first 3 elements obtained by performing Breadth-First Search (BFS) starting from the root. Let denote the set of first 3 elements obtained by performing Depth-First Search (DFS) starting from the root. The value of is ______.

    Answer: 1

    Solution

    Number the nodes (root), (level 1), (level 2). BFS first three: . DFS first three: . , so .
  27. Question 27Theory of Computationnat1 mark
    Consider the deterministic finite automaton (DFA) shown in the figure. The number of strings of length 8 accepted by the above automaton is ______.
    GATE CS 2021 Set 2 Question 27 figure

    Answer: 256

    Solution

    From the start state, after reading any two symbols the automaton reaches the accepting state, and the accepting state has self-loops on both and . Hence every string of length is accepted; for length 8 there are strings.
  28. Question 28Digital Logicnat1 mark
    If and are two decimal digits and , the decimal value of is ______.

    Answer: 3

    Solution

    . So , giving and .
  29. Question 29Computer Organization & Architecturenat1 mark
    Consider a set-associative cache of size 2KB ( bytes) with cache block size of 64 bytes. Assume that the cache is byte-addressable and a 32-bit address is used for accessing the cache. If the width of the tag field is 22 bits, the associativity of the cache is ______.

    Answer: 2

    Solution

    Block offset bits, so set-index bits sets. Total blocks . Associativity .
  30. Question 30Computer Organization & Architecturenat1 mark
    Consider a computer system with DMA support. The DMA module is transferring one 8-bit character in one CPU cycle from a device to memory through cycle stealing at regular intervals. Consider a 2 MHz processor. If 0.5% processor cycles are used for DMA, the data transfer rate of the device is ______ bits per second.

    Answer: 80000

    Solution

    DMA cycles per second . Each carries 8 bits, so the rate bits per second.
  31. Question 31Databasesnat1 mark
    A data file consisting of 1,50,000 student-records is stored on a hard disk with block size of 4096 bytes. The data file is sorted on the primary key RollNo. The size of a record pointer for this disk is 7 bytes. Each student-record has a candidate key attribute called ANum of size 12 bytes. Suppose an index file with records consisting of two fields, ANum value and the record pointer to the corresponding student record, is built and stored on the same disk. Assume that the records of the data file and index file are not split across disk blocks. The number of blocks in the index file is ______.

    Answer: 698

    Solution

    Index record size bytes; records per block . Since ANum is a candidate key, the index is dense with 150000 entries, needing blocks.
  32. Question 32Engineering Mathematicsnat1 mark
    For a given biased coin, the probability that the outcome of a toss is a head is 0.4. This coin is tossed 1,000 times. Let denote the random variable whose value is the number of times that head appeared in these 1,000 tosses. The standard deviation of (rounded to 2 decimal places) is ______.

    Answer: 15 to 16

    Solution

    , so .
  33. Question 33Programming & Data Structuresnat1 mark
    Consider the following ANSI C function.
    int SomeFunction(int x, int y) {
        if ((x == 1) || (y == 1)) return 1;
        if (x == y) return x;
        if (x > y) return SomeFunction(x - y, y);
        if (y > x) return SomeFunction(x, y - x);
    }
    The value returned by SomeFunction(15, 255) is ______.

    Answer: 15

    Solution

    The function performs the subtractive Euclidean algorithm, returning (with 1 as the base case). .
  34. Question 34Engineering Mathematicsnat1 mark
    Suppose that is a matrix such that every solution of the equation is a scalar multiple of . The rank of is ______.

    Answer: 4

    Solution

    The null space is one-dimensional, so nullity . By rank–nullity on 5 columns, rank .
  35. Question 35Engineering Mathematicsnat1 mark
    Suppose that is a continuous function on the interval and a differentiable function in the interval such that for every in the interval, . If , then is at most ______.

    Answer: 19

    Solution

    By the Mean Value Theorem, , so .
  36. Question 36Algorithmsmcq2 marks
    Consider the string abbccddeee. Each letter in the string must be assigned a binary code satisfying the following properties: 1. For any two letters, the code assigned to one letter must not be a prefix of the code assigned to the other letter. 2. For any two letters of the same frequency, the letter which occurs earlier in the dictionary order is assigned a code whose length is at most the length of the code assigned to the other letter. Among the set of all binary code assignments which satisfy the above two properties, what is the minimum length of the encoded string?
    • A.
      21
    • B.
      23
      ✓
    • C.
      25
    • D.
      30

    Answer: B

    Solution

    Frequencies: . Building an optimal prefix (Huffman) code and summing (frequency code length) gives the minimum total length of 23 bits.
  37. Question 37Computer Organization & Architecturemcq2 marks
    Assume a two-level inclusive cache hierarchy, L1 and L2, where L2 is the larger of the two. Consider the following statements. : Read misses in a write through L1 cache do not result in writebacks of dirty lines to the L2. : Write allocate policy must be used in conjunction with write through caches and no-write allocate policy is used with writeback caches. Which of the following statements is correct?
    • A.
      is true and is false
      ✓
    • B.
      is false and is true
    • C.
      is true and is true
    • D.
      is false and is false

    Answer: A

    Solution

    A write-through L1 never holds dirty lines (writes propagate immediately), so a read miss causes no writeback — is true. Write-allocate and no-write-allocate can be paired with either write policy; the "must" claim is false, so is false.
  38. Question 38Digital Logicmcq2 marks
    Suppose we want to design a synchronous circuit that processes a string of 0's and 1's. Given a string, it produces another string by replacing the first 1 in any subsequence of consecutive 1's by a 0. For example, input 00100011000011100 produces output 00000001000001100. The circuit is a two-state Mealy machine with states represented by Boolean values 0 and 1. Let denote the current state, next state, the next incoming bit, and the output bit respectively. The initial state is 0. What are the Boolean expressions for and in terms of and ?
    • A.
    • B.
      ✓
    • C.
    • D.

    Answer: B

    Solution

    State 1 means "currently inside a run of 1s (first 1 already replaced)". Next state is 1 exactly when the incoming bit , so . The output is 1 (keep the bit) only when already inside a run and the bit is 1, i.e. ; the first 1 of a run () is output as 0.
  39. Question 39Algorithmsmcq2 marks
    In an examination, a student can choose the order in which two questions (QuesA and QuesB) must be attempted. - If the first question is answered wrong, the student gets zero marks. - If the first question is answered correctly and the second question is not answered correctly, the student gets the marks only for the first question. - If both the questions are answered correctly, the student gets the sum of the marks of the two questions. The following table shows the probability of correctly answering a question and the marks of the question respectively.
    question   probability of answering correctly   marks
    QuesA               0.8                          10
    QuesB               0.5                          20
    Assuming that the student always wants to maximize her expected marks, in which order should she attempt the questions and what is the expected marks for that order (assume that the questions are independent)?
    • A.
      First QuesA and then QuesB. Expected marks 14.
    • B.
      First QuesB and then QuesA. Expected marks 14.
    • C.
      First QuesB and then QuesA. Expected marks 22.
    • D.
      First QuesA and then QuesB. Expected marks 16.
      ✓

    Answer: D

    Solution

    Order A then B: . Order B then A: . The larger is 16, attempting QuesA first.
  40. Question 40Compiler Designmcq2 marks
    Consider the following ANSI C code segment:
    z = x + 3 + y->f1 + y->f2;
    for (i = 0; i < 200; i = i + 2) {
        if (z > i) {
            p = p + x + 3;
            q = q + y->f1;
        } else {
            p = p + y->f2;
            q = q + x + 3;
        }
    }
    Assume that y points to a struct (allocated on the heap) with two fields f1 and f2, and that the local variables x, y, z, p, q, i are allotted registers. Common sub-expression elimination (CSE) is applied. The number of addition operations and dereference operations (of the form y->f1 or y->f2) in the optimized code, respectively, are:
    • A.
      403 and 102
    • B.
      203 and 2
    • C.
      303 and 102
    • D.
      303 and 2
      ✓

    Answer: D

    Solution

    The dereferences y->f1 and y->f2 are loop-invariant and computed once (2 total) after CSE. Counting the additions that remain after eliminating the common subexpression x+3 across the loop's 100 iterations gives 303 additions. Hence 303 and 2.
  41. Question 41Databasesmcq2 marks
    The relation scheme stores employee information, where empId is the key and deptId is the department to which the employee is assigned. Each employee is assigned to exactly one department.
    emp(empId, name, gender, salary, deptId)
    Consider the SQL query:
    select deptId, count(*)
    from emp
    where gender = "female" and salary > (select avg(salary) from emp)
    group by deptId;
    The above query gives, for each department in the company, the number of female employees whose salary is greater than the average salary of:
    • A.
      employees in the department.
    • B.
      employees in the company.
      ✓
    • C.
      female employees in the department.
    • D.
      female employees in the company.

    Answer: B

    Solution

    The subquery (select avg(salary) from emp) is uncorrelated and computes the average salary over all employees in the company, so the comparison is against the company-wide average.
  42. Question 42Databasesmcq2 marks
    Let be the following schedule of operations of three transactions and in a relational database system:
    Consider the statements P and Q below: P: is conflict-serializable. Q: If commits before finishes, then is recoverable. Which one of the following choices is correct?
    • A.
      Both P and Q are true
    • B.
      P is true and Q is false
      ✓
    • C.
      P is false and Q is true
    • D.
      Both P and Q are false

    Answer: B

    Solution

    The precedence graph of is acyclic, so is conflict-serializable (P true). reads after writes ; if commits before , the schedule is not recoverable (Q false).
  43. Question 43Engineering Mathematicsmcq2 marks
    A bag has red balls and black balls. All balls are identical except for their colours. In a trial, a ball is randomly drawn from the bag, its colour is noted and the ball is placed back into the bag along with another ball of the same colour. Note that the number of balls in the bag increases by one after the trial. A sequence of four such trials is conducted. Which one of the following choices gives the probability of drawing a red ball in the fourth trial?
    • A.
      ✓
    • B.
    • C.
    • D.

    Answer: A

    Solution

    In a Polya urn the draws are exchangeable, so the marginal probability of drawing red at any trial equals the initial proportion .
  44. Question 44Computer Networksmcq2 marks
    Consider the cyclic redundancy check (CRC) based error detecting scheme having the generator polynomial . Suppose the message is to be transmitted. Check bits are appended at the end of the message by the transmitter using the above CRC scheme. The transmitted bit string is denoted by . The value of the checkbit sequence is:
    • A.
      101
    • B.
      110
    • C.
      100
      ✓
    • D.
      111

    Answer: C

    Solution

    The generator is . Appending 3 zeros gives ; dividing modulo-2 by leaves remainder . So .
  45. Question 45Programming & Data Structuresmcq2 marks
    Consider the following ANSI C program.
    #include <stdio.h>
    #include <stdlib.h>
    struct Node { int value; struct Node *next; };
    int main() {
        struct Node *boxE, *head, *boxN; int index = 0;
        boxE = head = (struct Node *) malloc(sizeof(struct Node));
        head->value = index;
        for (index = 1; index <= 3; index++) {
            boxN = (struct Node *) malloc(sizeof(struct Node));
            boxE->next = boxN;
            boxN->value = index;
            boxE = boxN;
        }
        for (index = 0; index <= 3; index++) {
            printf("Value at index %d is %d\n", index, head->value);
            head = head->next;
            printf("Value at index %d is %d\n", index + 1, head->value);
        }
    }
    Which one of the statements below is correct about the program?
    • A.
      Upon execution, the program creates a linked-list of five nodes.
    • B.
      Upon execution, the program goes into an infinite loop.
    • C.
      It has a missing return which will be reported as an error by the compiler.
    • D.
      It dereferences an uninitialized pointer that may result in a run-time error.
      ✓

    Answer: D

    Solution

    The list has 4 nodes; the last node's next is never initialized. In the final iteration head = head->next follows that uninitialized pointer and the subsequent head->value dereferences it, causing a possible run-time error.
  46. Question 46Theory of Computationmcq2 marks
    Consider the following two statements about regular languages. : Every infinite regular language contains an undecidable language as a subset. : Every finite language is regular. Which one of the following choices is correct?
    • A.
      Only is true
    • B.
      Only is true
    • C.
      Both and are true
      ✓
    • D.
      Neither nor is true

    Answer: C

    Solution

    An infinite language has uncountably many subsets but only countably many are decidable, so it must contain an undecidable subset — is true. Every finite language is regular (a finite union of single-string languages) — is true.
  47. Question 47Engineering Mathematicsmcq2 marks
    For two -dimensional real vectors and , the operation is defined as follows:
    Let be a set of 10-dimensional non-zero real vectors such that for every pair of distinct vectors , . What is the maximum cardinality possible for the set ?
    • A.
      9
    • B.
      10
      ✓
    • C.
      11
    • D.
      100

    Answer: B

    Solution

    is the dot product; the set contains pairwise orthogonal non-zero vectors. In at most 10 vectors can be mutually orthogonal, so the maximum cardinality is 10.
  48. Question 48Compiler Designmcq2 marks
    For a statement in a program, in the context of liveness analysis, the following sets are defined: : the set of variables used in . : the set of variables that are live at the entry of . : the set of variables that are live at the exit of . Consider a basic block that consists of two statements, followed by . Which one of the following statements is correct?
    • A.
      ✓
    • B.
    • C.
    • D.

    Answer: A

    Solution

    Within a straight-line basic block, the point after is exactly the point before , so the variables live at the exit of equal those live at the entry of : .
  49. Question 49Algorithmsmcq2 marks
    For constants and , consider the following recurrence defined on the non-negative integers:
    Which one of the following options is correct about the recurrence ?
    • A.
      If is , then is .
    • B.
      If is , then is .
    • C.
      If is for some , then is .
      ✓
    • D.
      If is , then is .

    Answer: C

    Solution

    This is Master theorem Case 1: if then — option (C). (Case 2 with gives an extra factor, so (D) is wrong.)
  50. Question 50Databasesmsq2 marks
    Suppose the following functional dependencies hold on a relation with attributes and :
    Which of the following functional dependencies can be inferred from the above functional dependencies?
    • A.
      ✓
    • B.
    • C.
      ✓
    • D.
      ✓

    Answer: A, C, D

    Solution

    From we get (C) and , hence (D). Also , so (A). But needs as well, so (B) cannot be inferred.
  51. Question 51Theory of Computationmsq2 marks
    For a string , we define to be the reverse of . For example, if then . Which of the following languages is/are context-free?
    • A.
    • B.
      ✓
    • C.
      ✓
    • D.
      ✓

    Answer: B, C, D

    Solution

    (B) is a concatenation of two even-palindrome languages and (D) is a nested palindrome structure — both CFL. (C) equals (take ), which is regular, hence CFL. (A) has crossing dependencies between the two reversed parts and is not context-free.
  52. Question 52Operating Systemsmsq2 marks
    Consider the following multi-threaded code segment (in a mix of C and pseudo-code), invoked by two processes P1 and P2, and each of the processes spawns two threads T1 and T2:
    int x = 0;   // global
    Lock L1;     // global
    main() {
        create a thread to execute foo();  // Thread T1
        create a thread to execute foo();  // Thread T2
        wait for the two threads to finish execution;
        print(x);
    }
    foo() {
        int y = 0;
        Acquire L1;
        x = x + 1;
        y = y + 1;
        Release L1;
        print(y);
    }
    Which of the following statement(s) is/are correct?
    • A.
      Both P1 and P2 will print the value of x as 2.
      ✓
    • B.
      At least one of P1 and P2 will print the value of x as 4.
    • C.
      At least one of the threads will print the value of y as 2.
    • D.
      Both T1 and T2, in both the processes, will print the value of y as 1.
      ✓

    Answer: A, D

    Solution

    Processes have separate address spaces, so each process's global x is incremented by its own two threads (under the lock) to 2 — (A) true, and (B) false (x is never shared to reach 4). y is a local variable, always ending at 1 — (D) true, (C) false.
  53. Question 53Operating Systemsmsq2 marks
    Consider a computer system with multiple shared resource types, with one instance per resource type. Each instance can be owned by only one process at a time. Owning and freeing of resources are done by holding a global lock (L). The following scheme is used to own a resource instance:
    function OwnResource(Resource R)
        Acquire lock L            // a global lock
        if R is available then
            Acquire R
            Release lock L
        else
            if R is owned by another process P then
                Terminate P, after releasing all resources owned by P
                Acquire R
                Restart P
                Release lock L
            end if
        end if
    end function
    Which of the following choice(s) about the above scheme is/are correct?
    • A.
      The scheme ensures that deadlocks will not occur.
      ✓
    • B.
      The scheme may lead to live-lock.
      ✓
    • C.
      The scheme may lead to starvation.
      ✓
    • D.
      The scheme violates the mutual exclusion property.

    Answer: A, B, C

    Solution

    Because a requester forcibly terminates the current owner, no circular wait can form, so deadlock cannot occur (A). But a repeatedly terminated-and-restarted process may keep being preempted, producing live-lock (B) and starvation (C). Resources are still acquired exclusively, so mutual exclusion is not violated (D false).
  54. Question 54Computer Organization & Architecturemsq2 marks
    If the numerical value of a 2-byte unsigned integer on a little endian computer is 255 more than that on a big endian computer, which of the following choice(s) represent(s) the unsigned integer on a little endian computer?
    • A.
      0x6665
      ✓
    • B.
      0x0001
    • C.
      0x4243
    • D.
      0x0100
      ✓

    Answer: A, D

    Solution

    Let the two stored bytes be (lower address) and . Little-endian value big-endian value , so . The little-endian value is then . () and () satisfy this; (B) and (C) do not.
  55. Question 55Computer Networksmsq2 marks
    Consider a computer network using the distance vector routing algorithm in its network layer. The partial topology is shown in the figure. The objective is to find the shortest-cost path from router to routers and . has three neighbours . During one iteration, measures its distance to as 3, 2 and 5 respectively. gets routing vectors indicating that the distance to from are 7, 6 and 5, and the distance to from are 4, 6 and 8 respectively. Which of the following statement(s) is/are correct with respect to the new routing table of , after updation during this iteration?
    GATE CS 2021 Set 2 Question 55 figure
    • A.
      The distance from to will be stored as 10.
    • B.
      The distance from to will be stored as 7.
      ✓
    • C.
      The next hop router for a packet from to is .
      ✓
    • D.
      The next hop router for a packet from to is .

    Answer: B, C

    Solution

    To : via , via , via ; minimum 8 via (so A false, C true). To : via , via , via ; minimum 7 via (so B true, D false).
  56. Question 56Algorithmsmsq2 marks
    Consider the directed graph shown in the figure. Which of the following is/are correct about the graph?
    GATE CS 2021 Set 2 Question 56 figure
    • A.
      The graph does not have a topological order.
      ✓
    • B.
      A depth-first traversal starting at vertex classifies three directed edges as back edges.
      ✓
    • C.
      The graph does not have a strongly connected component.
    • D.
      For each pair of vertices and , there is a directed path from to .

    Answer: A, B

    Solution

    The graph contains directed cycles, so it has no topological order (A true). A DFS from encounters three edges that go back to an ancestor, i.e. three back edges (B true). Every graph has strongly connected components (at least singletons), so (C) is false, and the graph is not strongly connected, so (D) is false.
  57. Question 57Theory of Computationmsq2 marks
    Which of the following regular expressions represent(s) the set of all binary numbers that are divisible by three? Assume that the string is divisible by three.
    • A.
      ✓
    • B.
      ✓
    • C.
      ✓
    • D.

    Answer: A, B, C

    Solution

    Building the DFA that tracks the remainder modulo 3 and converting it to a regular expression, options (A), (B) and (C) each generate exactly the binary strings whose value is divisible by 3 (including ); (D) does not.
  58. Question 58Operating Systemsnat2 marks
    Consider a three-level page table to translate a 39-bit virtual address to a physical address as shown below.
    <----------- 39-bit virtual address ----------->
    | Level 1 | Level 2 | Level 3 |   Page   |
    | offset  | offset  | offset  |  offset  |
    |  9 bits |  9 bits |  9 bits |  12 bits |
    The page size is 4KB ( bytes) and the page table entry size at every level is 8 bytes. A process is currently using 2GB ( bytes) virtual memory which is mapped to 2GB of physical memory. The minimum amount of memory required for the page table of across all levels is ______ KB.

    Answer: 4108

    Solution

    2GB bytes pages. Level-3 tables: tables, each 4KB KB. Level-2 tables: tables KB. Level-1: 1 table KB. Total KB.
  59. Question 59Programming & Data Structuresnat2 marks
    Consider the following ANSI C program.
    #include <stdio.h>
    int foo(int x, int y, int q) {
        if ((x <= 0) && (y <= 0)) return q;
        if (x <= 0) return foo(x, y - q, q);
        if (y <= 0) return foo(x - q, y, q);
        return foo(x, y - q, q) + foo(x - q, y, q);
    }
    int main() {
        int r = foo(15, 15, 10);
        printf("%d", r);
        return 0;
    }
    The output of the program upon execution is ______.

    Answer: 60

    Solution

    The recursion counts the number of monotone lattice paths (steps of size decreasing or ) from down to the base region, each contributing . Evaluating the recursion gives the output 60.
  60. Question 60Discrete Mathematicsnat2 marks
    Let be a set consisting of 10 elements. The number of tuples of the form such that and are subsets of , and is ______.

    Answer: 59049

    Solution

    For each element there are three mutually exclusive possibilities: in neither nor , in only, or in both and (it cannot be in but not ). So the count is .
  61. Question 61Compiler Designnat2 marks
    Consider the following augmented grammar with as the set of terminals.
    S' -> S
    S  -> S # c S
    S  -> S S
    S  -> S @
    S  -> < S >
    S  -> a
    S  -> b
    S  -> c
    Let . The number of items in the set is ______.

    Answer: 8

    Solution

    Computing gives the item plus the closure on ; taking on again reproduces the same kernel item with its closure, yielding 8 items in total.
  62. Question 62Digital Logicnat2 marks
    Consider a Boolean function such that
    The number of literals in the minimal sum-of-products expression of is ______.

    Answer: 6

    Solution

    Filling the K-map from the three partial specifications and minimizing gives a sum-of-products expression whose total literal count is 6.
  63. Question 63Computer Organization & Architecturenat2 marks
    Consider a pipelined processor with 5 stages: Instruction Fetch (IF), Instruction Decode (ID), Execute (EX), Memory Access (MEM) and Write Back (WB). Each stage, except the EX stage, takes one cycle. The ID stage merely decodes the instruction and the register read is performed in the EX stage. The EX stage takes one cycle for ADD and two cycles for MUL. Ignore pipeline register latencies. Consider the sequence of 8 instructions:
    ADD, MUL, ADD, MUL, ADD, MUL, ADD, MUL
    Every MUL is data-dependent on the ADD just before it, and every ADD (except the first) is data-dependent on the MUL just before it. Speedup = (execution time without operand forwarding) / (execution time with operand forwarding). The speedup achieved (rounded to 2 decimal places) is ______.

    Answer: 1.87 to 1.88

    Solution

    Counting cycles for the dependent ADD/MUL chain with and without operand forwarding (forwarding removes the stalls inserted to wait for register write-back) gives a speedup of approximately 1.87–1.88.
  64. Question 64Computer Networksnat2 marks
    Consider a network using the pure ALOHA medium access control protocol, where each frame is of length 1,000 bits. The channel transmission rate is 1 Mbps ( bits per second). The aggregate number of transmissions across all the nodes (including new frame transmissions and retransmitted frames due to collisions) is modelled as a Poisson process with a rate of 1,000 frames per second. Throughput is defined as the average number of frames successfully transmitted per second. The throughput of the network (rounded to the nearest integer) is ______.

    Answer: 130 to 140

    Solution

    Frame time ms, so the offered load . Pure ALOHA throughput frames per frame-time, i.e. frames per second.
  65. Question 65Algorithmsnat2 marks
    In a directed acyclic graph with a source vertex , the quality-score of a directed path is defined to be the product of the weights of the edges on the path. Further, for a vertex other than , the quality-score of is defined to be the maximum among the quality-scores of all the paths from to . The quality-score of is assumed to be 1. (See the figure for the weighted DAG.) The sum of the quality-scores of all the vertices in the graph shown is ______.
    GATE CS 2021 Set 2 Question 65 figure

    Answer: 929

    Solution

    Processing the vertices in topological order and taking, for each vertex, the maximum product of edge weights over all paths from , then summing these best scores across all vertices, gives 929.

Practice the full paper with a timer

Attempt GATE CS 2021 Set 2 in the exact GATE interface and get a detailed score and topic-wise analysis — free.

Create free account →