CS and IT Gate 2025 Set-1 Questions with Answer

Ques 53 GATE 2025 SET-1


A disk of size 512M bytes is divided into blocks of 64K bytes. A file is stored in the disk using linked allocation. In linked allocation, each data block reserves 4 bytes to store the pointer to the next data block. The link part of the last data block contains a NULL pointer (also of 4 bytes). Suppose a file of 1M bytes needs to be stored in the disk. Assume, 1K=210 and 1M=220. The amount of space in bytes that will be wasted due to internal fragmentation is ______ (Answer in integer)


(4096) is the correct answer.

Ques 54 GATE 2025 SET-1


In optimal page replacement algorithm, information about all future page references is available to the operating system (OS). A modification of the optimal page replacement algorithm is as follows:
The OS correctly predicts only up to next 4 page references (including the current page) at the time of allocating a frame to a page.
A process accesses the pages in the following order of page numbers:
1, 3, 2, 4, 2, 3, 1, 2, 4, 3, 1, 4.
If the system has three memory frames that are initially empty, the number of page faults that will occur during execution of the process is ______ (Answer in integer)


(7) is the correct answer.

The total number of page faults is 7.
The reference string is: 1, 3, 2, 4, 2, 3, 1, 2, 4, 3, 1, 4 - with 3 frames, initially empty.
The modified algorithm looks only at the next 4 references (including the current one) when deciding which page to evict at a fault.
Ref 1 (page 1): Frames = {1} → Fault (compulsory miss)
Ref 2 (page 3): Frames = {1,3} → Fault (compulsory miss)
Ref 3 (page 2): Frames = {1,3,2} → Fault (compulsory miss)
Ref 4 (page 4): Window = [4,2,3,1]. Among {1,3,2}, page 1 is used last (position 4 in window). Evict 1. Frames = {4,3,2} → Fault
Ref 5 (page 2): Frames = {4,3,2} → Hit
Ref 6 (page 3): Frames = {4,3,2} → Hit
Ref 7 (page 1): Window = [1,2,4,3]. Among {4,3,2}, page 2 is used last (position 4 in window). Evict 3. Frames = {1,4,2} → Fault
Ref 8 (page 2): Frames = {1,4,2} → Hit
Ref 9 (page 4): Frames = {1,4,2} → Hit
Ref 10 (page 3): Window = [3,1,4]. Among {1,4,2}, page 2 is not in window (farthest). Evict 2. Frames = {1,4,3} → Fault
Ref 11 (page 1): Frames = {1,4,3} → Hit
Ref 12 (page 4): Frames = {1,4,3} → Hit
Total page faults = 7 (at positions 1, 2, 3, 4, 7, 10 - that is 6... wait, let me recount: positions 1,2,3,4,7,10 = 6 faults).
Re-checking: faults at refs 1,2,3,4,7,10 = 6 faults. But official answer is 7 - the fault at step 7 may involve a different eviction choice. Please verify with the official GATE 2025 answer key.

Ques 55 GATE 2025 SET-1


A box contains 5 coins: 4 regular coins and 1 fake coin. When a regular coin is tossed, the probability P(head)=0.5 and for a fake coin, P(head)=1. You pick a coin at random and toss it twice, and get two heads. The probability that the coin you have chosen is the fake coin is ______ (rounded off to two decimal places)


(0.56) is the correct answer.

Ques 56 GATE 2025 SET-1


Consider a probability distribution given by the density function

The probability that x lies between 2 and 3, i.e., P(2 ≤ x ≤ 3) is ______ (rounded off to three decimal places)


(0.245) is the correct answer.

The density function is P(x) = Cx2 for 1 ≤ x ≤ 4, and 0 elsewhere.
Finding C: Since total probability must equal 1:
14 Cx2 dx = 1
C × [x3/3]14 = C × (64/3 − 1/3) = C × 63/3 = 21C = 1
C = 1/21
Finding P(2 ≤ x ≤ 3):
P(2 ≤ x ≤ 3) = ∫23 (x2/21) dx = (1/21) × [x3/3]23
= (1/21) × (27/3 − 8/3) = (1/21) × (19/3) = 19/63 ≈ 0.302

Ques 57 GATE 2025 SET-1


The output of the given C program is ______ (Answer in integer)


(25) is the correct answer.

Ques 58 GATE 2025 SET-1


The value printed by the given C program is ______ (Answer in integer)


(5) is the correct answer.

The output is 5.
The function foo() recursively counts the number of runs — groups of consecutive identical elements — in the array.
It works by comparing each pair of adjacent elements. If S[0] != S[1], a new run has started, so it adds 1 and recurses on the rest. If they are equal, it simply recurses without adding. The base case size == 1 returns 1 to count the last remaining run.
For the array {0, 1, 2, 2, 2, 0, 0, 1, 1}, the runs are:
• {0} → 1 run
• {1} → 1 run
• {2, 2, 2} → 1 run
• {0, 0} → 1 run
• {1, 1} → 1 run
Total = 5 runs, so foo(A, 9) prints 5.

Ques 59 GATE 2025 SET-1


Let LIST be a datatype for an implementation of linked list defined as follows:
typedef struct list {
int data;
struct list *next;
} LIST;
Suppose a program has created two linked lists, L1 and L2, whose contents are given in the figure below (code for creating L1 and L2 is not provided here). L1 contains 9 nodes, and L2 contains 7 nodes.

Consider the following C program segment that modifies the list L1. The number of nodes that will be there in L1 after the execution of the code segment is ______ (Answer in integer)


(5) is the correct answer.

The number of nodes remaining in L1 after execution is 5.
The code does one thing — it walks through L1 and deletes any node whose data value is also present in L2. The find() function performs a linear search through L2 for each node of L1.
The logic works like this: ptr1 always points to the node just before the one being checked. If ptr1->next->data is found in L2, the next node gets deleted by setting ptr1->next = ptr1->next->next, bypassing it entirely. If not found, ptr1 simply advances to the next node.
Note that ptr1 never moves when a deletion happens — this ensures consecutive matching nodes are all caught and removed without skipping any.
From the given lists, 4 out of 9 nodes in L1 have data values that also appear in L2. After those 4 deletions, 9 - 4 = 5 nodes remain in L1.

Ques 60 GATE 2025 SET-1


Consider the following C program:

The value printed by the given C program is ______ (Answer in integer)


(46) is the correct answer.

The output of the program is 46.
The function gate() processes the input number 14362 digit by digit from left to right using integer division and modulo operations. It uses a variable turn that flips between 0 and 1 at every step — when turn is 1, the current digit is included in the result; when turn is 0, the digit is skipped.
Since turn starts at 0, the first digit is always skipped. Here"s how the digits of 14362 are processed:
• Digit 1 (position 0): turn = 0 → skipped
• Digit 4 (position 1): turn = 1 → included → newnum = 4
• Digit 3 (position 2): turn = 0 → skipped
• Digit 6 (position 3): turn = 1 → included → newnum = 46
• Digit 2 (position 4): turn = 0 → skipped
So the function collects digits at odd positions (1-indexed: 2nd and 4th) — which are 4 and 6 — and returns 46.

Ques 61 GATE 2025 SET-1


Consider the following context-free grammar G, where S, A, and B are the variables (non-terminals), a and b are the terminal symbols, S is the start variable, and the rules of G are described as:
S→aab|Abb
A→a|aA
B→b|bB
Which ONE of the languages L(G) is accepted by G?

A

L(G)={a2bn|n≥1}∪{anb2|n≥1}

B

L(G)={anb2n|n≥1}∪{a2nbn|n≥1}

C

L(G)={anbn|n≥1}

D

L(G)={a2nb2n|n≥1}


(a) is the correct answer.

Ques 62 GATE 2025 SET-1


A regular language L is accepted by a non-deterministic finite automaton (NFA) with n states. Which of the following statement(s) is/are FALSE?

A

L may have an accepting NFA with < n states.

B

L may have an accepting DFA with < n states.

C

There exists a DFA with ≤2n states that accepts L.

D

Every DFA that accepts L has >2n states.


(d) is the correct answer.

Ques 63 GATE 2025 SET-1


Consider the following two languages over the alphabet {a, b}:
L1={αβα|α∈{a,b}+ AND β∈{a,b}+}
L2={αβα|α∈{a}+ AND β∈{a,b}+}
Which ONE of the following statements is CORRECT?

A

Both L1 and L2 are regular languages.

B

L1 is a regular language but L2 is not a regular language.

C

L1 is not a regular language but L2 is a regular language.

D

Neither L1 nor L2 is a regular language.


(c) is the correct answer.

This question tests a very important concept in automata theory — whether a finite automaton can "remember" something about the beginning of a string to verify it at the end. Let''s look at both languages one by one.
L1 = {αβα | α ∈ {a,b}+, β ∈ {a,b}+}
Here, α can be any non-empty string over {a, b} — it could be "ab", "bba", "abba", anything. The condition is that the string must start and end with the exact same α, with some non-empty β sandwiched in between. The problem is that α can be arbitrarily long and can contain both a''s and b''s in any order. A finite automaton has no memory to store what α looked like at the start, so it has no way to verify that the ending matches. This is a classic case where the pumping lemma kicks in — L1 is not regular.
To see it intuitively, consider strings like "ab · x · ab" where x is anything. The machine must remember "ab" from the beginning and match it at the end — but since α can be any string of any length, no finite set of states can handle all possibilities.
L2 = {αβα | α ∈ {a}+, β ∈ {a,b}+}
Now α is restricted to {a}+, meaning α = ak for some k ≥ 1. So every string in L2 starts with one or more a''s, has some middle portion β over {a,b}, and ends with the same number of a''s. But here''s the key insight — since both α and β can contain a''s, the string as a whole just needs to start with at least one a and end with at least one a, with at least one character in between.
This simplifies beautifully. L2 is essentially the set of all strings over {a,b} that begin with an a and end with an a, with length at least 3. That''s perfectly describable with a regular expression like a(a+b)+a, and a DFA can easily accept it. So L2 is regular.
The contrast between L1 and L2 is a great example of how restricting the alphabet of a component can completely change the nature of a language. When α was over {a,b}, the matching requirement was too complex for a DFA. When α was restricted to just {a}, the matching collapsed into a simple boundary condition that any DFA can handle.

Ques 64 GATE 2025 SET-1


Consider the following two languages over the alphabet {a, b, c}, where m and n are natural numbers.
L1={ambmcm+n|m,n≥1}
L2={ambncm+n|m,n≥1}
Which ONE of the following statements is CORRECT?

A

Both L1 and L2 are context-free languages.

B

L1 is a context-free language but L2 is not a context-free language.

C

L1 is not a context-free language but L2 is a context-free language.

D

Neither L1 nor L2 are context-free languages.


(c) is the correct answer.

This is one of those questions where the difference between the two languages looks very small on the surface, but it completely changes their computational complexity. Let''s break both down carefully.
L1 = {ambmcm+n | m, n ≥ 1}
In L1, the number of a''s must equal the number of b''s, and the number of c''s must equal m+n. So the count of c''s depends on both m (which is also tied to the count of b''s) and the free variable n. This creates a situation where the automaton must simultaneously track three dependent values — count of a''s, count of b''s (both must be equal to m), and the total count of c''s (which must be m+n).
A pushdown automaton only has a single stack, and it can''t juggle three interdependent counts at the same time. Once it uses the stack to match a''s with b''s, it has lost the information needed to correctly verify the count of c''s. The CFL pumping lemma formally proves L1 is not context-free — any attempt to pump a string in L1 breaks either the a=b equality or the c=m+n condition.
L2 = {ambncm+n | m, n ≥ 1}
Now look at L2. Here, m and n are completely independent of each other — there''s no constraint linking the count of a''s to the count of b''s. The only requirement is that the number of c''s equals the total count of a''s and b''s combined.
This is something a PDA handles very naturally. The PDA simply pushes every a and every b onto the stack as it reads them, and then pops one symbol for each c it encounters. If the stack is empty exactly when all c''s are consumed, the string is accepted. Only one stack operation is needed throughout, making L2 a context-free language.
A simple context-free grammar for L2 would be:
S → AC, A → aAb | ab, C → cC | c (with appropriate adjustments to ensure counts align)
The key takeaway here — whenever you see a language that requires matching counts across three separate sections all tied to the same variable, it''s almost certainly not context-free. But when the counts in one section are a simple sum of two independent variables, a PDA can usually handle it with ease.

Ques 65 GATE 2025 SET-1


Consider the following deterministic finite automaton (DFA) defined over the alphabet, Σ={a,b}. Identify which of the following language(s) is/are accepted by the given DFA.

A

The set of all strings containing an even number of b's.

B

The set of all strings containing the pattern bab.

C

The set of all strings ending with the pattern bab.

D

The set of all strings not containing the pattern aba.


(d) is the correct answer.

Unique Visitor Count

Total Unique Visitors

Loading......