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.
- Question 1General Aptitudemcq1 markGauri 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". - A.
- Question 2General Aptitudemcq1 markA 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).)

- 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). - A.
- Question 3General Aptitudemcq1 markThe 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 . . - A.
- Question 4General Aptitudemcq1 markConsider the following equation.The value of is ______.
- A.2
- B.4✓
- C.6
- D.8
Answer: B
Solution
Using with : . - A.
- Question 5General Aptitudemcq1 markPen : 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". - A.
- Question 6General Aptitudemcq2 marksListening 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). - A.
- Question 7General Aptitudemcq2 marksA 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).)

- 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). - A.
- Question 8General Aptitudemcq2 marksThe 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 . - A.
- Question 9General Aptitudemcq2 marksThe 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 ______.

- 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 . - A.
- Question 10General Aptitudemcq2 marksSix 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. - A.
- Question 11Algorithmsmcq1 markLet 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. - A.
- Question 12Programming & Data Structuresmcq1 markConsider 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. - A.
- Question 13Compiler Designmcq1 markConsider the following ANSI C program.
Which one of the following phases of a compiler will detect the error (if any) in the above program?int main() { Integer x; return 0; }- A.Lexical analyzer
- B.Syntax analyzer
- C.Semantic analyzer✓
- D.Machine dependent code optimizer
Answer: C
Solution
Integeris a valid identifier token (passes lexical analysis) andInteger x;is syntactically a valid declaration form (passes parsing). The error — thatIntegeris not a declared type — is caught during semantic analysis. - A.
- Question 14Digital Logicmcq1 markConsider 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 . - A.
- Question 15Digital Logicmcq1 markWhich 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 , .)

- 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 . - A.
- Question 16Databasesmcq1 markConsider 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. - A.
- Question 17Computer Networksmcq1 markConsider 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 . - A.
- Question 18Algorithmsmcq1 markConsider 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. - A.
- Question 19Theory of Computationmcq1 markLet 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. - A.
- Question 20Programming & Data Structuresmcq1 markConsider the following ANSI C program.
The output of the program is ______.#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; }- A.14
- B.20
- C.24✓
- D.30
Answer: C
Solution
arr[1]points toarr[1][0]. Adding 9 (row-major) reaches element at offset 9, i.e.arr[2][4](row length 5: ). Its value is . - A.
- Question 21Discrete Mathematicsmsq1 markLet 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). - A.
- Question 22Theory of Computationmsq1 markLet 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. - A.
- Question 23Compiler Designmsq1 markIn 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. - A.
- Question 24Operating Systemsmsq1 markWhich 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). - A.
- Question 25Discrete Mathematicsmsq1 markChoose 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). - A.
- Question 26Programming & Data Structuresnat1 markConsider 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 . - Question 27Theory of Computationnat1 markConsider the deterministic finite automaton (DFA) shown in the figure. The number of strings of length 8 accepted by the above automaton is ______.

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. - Question 28Digital Logicnat1 markIf and are two decimal digits and , the decimal value of is ______.
Answer: 3
Solution
. So , giving and . - Question 29Computer Organization & Architecturenat1 markConsider 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 . - Question 30Computer Organization & Architecturenat1 markConsider 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. - Question 31Databasesnat1 markA 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. - Question 32Engineering Mathematicsnat1 markFor 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 . - Question 33Programming & Data Structuresnat1 markConsider the following ANSI C function.
The value returned byint 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); }SomeFunction(15, 255)is ______.Answer: 15
Solution
The function performs the subtractive Euclidean algorithm, returning (with 1 as the base case). . - Question 34Engineering Mathematicsnat1 markSuppose 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 . - Question 35Engineering Mathematicsnat1 markSuppose 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 . - Question 36Algorithmsmcq2 marksConsider 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. - A.
- Question 37Computer Organization & Architecturemcq2 marksAssume 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. - A.
- Question 38Digital Logicmcq2 marksSuppose 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
00100011000011100produces output00000001000001100. 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. - A.
- Question 39Algorithmsmcq2 marksIn 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.
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)?question probability of answering correctly marks QuesA 0.8 10 QuesB 0.5 20- 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. - A.
- Question 40Compiler Designmcq2 marksConsider the following ANSI C code segment:
Assume thatz = 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; } }ypoints to astruct(allocated on the heap) with two fieldsf1andf2, and that the local variablesx, y, z, p, q, iare allotted registers. Common sub-expression elimination (CSE) is applied. The number of addition operations and dereference operations (of the formy->f1ory->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 dereferencesy->f1andy->f2are loop-invariant and computed once (2 total) after CSE. Counting the additions that remain after eliminating the common subexpressionx+3across the loop's 100 iterations gives 303 additions. Hence 303 and 2. - A.
- Question 41Databasesmcq2 marksThe relation scheme stores employee information, where
empIdis the key anddeptIdis the department to which the employee is assigned. Each employee is assigned to exactly one department.
Consider the SQL query:emp(empId, name, gender, salary, 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:select deptId, count(*) from emp where gender = "female" and salary > (select avg(salary) from emp) group by deptId;- 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. - A.
- Question 42Databasesmcq2 marksLet 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). - A.
- Question 43Engineering Mathematicsmcq2 marksA 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 . - A.
- Question 44Computer Networksmcq2 marksConsider 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 . - A.
- Question 45Programming & Data Structuresmcq2 marksConsider the following ANSI C program.
Which one of the statements below is correct about the 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); } }- 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
returnwhich 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'snextis never initialized. In the final iterationhead = head->nextfollows that uninitialized pointer and the subsequenthead->valuedereferences it, causing a possible run-time error. - A.
- Question 46Theory of Computationmcq2 marksConsider 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. - A.
- Question 47Engineering Mathematicsmcq2 marksFor 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. - A.
- Question 48Compiler Designmcq2 marksFor 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 : . - A.
- Question 49Algorithmsmcq2 marksFor 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.) - A.
- Question 50Databasesmsq2 marksSuppose 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. - A.
- Question 51Theory of Computationmsq2 marksFor 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. - A.
- Question 52Operating Systemsmsq2 marksConsider 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:
Which of the following statement(s) is/are correct?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); }- 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 globalxis incremented by its own two threads (under the lock) to 2 — (A) true, and (B) false (x is never shared to reach 4).yis a local variable, always ending at 1 — (D) true, (C) false. - A.
- Question 53Operating Systemsmsq2 marksConsider 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:
Which of the following choice(s) about the above scheme is/are correct?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- 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). - A.
- Question 54Computer Organization & Architecturemsq2 marksIf 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. - A.
- Question 55Computer Networksmsq2 marksConsider 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?

- 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). - A.
- Question 56Algorithmsmsq2 marksConsider the directed graph shown in the figure. Which of the following is/are correct about the graph?

- 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. - A.
- Question 57Theory of Computationmsq2 marksWhich 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. - A.
- Question 58Operating Systemsnat2 marksConsider a three-level page table to translate a 39-bit virtual address to a physical address as shown below.
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.<----------- 39-bit virtual address -----------> | Level 1 | Level 2 | Level 3 | Page | | offset | offset | offset | offset | | 9 bits | 9 bits | 9 bits | 12 bits |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. - Question 59Programming & Data Structuresnat2 marksConsider the following ANSI C program.
The output of the program upon execution is ______.#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; }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. - Question 60Discrete Mathematicsnat2 marksLet 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 . - Question 61Compiler Designnat2 marksConsider the following augmented grammar with as the set of terminals.
Let . The number of items in the set is ______.S' -> S S -> S # c S S -> S S S -> S @ S -> < S > S -> a S -> b S -> cAnswer: 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. - Question 62Digital Logicnat2 marksConsider a Boolean function such thatThe 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. - Question 63Computer Organization & Architecturenat2 marksConsider 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:
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 ______.ADD, MUL, ADD, MUL, ADD, MUL, ADD, MULAnswer: 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. - Question 64Computer Networksnat2 marksConsider 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. - Question 65Algorithmsnat2 marksIn 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 ______.

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 →