CS and IT GATE 2025 SET-1 Questions with Answer

Ques 1 Algorithms


Let G be any undirected graph with positive edge weights, and T be a minimum spanning tree of G. For any two vertices, u and v, let d1(u,v) and d2(u,v) be the shortest distances between u and v in G and T, respectively. Which ONE of the options is CORRECT for all possible G, T, u and v?

A

d1(u,v)=d2(u,v)

B

d1(u,v)≤d2(u,v)

C

d1(u,v)≥d2(u,v)

D

d1(u,v)≠d2(u,v)


Ques 2 Algorithms


Consider the following recurrence relation:
T(n)=2T(n-1)+n2n for n>0, T(0)=1.
Which ONE of the following options is CORRECT?

A

T(n)=Θ(n22n)

B

T(n)=Θ(n2n)

C

T(n)=Θ((log n)22n)

D

T(n)=Θ(4n)


Ques 3 Algorithms


The pseudocode of a function fun () is given below:

Let A[0,...,29] be an array storing 30 distinct integers in descending order. The number of swap operations that will be performed, if the function fun () is called with A[0,...,29] as argument, is ______ (Answer in integer)


Ques 4 Algorithms


Let G(V,E) be an undirected and unweighted graph with 100 vertices. Let d(u,v) denote the number of edges in a shortest path between vertices u and v in V. Let the maximum value of d(u,v) u, v∈V such that u≠v, be 30. Let T be any breadth-first-search tree of G. Which ONE of the given options is CORRECT for every such graph G?

A

The height of T is exactly 15.

B

The height of T is exactly 30.

C

The height of T is at least 15.

D

The height of T is at least 30.


Ques 5 Algorithms


The maximum value of x such that the edge between the nodes B and C is included in every minimum spanning tree of the given graph is ______ (answer in integer)


Ques 6 Compilers


Which ONE of the following statements is FALSE regarding the symbol table?

A

Symbol table is responsible for keeping track of the scope of variables.

B

Symbol table can be implemented using a binary search tree.

C

Symbol table is not required after the parsing phase.

D

Symbol table is created during the lexical analysis phase.


Statement A: Symbol table is responsible for keeping track of the scope of variables — This is TRUE. The symbol table manages scope information to determine where variables can be accessed.

Statement B: Symbol table can be implemented using a binary search tree — This is TRUE. Symbol tables can be implemented using various data structures including binary search trees, hash tables, arrays, or linked lists.

Statement C: Symbol table is not required after the parsing phase — This is FALSE. The symbol table is used throughout multiple phases including semantic analysis, intermediate code generation, code optimization, and target code generation, not just during parsing.

Statement D: Symbol table is created during the lexical analysis phase — This is TRUE. The lexical analyzer creates entries for tokens and identifiers when it encounters them during scanning.

✅ Final Answer: Option (C) — Symbol table is not required after the parsing phase.

Reason: The symbol table is used by multiple compilation phases beyond parsing, including semantic analysis, code generation, and optimization phases.

Ques 7 Compilers


Which ONE of the following techniques used in compiler code optimization uses live variable analysis?

A

Run-time function call management

B

Register assignment to variables

C

Strength reduction

D

Constant folding


A) Run-time function call management — This involves managing function calls at runtime and does not use live variable analysis.

B) Register assignment to variables — This uses live variable analysis to determine which variables are live at different program points, helping the compiler decide which variables should be allocated to registers and for how long. This is the primary application of live variable analysis.

C) Strength reduction — This optimization replaces expensive operations with cheaper ones (like replacing multiplication by 2 with left shift) and does not require live variable analysis.

D) Constant folding — This optimization evaluates constant expressions at compile time and does not use live variable analysis.

✅ Final Answer: Option (B) — Register assignment to variables.

Reason: Live variable analysis determines which variables are "live" at each program point, which is essential for efficient register allocation and assignment to minimize memory access and optimize performance.

Ques 8 Compilers


Which of the following statement(s) is/are TRUE while computing First and Follow during top down parsing by a compiler?

A

For a production A→ε, ε will be added to First.

B

If there is any input right end marker, it will be added to First(S), where S is the start symbol.

C

For a production A→ε, ε will be added to Follow(A).

D

If there is any input right end marker, it will be added to Follow(S), where S is the start symbol.


Statement A: For a production A→ε, ε will be added to First(A) — This is TRUE. The First set of a non-terminal A includes ε if A can derive the empty string directly.

Statement B: If there is any input right end marker, it will be added to First(S), where S is the start symbol — This is FALSE. The end marker ($) is never added to the First set of any symbol. First sets contain only terminals that can begin strings derived from that symbol.

Statement C: For a production A→ε, ε will be added to Follow(A) — This is FALSE. The fact that A can produce ε does not mean ε is added to Follow(A). Follow sets contain terminals that can appear immediately after a non-terminal, not ε itself.

Statement D: If there is any input right end marker, it will be added to Follow(S), where S is the start symbol — This is TRUE. The end marker ($) is always added to Follow(S) for the start symbol S, indicating the end of input.

✅ Final Answer: Statements A and D are TRUE.

Reason: First sets include ε for productions that derive empty strings, and Follow sets for the start symbol always include the end marker ($). However, end markers are never in First sets, and ε is never in Follow sets.

Ques 9 Compilers


Refer to the given 3-address code sequence. This code sequence is split into basic blocks. The number of basic blocks is ______ (Answer in integer)

1001:i=1
1002:j=1
1003:t1=10*i
1004:t2=t1+j
1005:t3=8*t2
1006:t4=t3-88
1007:a[t4]=0.0
1008:j=j+1
1009:if j<=10 goto 1003
1010:i=i+1
1011:if i<=10 goto 1002
1012:i=1
1013:t5=i-1
1014:t6=88*t5
1015:a[t6]=1.0
1016:i=i+1
1017:if i<=10 goto 1013


To identify basic blocks, we find leaders (starting points) and group consecutive statements until a jump or branch. Leaders include the first statement, targets of jumps, and statements immediately following conditional jumps.

The leaders in this code are at lines 1001, 1002, 1003, 1010, 1012, and 1013. This creates six basic blocks: Block 1 (line 1001), Block 2 (line 1002), Block 3 (lines 1003-1009), Block 4 (lines 1010-1011), Block 5 (line 1012), and Block 6 (lines 1013-1017).

✅ Final Answer: 6

Reason: Each leader starts a new basic block, and consecutive statements without control flow changes belong to the same block.

Ques 10 Computer Networks


Identify the ONE CORRECT matching between the OSI layers and their corresponding functionalities as shown.

OSI LayersFunctionalities
(a) Network layer(I) Packet routing
(b) Transport layer(II) Framing and error handling
(c) Datalink layer(III) Host to host communication

A

(a)-(I), (b)-(II), (c)-(III)

B

(a)-(I), (b)-(III), (c)-(II)

C

(a)-(II), (b)-(I), (c)-(III)

D

(a)-(III), (b)-(II), (c)-(I)


Network layer (a): Responsible for packet routing between networks, determining the best path for data transmission from source to destination. This matches functionality (I) - Packet routing.

Transport layer (b): Provides host-to-host communication, ensuring end-to-end delivery of data between processes on different hosts. This matches functionality (III) - Host to host communication.

Data link layer (c): Handles framing of data into frames and provides error detection and correction mechanisms for reliable transmission over the physical medium. This matches functionality (II) - Framing and error handling.

Therefore, the correct matching is: Network layer with Packet routing, Transport layer with Host to host communication, and Data link layer with Framing and error handling.

✅ Final Answer: Option (B) — (a)-(I), (b)-(III), (c)-(II).

Reason: Each OSI layer has specific functions: Network layer routes packets, Transport layer provides host-to-host communication, and Data link layer handles framing and error control.

Ques 11 Computer Networks


Consider the 3-way handshaking protocol for TCP connection establishment. Let the three packets exchanged during the connection establishment be denoted as P1, P2, and P3, in order. Which of the following option(s) is/are TRUE with respect to TCP header flags that are set in the packets?

A

P3: SYN=1, ACK=1

B

P2: SYN=1, ACK=1

C

P2: SYN=0, ACK=1

D

P1: SYN=1


Ques 12 Computer Networks


A packet with the destination IP address 145.36.109.70 arrives at a router whose routing table is shown. Which interface will the packet be forwarded to?

Subnet AddressSubnet Mask (in CIDR notation)Interface
145.36.0.0/16E1
145.36.128.0/17E2
145.36.64.0/18E3
145.36.255.0/24E4
Default..E5

A

E3

B

E1

C

E2

D

E5


Ques 13 Computer Networks


Suppose a 5-bit message is transmitted from a source to a destination through a noisy channel. The probability that a bit of the message gets flipped during transmission is 0.01. Flipping of each bit is independent of one another. The probability that the message is delivered error-free to the destination is ______ (rounded off to three decimal places)


For a message to be delivered error-free, all bits must be transmitted correctly. Since each bit has a probability of 0.99 of being transmitted correctly and bit transmissions are independent, we multiply the probabilities for all 5 bits.

Probability of error-free transmission = (0.99)^5 = 0.9509900499

Rounded to three decimal places, this gives 0.951.

✅ Final Answer: 0.951

Reason: Independent events require multiplication of individual probabilities, and all bits must be correct for error-free delivery.

Unique Visitor Count

Total Unique Visitors

Loading......