The sentence describes a sequence of events that occurred in the past. Rajendra Chola first "returned" from his voyage, which is a past action. The subsequent action of his desire to visit the temple also happened in the past. The simple past tense "wished" correctly follows the past tense of the first clause, maintaining grammatical consistency.
Q2GATE 0MCQ1MGeneral Aptitude
Research in the workplace reveals that people work for many reasons _______________ .
The sentence intends to convey that people work for reasons in addition to money. The word "besides" is a preposition meaning "in addition to" or "apart from". The word "beside" means "next to" or "at the side of". Therefore, "besides" is the correct word to complete the meaning of the sentence.
Q3GATE 0MCQ1MGeneral Aptitude
Rahul, Murali, Srinivas and Arul are seated around a square table. Rahul is sitting to the left of Murali. Srinivas is sitting to the right of Arul. Which of the following pairs are seated opposite each other?
Let's arrange the four people around a square table, facing the center.
Place Murali at the top side.
"Rahul is sitting to the left of Murali," so Rahul is on the left side.
"Srinivas is sitting to the right of Arul." For this to be true in the remaining two spots, Arul must be on the right side, which places Srinivas on the bottom side (to Arul's right).
The final arrangement is: Murali (Top), Rahul (Left), Srinivas (Bottom), Arul (Right).
The pairs sitting opposite each other are (Murali, Srinivas) and (Rahul, Arul).
Q4GATE 0MCQ1MGeneral Aptitude
Find the smallest number y such that y×162 is a perfect cube.
To make a number a perfect cube, the exponents of its prime factors must all be multiples of 3. First, find the prime factorization of 162: 162=2×81=21×34.
We need to find the smallest integer y such that y×(21×34) is a perfect cube.
The exponent of 2 is 1; the next multiple of 3 is 3. We need to multiply by 23−1=22.
The exponent of 3 is 4; the next multiple of 3 is 6. We need to multiply by 36−4=32.
Thus, the smallest y is 22×32=4×9=36.
Q5GATE 0MCQ1MGeneral Aptitude
The probability that a k-digit number does NOT contain the digits 0, 5, or 9 is
There are 10 possible digits (0 through 9). The problem states that the digits 0, 5, and 9 are not allowed. This leaves 7 allowed digits (1, 2, 3, 4, 6, 7, 8).
For a k-digit number, each of the k positions is an independent event. The probability of a single digit not being 0, 5, or 9 is 107.
Since there are k digits, the probability that none of them are 0, 5, or 9 is the product of the individual probabilities: P=(107)k=0.7k.
Q6GATE 0MCQ2MGeneral Aptitude
"The hold of the nationalist imagination on our colonial past is such that anything inadequately or improperly nationalist is just not history." Which of the following statements best reflects the author's opinion?
The author's statement implies that historical accounts of the colonial past are judged based on how well they fit a "nationalist" narrative. If an event or interpretation is not considered sufficiently "nationalist," it is dismissed and not accepted as part of history. This indicates that the lens of nationalism acts as a filter, determining what is and is not considered legitimate history.
Q7GATE 0MCQ2MGeneral Aptitude
Six people are seated around a circular table. There are at least two men and two women. There are at least three right-handed persons. Every woman has a left-handed person to her immediate right. None of the women are right-handed. The number of women at the table is
There are at least two women, and none are right-handed, making them left-handed. Each woman has a left-handed person to her immediate right. Since there are at least three right-handed people, these must be men. If we assume there are two women, they must sit together for one to have a left-handed person (the other woman) to her right. The other woman would then need a left-handed person to her right. This can be a left-handed man. The remaining three seats are filled by right-handed men. This configuration with two women satisfies all conditions.
The solution can be found by considering two cases for the expression ∣x−y∣.
Case 1: If x≥y, then ∣x−y∣=x−y. The expression becomes: 2(x+y)−(x−y)=22y=y
In this case, y is the minimum value.
Case 2: If x<y, then ∣x−y∣=−(x−y)=y−x. The expression becomes: 2(x+y)−(y−x)=22x=x
In this case, x is the minimum value.
In both scenarios, the expression evaluates to the minimum of x and y.
Q9GATE 0MCQ2MGeneral Aptitude
Arun, Gulab, Neel and Shweta must choose one shirt each from a pile of four shirts coloured red, pink, blue and white respectively. Arun dislikes the colour red and Shweta dislikes the colour white. Gulab and Neel like all the colours. In how many different ways can they choose the shirts so that no one has a shirt with a colour he or she dislikes?
The problem asks for the number of ways four people can choose one shirt each from four different colored shirts, with two restrictions. We can solve this using the principle of inclusion-exclusion.
Total possible arrangements without any restrictions is 4!=24.
Let CA be the case where Arun gets the red shirt, and CS be the case where Shweta gets the white shirt. We need to find the number of invalid arrangements, which is ∣CA∪CS∣=∣CA∣+∣CS∣−∣CA∩CS∣.
∣CA∣: If Arun gets red, the other 3 people can be assigned the remaining 3 shirts in 3!=6 ways.
∣CS∣: If Shweta gets white, the other 3 people can be assigned the remaining 3 shirts in 3!=6 ways.
∣CA∩CS∣: If Arun gets red and Shweta gets white, the other 2 people can be assigned the remaining 2 shirts in 2!=2 ways.
Number of invalid ways = 6+6−2=10.
Number of valid ways = Total ways - Invalid ways = 24−10=14.
Q10GATE 0MCQ2MGeneral Aptitude
A contour line joins locations having the same height above the mean sea level. The following is a contour plot of a geographical region. Contour lines are shown at 25 m intervals in this plot. If in a flood, the water level rises to 525 m, which of the villages P, Q, R, S, T get submerged?
The contour plot shows lines at 25m intervals. The water level in the flood rises to 525m. Any village located at an elevation below 525m will be submerged.
Village P is between the 500m and 550m contours.
Village Q is above the 550m contour.
Villages R, S, and T are all located within the area below the 500m contour line.
Therefore, villages R, S, and T are at an elevation less than 500m and will be submerged by the 525m floodwater.
CSE55 questions
Q11GATE 0MCQ1MDiscrete Mathematics
The statement (¬p)⇒(¬q) is logically equivalent to which of the statements below? I. p⇒q II. q⇒p III. (¬q)∨p IV. (¬p)∨q
The statement (¬p)⇒(¬q) is a conditional statement. According to the rule of contrapositive, a conditional statement is logically equivalent to its contrapositive. The contrapositive of (¬p)⇒(¬q) is formed by swapping the hypothesis and conclusion and negating both, which results in q⇒p. This matches statement II.
Furthermore, any implication A⇒B is logically equivalent to (¬A)∨B. Applying this to q⇒p, we get (¬q)∨p, which matches statement III.
Q12GATE 0MCQ1MDiscrete Mathematics
Consider the first-order logic sentence F:∀x(∃yR(x,y)) . Assuming non-empty logical domains, which of the sentences below are implied by F? I. ∃y(∃xR(x,y)) II. ∃y(∀xR(x,y)) III. ∀y(∃xR(x,y)) IV. ¬∃x(∀y¬R(x,y))
The statement F:∀x(∃yR(x,y)) means "for every x, there exists some y such that R(x,y) is true".
Statement IV, ¬∃x(∀y¬R(x,y)), is equivalent to F. By applying De Morgan's laws for quantifiers, we get ∀x¬(∀y¬R(x,y)), which simplifies to ∀x(∃yR(x,y)).
Statement I, ∃y(∃xR(x,y)), is implied by F. Since for every x there is a corresponding y, the domain is non-empty, guaranteeing that there is at least one such (x,y) pair. Thus, there must exist a y and an x for which R(x,y) holds.
Q13GATE 0MCQ1MEngineering Mathematics
Let c1....cn be scalars, not all zero, such that ∑i=1nciai=0 where ai are column vectors in Rn . Consider the set of linear equations Ax = b where A= a1....an and b= ∑i=1nai . The set of equations has
The condition ∑i=1nciai=0 with not all ci being zero is the definition of linear dependence for the column vectors ai of matrix A. A matrix with linearly dependent columns is singular, meaning its determinant is zero (∣A∣=0).
For a system of linear equations Ax=b, if the matrix A is singular, the system has either no solution or infinitely many solutions.
We are given that b=∑i=1nai. This means that b is a linear combination of the columns of A. A specific solution exists: if we take x to be a vector of all ones, then Ax=∑ai=b.
Since a solution exists and the matrix A is singular, there must be infinitely many solutions.
Q14GATE 0MCQ1MAlgorithm
Consider the following functions from positive integers to real numbers: 10,n,n,log2n,n100 . The CORRECT arrangement of the above functions in increasing order of asymptotic complexity is:
To arrange the functions by increasing asymptotic complexity, we analyze their growth rates as n→∞.
n100: Decreases towards 0.
10: A constant function.
log2n: Logarithmic growth, which is slower than any polynomial.
n=n0.5: Polynomial growth.
n=n1: Polynomial growth, faster than n.
Comparing their growth rates, a decreasing function grows slowest, followed by a constant, then logarithmic, and finally polynomial functions in increasing order of their exponents. The correct order is n100,10,log2n,n,n.
Q15GATE 0MCQ1MAlgorithm
Consider the following table: Match the algorithms to the design paradigms they are based on.
The matching is based on the fundamental design strategy of each algorithm:
P. Kruskal: This algorithm finds a Minimum Spanning Tree by iteratively adding the edge with the least weight that does not form a cycle. This is a classic example of a Greedy approach.
Q. Quicksort: This sorting algorithm works by selecting a 'pivot' element and partitioning the other elements into two sub-arrays, according to whether they are less than or greater than the pivot. The sub-arrays are then sorted recursively. This is the Divide and Conquer paradigm.
R. Floyd-Warshall: This algorithm computes all-pairs shortest paths by considering all possible intermediate vertices for each pair of source and destination vertices. It builds the solution based on solutions to smaller subproblems, which is the essence of Dynamic Programming.
Q16GATE 0MCQ1MData Structure
Let T be a binary search tree with 15 nodes. The minimum and maximum possible heights of T are : Note: The height of a tree with a single node is 0.
The minimum height of a binary search tree with N nodes occurs when the tree is as balanced as possible. The formula for the minimum height is ⌊log2N⌋. For N = 15 nodes, the minimum height is ⌊log215⌋=3.
The maximum height occurs when the tree is completely skewed (either left-skewed or right-skewed), resembling a linked list. For N nodes, the maximum height is N-1. For N = 15 nodes, the maximum height is 15−1=14.
Q17GATE 0MCQ1MDigital Logic
The n-bit fixed-point representation of an unsigned real number real X uses f bits for the fraction part. Let i=n-f. The range of decimal values for X in this representation is
The representation uses i bits for the integer part and f bits for the fractional part. Since the number is unsigned, the minimum value is 0, which occurs when all bits are 0.
The maximum value occurs when all n bits are 1. The i integer bits being all 1s represent the value 2i−1. The f fractional bits being all 1s represent the value ∑k=1f2−k=1−2−f. The total maximum value is the sum of these two parts: (2i−1)+(1−2−f)=2i−2−f. Thus, the range is from 0 to (2i−2−f).
Q18GATE 0MCQ1MData Structure
Consider the C code fragment given below. typedef struct node { int data; node* next ; } node;
void join (node* m, node* n) {
node* p=n ;
while (p->next ! =NULL) {
p = p -> next ;
}
p-> next = m;
}
Assuming that m and n point to valid NULL- terminated linked lists, invocation of join will
The join(m, n) function is designed to append the linked list m to the end of the linked list n.
The code first initializes a pointer p to the head of list n. The while loop then traverses list n until p points to the last node (i.e., the node whose next pointer is NULL). Finally, it sets the next pointer of this last node to m, linking the two lists.
However, there is a critical edge case. If the list n is empty, the input n will be NULL. In this scenario, p is initialized to NULL, and the subsequent attempt to access p->next will cause a null pointer dereference. Thus, the function either appends the list or causes this error.
Q19GATE 0MCQ1MDigital Logic
When two 8-bit numbers A7....A0 and B7....B0 in 2's complement representation (with A0 and B0 as the least significant bits ) are added using a ripple-carry Combinational Circuit, the sum bits obtained are S7....S0 and the carry bits are C7....C0 . An overflow is said to have occurred if
In 2's complement addition, an overflow occurs if the sum of two positive numbers is negative, or the sum of two negative numbers is positive. A standard method for detecting this is to compare the carry-in and carry-out of the most significant bit (MSB). An overflow happens if they are different.
The expression (A7B7S7ˉ+A7ˉB7ˉS7) correctly captures this logic. The first term, A7B7S7ˉ, is true when two negative numbers (A7=1,B7=1) produce a positive result (S7=0). The second term, A7ˉB7ˉS7, is true when two positive numbers (A7=0,B7=0) produce a negative result (S7=1).
Q20GATE 0MCQ1MTheory of Computation
Consider the following context-free grammar over the alphabet ∑ = {a,b,c} with S as the start symbol. S → abScT|abcT T → bT|b Which one of the following represents the language generated by the above grammar ?
The grammar rules are S → abScT | abcT and T → bT | b.
First, the non-terminal T generates one or more 'b's, i.e., the language L(T)={bm∣m≥1}.
The S productions build the string structure. The base case S -> abcT generates strings like abcb^{m_1}. The recursive rule S -> abScT prepends ab and appends cT around a string already generated by S. Applying the recursion n-1 times followed by the base case results in a structure of the form (ab)ncT(cT)...(cT), with n instances of cT. Since each T can independently generate a different sequence of bs (bmi), the final language is { (ab)ncbm1cbm2...cbmn∣n,m1,...,mn≥1 }.
Q21GATE 0MCQ1MComputer Organization
Consider the C struct defined below: struct data { int marks [100] ; char grade; int cnumber; }; struct data student; The base address of student is available in register R1. The field student.grade can be accessed efficiently using
The student.grade field is located at a fixed offset from the base address of the student struct, which is stored in register R1. To access this field, the processor must calculate the memory address by adding this fixed offset to the value in R1. The index addressing mode, commonly represented as X(R1), is specifically designed for this operation. It computes the effective address by summing a constant displacement X (the offset) and the contents of a base register R1. This makes it the most efficient method for accessing struct fields.
Q22GATE 0MCQ1MCompiler Design
Consider the following intermediate program in three address code p= a -b q= p *c p= u * v q= p + q Which one of the following corresponds to a static single assignment form of the above code?
Static Single Assignment (SSA) form is an intermediate representation property where every variable is assigned a value exactly once. In the given three-address code, variables p and q are reassigned. To convert to SSA, each new assignment must be to a new, uniquely named variable.
The correct transformation is:
p = a - b becomes p_3 = a - b.
q = p * c becomes q_4 = p_3 * c, using the new p_3.
p = u * v becomes p_4 = u * v.
q = p + q becomes q_5 = p_4 + q_4, using the new p_4 and the previous q_4.
Option B correctly reflects this principle, assigning each result to a new variable.
Q23GATE 0MCQ1MC Programming
Consider the following C code: # include lt stdio.h > int * assignval (int *x, int val) { *x = val; return x; }
void main ( ) {
int * x= malloc (sizeof (int));
if (NULL = = x) return;
x = assignval (x,0);
if(x) {
x=(int *) malloc (sizeof (int));
if (NULL = = x) return;
x = assignval (x, 10);
}
printf("%d\n", *x);
free (x);
}
The code suffers from which one of the following problems:
The code suffers from a memory leak. Initially, the pointer x is assigned a memory address by the first malloc call. The program then enters the if block, where x is reassigned to a new memory address from a second malloc call. This reassignment overwrites the address of the first memory block. As there are no other pointers to this first block, it becomes inaccessible and cannot be deallocated. The final free(x) call only releases the second memory block, leaving the first one leaked.
Q24GATE 0MCQ1MComputer Network
Consider a TCP client and a TCP server running on two different machines. After completing data transfer, the TCP client calls close to terminate the connectional and a FIN segment is sent to the TCP server. Server-side TCP responds by sending an ACK which is received by the client-side TCP. As per the TCP connections state diagram (RFC 793), in which state does the client-side TCP connection wait for the FIN from the sever-side TCP?
The TCP connection closing sequence involves several state transitions. When the client application initiates a close, it sends a FIN segment to the server and transitions from ESTABLISHED to the FIN-WAIT-1 state. Upon receiving an ACK for its FIN from the server, the client's side of the connection is closed for sending, and it moves to the FIN-WAIT-2 state. In this state, the client waits to receive a FIN segment from the server, which indicates that the server has also finished sending its data.
Q25GATE 0MCQ1MComputer Network
A sender S sends a message m to receiver R, which is digitally signed by S with its private key. In this scenario, one or more of the following security violations can take place. I. S can launch a birthday attack to replace m with a fraudulent message. II. A third party attacker can launch a birthday attack to replace m with a fraudulent message III. R can launch a birthday attack to replace m with a fraudulent message. Which of the following are possible security violations?
A birthday attack on a digital signature involves finding two different messages, m and m', that have the same hash value. The sender (S), who possesses the private key, can exploit this. S can generate an innocent message m and a fraudulent one m', find a hash collision, and get the receiver (R) to agree to m. S then provides the signature for hash(m). Later, S can claim to have sent m', as the signature is also valid for it. A third party or the receiver cannot perform this attack because they lack the sender's private key to create a valid signature for any message.
Q26GATE 0MCQ1MDatabase Management System
The following functional dependencies hold true for the relational schema R{V,W,X,Y,Z}: V → W VW → X Y → VX Y → Z Which of the following is irreducible equivalent for this set of functional dependencies ?
The given set of functional dependencies is F = {V → W, VW → X, Y → VX, Y → Z}.
First, we decompose Y → VX into Y → V and Y → X.
The set becomes {V → W, VW → X, Y → V, Y → X, Y → Z}.
Since V → W, the attribute W in VW → X is extraneous. We can simplify VW → X to V → X.
The set is now {V → W, V → X, Y → V, Y → X, Y → Z}.
Now, we check for redundant dependencies. Since we have Y → V and V → X, by transitivity, Y → X holds. Therefore, Y → X is redundant and can be removed.
The final minimal cover is {V → W, V → X, Y → V, Y → Z}.
Q27GATE 0MCQ1MTheory of Computation
Consider the following grammar. P → xQRS Q → yz|z R → w| ε S → y What is FOLLOW (Q) ?
To find FOLLOW(Q), we look at the production P → xQRS. The FOLLOW set of a non-terminal is the set of terminals that can appear immediately to its right.
Here, FOLLOW(Q) includes everything in FIRST(RS).
First, we find FIRST(R). From R → w|ε, we get FIRST(R) = {w, ε}.
So, 'w' is in FOLLOW(Q).
Since R can derive ε (the empty string), we must also consider what follows R, which is S. We add FIRST(S) to FOLLOW(Q).
From S → y, we get FIRST(S) = {y}.
Therefore, FOLLOW(Q) = {w, y}.
Threads within the same process operate in a shared memory space. This shared space includes the code segment, data segment (for global variables), and the heap (for dynamically allocated memory). Each thread, however, has its own separate stack for local variables and function calls, as well as its own set of registers, including the program counter. Therefore, threads of a process share both global variables and the heap.
Q29GATE 0NAT1MDiscrete Mathematics
Let X be a Gaussian random variable mean 0 and variance σ2 . Let Y=max(X, 0) where max (a,b) is the maximum of a and b. The median of Y is ____________.
X is a Gaussian random variable with a mean of 0. This implies its probability density function is symmetric about 0, so P(X ≤ 0) = 0.5.
The variable Y is defined as Y = max(X, 0). This means:
If X ≤ 0, then Y = 0.
If X > 0, then Y = X.
Since P(X ≤ 0) = 0.5, it follows that P(Y = 0) ≥ 0.5.
The median is the value that separates the higher half from the lower half of a data sample. As at least 50% of the probability mass of Y is at the value 0, the median of Y must be 0.
Q30GATE 0NAT1MDiscrete Mathematics
Let T be a tree with 10 vertices. The sum of the degrees of all the vertices in T is _________.
For any tree with V vertices, the number of edges E is always V-1.
In this case, the tree T has V = 10 vertices, so it must have E = 10 - 1 = 9 edges.
The handshaking lemma states that the sum of the degrees of all vertices in a graph is equal to twice the number of edges.
Sum of degrees = 2 * E
Substituting the number of edges, we get:
Sum of degrees = 2 * 9 = 18.
Q31GATE 0NAT1MDigital Logic
Consider the Karnaugh map given below, where x represents "don't care" and blank represents 0. Assume for all inputs (a, b, c, d) the respective complements (aˉ,bˉ,cˉ,dˉ) are also available. The above logic is implemented 2-input NOR gates only. The minimum number of gates required is ____________.
The Karnaugh map simplification is the first step. The PDF solution simplifies the function to F(a,b,c,d)=aˉc. The question requires implementing this function using only 2-input NOR gates, and the complements of the inputs are available.
The expression aˉc can be rewritten for a NOR-gate implementation using De Morgan's laws: F=aˉc=(aˉc)=aˉ+cˉ=a+cˉ
Since the inputs a and cˉ are directly available, this expression can be implemented with a single 2-input NOR gate.
Q32GATE 0NAT1MTheory of Computation
Consider the language L given by the regular expression (a+b )* b (a+b ) over the alphabet {a, b}. The smallest number of states needed in a deterministic finite-state automation (DFA) accepting L is ___________.
The regular expression is (a+b)∗b(a+b). This language consists of all strings over the alphabet {a,b} where the second-to-last symbol is 'b'. This is equivalent to the set of strings ending in 'ba' or 'bb'.
A minimal Deterministic Finite Automaton (DFA) for this language requires 4 states:
An initial state.
A state reached after reading a 'b'. This 'b' could potentially be the second-to-last symbol.
A final state for strings ending in 'ba'.
A final state for strings ending in 'bb'.
These states are necessary to keep track of the last two symbols seen to determine if the string should be accepted. The transitions ensure that the machine is in a final state only if the second-to-last symbol was 'b'.
Q33GATE 0NAT1MDatabase Management System
Consider a database that has the relation schema EMP (EmpId, EmpName, and DeptName). An instance of the schema EMP and a SQL query on it are given below. The output of executing the SQL query is _____.
The SQL query consists of an inner query and an outer query.
First, the inner query (SELECT DeptName, COUNT(EmpId) AS Num FROM EMP GROUP BY DeptName) calculates the number of employees in each department. Based on the provided table, the result is:
AA: 4
AB: 3
AC: 3
AD: 2
AE: 1
The outer query SELECT AVG(EC.Num) FROM EC ... then calculates the average of the Num column from the result of this inner query (aliased as EC).
The average is calculated as the sum of the counts divided by the number of departments: Average=54+3+3+2+1=513=2.6
Q34GATE 0NAT1MOperating System
Consider the following CPU processes with arrival times (in milliseconds) and length of CPU burst (in milliseconds) as given below: If the pre-emptive shortest remaining time first scheduling algorithm is used to schedule the processes., then the average waiting time across all processes is ________ milliseconds.
The Shortest Remaining Time First (SRTF) algorithm is a pre-emptive scheduling method. The execution proceeds as follows, tracked by a Gantt chart:
At t=0, P1 starts.
At t=3, P2 arrives with a burst time of 3, which is less than P1's remaining time of 4. P2 preempts P1 and runs to completion at t=6.
At t=6, P4 arrives with a burst time of 2, which is the shortest. P4 runs to completion at t=8.
At t=8, P1 (remaining time 4) resumes and finishes at t=12.
At t=12, P3 (burst time 5) runs and finishes at t=17.
Waiting times are: P1=5, P2=0, P3=7, P4=0.
The average waiting time is 45+0+7+0=412=3 ms.
Q35GATE 0NAT1MComputer Organization
Consider a two-level cache hierarchy with L1 and L2 caches. An application incurs 1.4 memory accesses per instruction on average. For this application, the miss rate of L1 cache 0.1, the L2 cache experiences, on average, 7 misses per 1000 instructions. The miss rate of L2 expressed correct to two decimal places is ___________.
An application has 1.4 memory accesses per instruction. For 1000 instructions, the total number of memory accesses is 1.4×1000=1400.
The L1 miss rate is 0.1. The number of L1 misses (which become accesses to L2) is 1400×0.1=140.
The L2 cache experiences 7 misses per 1000 instructions. The L2 miss rate is the ratio of L2 misses to L2 accesses.
L2 Miss Rate = Number of L2 accessesNumber of L2 misses=1407=201=0.05.
Q36GATE 0MCQ2MAlgorithm
Let G = (V, E) be any connected undirected edge-weighted graph. The weights of the edges in E are positive and distinct. Consider the following statements: (I) Minimum spanning tree of G is always unique. (II) Shortest path between any two vertices of G is always unique. Which of the above statements is/are necessarily true?
Statement (I) is true. A well-known property of graphs is that if all edge weights are distinct, the Minimum Spanning Tree (MST) is unique. This is because algorithms like Kruskal's or Prim's will have a unique choice for the next edge to add at every step.
Statement (II) is false. The shortest path between two vertices is not necessarily unique, even if all edge weights are distinct. The provided PDF solution gives a counterexample where two different paths, B-A-C and B-C, have the same total weight of 3, demonstrating that multiple shortest paths can exist.
Q37GATE 0MCQ2MOperating System
A multithreaded program P executes with x number of threads and uses y number of locks for ensuring mutual exclusion while operating on shared memory locations. All locks in the program are non-reentrant, i.e., if a thread holds a lock l, then it cannot re-acquire lock l without releasing it. If a thread is unable to acquire a lock, it blocks until the lock becomes available. The minimum value of x and the minimum value of y together for which execution of P can result in a deadlock are:
A deadlock requires a circular wait condition, which involves multiple threads and multiple resources (locks).
With only one thread (x=1), a deadlock cannot occur as there is no other thread to create a circular dependency with.
With only one lock (y=1), a deadlock is also not possible. One thread will acquire the lock, and any other threads will simply wait for it to be released. No circular wait can be formed.
The minimum condition for a deadlock is with two threads (x=2) and two locks (y=2). A deadlock occurs if Thread 1 acquires Lock 1 and waits for Lock 2, while Thread 2 acquires Lock 2 and waits for Lock 1.
Directly substituting x=1 into the expression gives the indeterminate form 1−3(1)+21−2(1)+1=00.
To resolve this, we can apply L'Hôpital's Rule by taking the derivative of the numerator and the denominator with respect to x.
The derivative of the numerator is 7x6−10x4.
The derivative of the denominator is 3x2−6x.
Now, we evaluate the limit of the new expression: limx→13x2−6x7x6−10x4=3(1)2−6(1)7(1)6−10(1)4=3−67−10=−3−3=1
Q39GATE 0MCQ2MDiscrete Mathematics
Let p, q, and r be propositions and the expression (p → q) → r be a contradiction. Then, the expression (r → p) → q is
The expression (p→q)→r is a contradiction, meaning it is always False. An implication A→B is False only when A is True and B is False.
Therefore, we must have:
(p→q) is True.
r is False.
Now, we evaluate the expression (r→p)→q under these conditions.
Since r is False, the antecedent (r→p) is always True (as False implies anything).
The expression simplifies to (T→q), which is logically equivalent to q.
Thus, the value of the expression is the same as the value of q. This means the expression is always TRUE when q is TRUE.
Q40GATE 0MCQ2MEngineering Mathematics
Let u and v be two vectors in R2 whose Euclidean norms satisfy ||u||=2|| v|| . What is the value of α such that w=u+ α v bisects the angle between u and v ?
A vector w bisects the angle between two vectors u and v if it is in the same direction as the sum of their unit vectors. The unit vectors are u^=∣∣u∣∣u and v^=∣∣v∣∣v.
So, w must be proportional to u^+v^. w=k(∣∣u∣∣u+∣∣v∣∣v)
We are given w=u+αv. Equating the two expressions: u+αv=∣∣u∣∣ku+∣∣v∣∣kv
By comparing the coefficients of u, we get 1=∣∣u∣∣k, so k=∣∣u∣∣.
By comparing the coefficients of v, we get α=∣∣v∣∣k=∣∣v∣∣∣∣u∣∣.
Given that ∣∣u∣∣=2∣∣v∣∣, we can substitute this in: α=∣∣v∣∣2∣∣v∣∣=2
Q41GATE 0MCQ2MEngineering Mathematics
Let A be nxn real valued square symmetric matrix of rank 2 with ∑i=1n∑j=1nAij2=50 . Consider the following statements. (I) One eigen value must be in [-5, 5] (II) The eigen value with the largest magnitude must be strictly greater than 5. Which of the above statements about eigen values of A is/are necessarily CORRECT?
The sum of the squares of all elements of a real symmetric matrix A is equal to the sum of the squares of its eigenvalues, i.e., ∑i,jAij2=∑kλk2. We are given this sum is 50.
The rank of the matrix is 2, which means it has exactly two non-zero eigenvalues, say λ1 and λ2. All other n−2 eigenvalues are 0. Thus, λ12+λ22=50.
(I) Since n−2 eigenvalues are 0 (assuming n≥2), and 0 is within the interval [-5, 5], at least one eigenvalue is in this range. So, statement (I) is true.
(II) Consider the case where λ1=5 and λ2=5. Then λ12+λ22=25+25=50. The largest magnitude is 5, which is not strictly greater than 5. Therefore, statement (II) is not necessarily true.
Q42GATE 0MCQ2MComputer Network
A computer network uses polynomials over GF(2) for error checking with 8 bits as information bits and uses x3+x+1 as the generator polynomial to generate the check bits. In this network, the message 01011011 is transmitted as
The generator polynomial x3+x+1 corresponds to the divisor bit string 1011. The degree of the polynomial is 3.
To find the check bits, we append 3 zeros to the message 01011011, resulting in 01011011000. We then perform binary division (using XOR for subtraction) of this appended message by the divisor 1011.
The long division process shown in the PDF yields a remainder of 101. These three bits are the check bits.
The final transmitted message is the original message with the check bits appended: 01011011101.
Q43GATE 0MCQ2MDigital Logic
Consider a combination of T and D flip-flops connected as shown below. The output of the D flip-flop is connected to the input of the T flip-flop and the output of the T flip-flop is connected to the input of the D flip-flop Initailly, both Q0 and Q1 are set to 1 (before the 1st clock cycle). The outputs
Let the T flip-flop output be Q1 and the D flip-flop output be Q0. The circuit connections give the next-state equations: Q1(t+1)=Q1(t)⊕T∈=Q1(t)⊕Q0(t) Q0(t+1)=D∈=Q1(t)
We trace the states for each clock cycle, starting from the initial state Q1Q0=11:
Initial:Q1Q0=11
After 1st cycle:Q1=1⊕1=0, Q0=1. State: 01.
After 2nd cycle:Q1=0⊕1=1, Q0=0. State: 10.
After 3rd cycle:Q1=1⊕0=1, Q0=1. State: 11.
After 4th cycle:Q1=1⊕1=0, Q0=1. State: 01.
The outputs Q1Q0 after the 3rd cycle are 11, and after the 4th cycle are 01.
Q44GATE 0MCQ2MTheory of Computation
If G is grammar with productions S→SaS∣aSb∣bSa∣SS∣ϵ where S is the start variable, then which one of the following is not generated by G?
This problem requires tracing the execution of two mutually recursive functions. The call sequence starting with fun1(5) is as follows:
fun1(5) prints 5, calls fun2(3).
fun2(3) prints 3, calls fun1(4).
fun1(4) prints 4, calls fun2(2).
fun2(2) prints 2, calls fun1(3).
fun1(3) prints 3, calls fun2(1).
fun2(1) prints 1, calls fun1(2).
fun1(2) prints 2, calls fun2(0) which returns, then prints 2 again.
As the function calls return, the second printf statement in each function's body is executed. Tracing the entire sequence of prints gives the output 53423122233445.
Q46GATE 0MCQ2MC Programming
Consider the C functions foo and bar given below:
int foo (int val ) {
int x = 0;
while (val > 0) {
x = x + foo(val--);
}
return val ;
}
int bar (int val ) {
int x = 0;
while (val > 0) {
x = x + bar(val-1);
}
return val ;
}
The function foo(val) contains the recursive call foo(val--). The post-decrement operator means foo is called with the same value of val repeatedly, leading to infinite recursion. This will exhaust the call stack and cause an abnormal program termination (stack overflow).
The function bar(val) contains the recursive call bar(val-1). This recursion has a base case when val becomes 0. However, the recursive call is inside a while(val > 0) loop. The value of val is never modified within the loop's scope, so once the recursion returns, the while condition remains true, and the function enters an infinite loop.
Q47GATE 0MCQ2MTheory of Computation
Consider the context-free grammars over the alphabet {a,b,c} given below. S and T are non-terminals G1:S→aSb∣T,T→cT∣ϵG2:S→bSa∣T,T→cT∣ϵ The language L(G1)∩L(G2) is
First, let's determine the languages generated by the grammars.
The non-terminal T generates the language L(T)={cm∣m≥0}, which is c∗.
For G1:S→aSb∣T. This generates strings where a's are matched with b's, with a string from L(T) in the middle. So, L(G1)={ancmbn∣n,m≥0}.
For G2:S→bSa∣T. This generates strings where b's are matched with a's. So, L(G2)={bncman∣n,m≥0}.
The intersection L(G1)∩L(G2) contains strings that belong to both languages. A string must have the form ancmbn and bpcqap. This is only possible if the number of a's and b's is zero (n=p=0). Thus, the intersection is the language {cm∣m≥0}. This language is represented by the regular expression c∗, which is infinite and regular.
Q48GATE 0MCQ2MTheory of Computation
Consider the following languages over the alphabet Σ={a,b,c} . Let L1={anbncm∣m,n≥0} and L2={ambncn∣m,n≥0} Which of the following are context-free languages ? I. L1∪L2 II. L1∩L2
I. L1∪L2: The union of two context-free languages is always context-free. We can construct a new grammar with a new start symbol S′ such that S′→S1∣S2, where S1 and S2 are the start symbols for grammars generating L1 and L2. Thus, L1∪L2 is context-free. Statement I is true.
II. L1∩L2: The intersection of two CFLs is not guaranteed to be a CFL. Let's find the intersection. A string in the intersection must be of the form anbncm (from L1) and also apbqcq (from L2). For a string to satisfy both forms, we must have n=q and m=q. This implies n=m=q. The resulting language is {anbncn∣n≥0}, which is a classic example of a language that is not context-free. Statement II is false.
Q49GATE 0MCQ2MTheory of Computation
Let A and B be infinite alphabets and let # be a symbol outside both A and B. Let f be a total functional from A* to B*. We say f is computable if there exists a Turning machine M which given an input x in A*, always halts with f(x) on its tape. Let Lf denote the language {x#f(x)|x ∈ A*}. Which of the following statements is true:
A function f is computable if there is a Turing Machine (TM) that halts on every input x and produces f(x). A language L is recursive if there is a TM (a decider) that halts on every input, accepting strings in L and rejecting strings not in L.
If f is computable, we can construct a decider for Lf={x#f(x)∣x∈A∗}. Given an input w, the decider first checks if it has the form x#y. If so, it computes f(x) (which is guaranteed to halt) and compares the result with y. This process always halts, so Lf is recursive.
If Lf is recursive, we can construct a TM to compute f(x). Given an input x, this TM can enumerate all possible strings y∈B∗ and for each, it uses the decider for Lf to check if x#y∈Lf. Since f is a total function, this search is guaranteed to find the unique correct y and halt. Thus, f is computable.
Therefore, f is computable if and only if Lf is recursive.
Q50GATE 0MCQ2MOperating System
Recall that Belady's anomaly is that the pages-fault rate may increase as the number of allocated frames increases. Now consider the following statements: S1: Random page replacement algorithm (where a page chosen at random is replaced) suffers from Belady's anomaly S2: LRU page replacement algorithm suffers from Belady's anomaly Which of the following is CORRECT ?
S1: Random page replacement algorithm can suffer from Belady's anomaly. The random choice of a page to evict does not guarantee that an optimal or near-optimal choice is made. It is possible to construct a reference string where, with more frames, a series of "unlucky" random choices leads to more page faults than with fewer frames. Therefore, S1 is true.
S2: LRU (Least Recently Used) page replacement algorithm is a stack algorithm. A key property of stack algorithms is that the set of pages in memory with k frames is always a subset of the set of pages in memory with k+1 frames. This property ensures that increasing the number of frames will never increase the number of page faults. Thus, LRU does not suffer from Belady's anomaly. Therefore, S2 is false.
Q51GATE 0MCQ2MDatabase Management System
Consider a database that has the relation schemas EMP(EmpId, EmpName, DepId) and DEPT(DeptName, DeptId). Note that the DeptId can be permitted to be NULL in the relation EMP. Consider the following queries on the database expressed in tuple relational calculus. Which of the above queries are safe?
A query in tuple relational calculus is considered "safe" if it is guaranteed to produce a finite set of tuples as its result. Unsafe queries can potentially generate infinite results, often due to negations over infinite domains or lack of sufficient constraints.
In this problem, all three queries are constrained by the tuples that exist within the EMP and DEPT relations. Since these base relations are finite, any result derived from them will also be finite. Therefore, all three queries are safe.
Q52GATE 0MCQ2MDatabase Management System
In a database system, unique time stamps are assigned to each transaction using Lamport's logical clock . Let TS( T1 ) and TS( T2 ) be the timestamps of transactions T1 and T2 respectively. Besides, T1 holds a lock on the resource R, and T2 has requested a conflicting lock on the same resource R. The following algorithm is used to prevent deadlocks in the database system assuming that a killed transaction is restarted with the same timestamp. Assume any transactions that is not killed terminates eventually. Which of the following is TRUE about the database system that uses the above algorithm to prevent deadlocks?
The given algorithm is a variant of the Wound-Wait deadlock prevention scheme. An older transaction (smaller timestamp) "wounds" (kills) a younger transaction that holds a required lock. A younger transaction waits for an older one.
Deadlock-Free: A circular wait condition T1→T2→⋯→T1 cannot occur. In this scheme, a transaction can only wait for an older transaction. A cycle would imply TS(T1)>TS(T2)>⋯>TS(T1), which is a contradiction. Thus, the system is deadlock-free.
Starvation-Free: When a transaction is killed, it is restarted with its original (old) timestamp. As it ages, it will eventually become the oldest transaction in any conflict and will no longer be killed. It will eventually acquire all necessary locks and complete, preventing starvation.
Q53GATE 0NAT2MCompiler Design
Consider the following grammar: stmt → if expr then expr else expr; stmt| O˙ expr → term relop term|term term → id|number if → a|b|c number → [0-9] where relop is a relational operate (e.g <,> ,...), O˙ refers to the empty statement, and if ,then, else are terminals. Consider a program P following the above grammar containing ten if terminals. The number of control flows paths in P is ____________. For example the program if e1 then e2 else e3 has 2 controls flow paths e1→e2 and e1→e3 .
The grammar rule stmt → if expr then expr else expr defines a control structure with two distinct branches: the then path and the else path. Each if statement in the program effectively doubles the number of possible execution paths.
If a program contains n independent if-then-else statements, the total number of control flow paths is 2n. For a program with ten if terminals, the total number of paths is: 210=1024
Q54GATE 0NAT2MComputer Network
In a RSA cryptosystem a participant A uses two prime numbers p=13 and q=17 to generate her public and private keys. If the public key of A is 35. Then the private key of A is __________.
To find the private key d in the RSA algorithm, we follow these steps:
Calculate the modulus n=p×q. n=13×17=221.
Calculate Euler's totient function ϕ(n)=(p−1)(q−1). ϕ(n)=(13−1)(17−1)=12×16=192.
The private key d is the modular multiplicative inverse of the public key e=35 modulo ϕ(n). We need to solve the congruence: e⋅d≡1(modϕ(n))⟹35d≡1(mod192).
By testing the options, we check d=11: 35×11=385. 385(mod192)=(2×192+1)(mod192)=1.
The congruence holds, so the private key is 11.
Q55GATE 0NAT2MComputer Network
The values of parameters for the Stop-and-Wait ARQ protocol are as given below: Bit rate of the transmission channel = 1Mbps Propagation delay from sender to receiver = 0.75 ms Time to process a frame = 0.25ms Number of bytes in the information frame =1980 Number of bytes in the acknowledge frame = 20 Number of overhead bytes in the information frame = 20 Assume that there are no transmission errors. Then the transmission efficiency ( expressed in percentage) of the Stop-and - Wait ARQ protocol for the above parameters is _________( correct to 2 decimal places)
The efficiency of the Stop-and-Wait protocol is the ratio of the time spent transmitting the useful data frame to the total time for one cycle.
Transmission time of data frame (Tx):
Frame size = 1980 (info) + 20 (overhead) = 2000 bytes. Tx=1×106 bps2000 bytes×8 bits/byte=16 ms.
Transmission time of ACK frame (Tack): Tack=1×106 bps20 bytes×8 bits/byte=0.16 ms.
Total cycle time: This includes data transmission, round-trip propagation, processing, and ACK transmission.
Total time = Tx+2×Tp+Tproc+Tack
Total time = 16+2(0.75)+0.25+0.16=17.91 ms.
Efficiency (η): η=Total timeTx=17.9116≈0.8933.
In percentage, the efficiency is 89.33%.
Q56GATE 0NAT2MDatabase Management System
Consider a database that has the relation schema CR (StudentName, CourseName). An instance of the schema CR is as given below. The following query is made on the database T1←πCourseName(σStudentName=′SA′(CR))T2←CR÷T1 The number of rows in T2 is ____________.
The first query, T1←πCourseName(σStudentName=′SA′(CR)), selects the set of courses taken by student 'SA'. From the provided table, these courses are {CA, CB, CC}.
The second query, T2←CR÷T1, performs relational division. It finds all students who have taken every course listed in T1. We must check the table for students who are enrolled in all three courses: CA, CB, and CC.
The students who satisfy this condition are SA, SC, SD, and SF. Therefore, the resulting relation T2 will contain 4 rows.
Q57GATE 0NAT2MDiscrete Mathematics
The number of integers between 1 and 500 (both inclusive) that are divisible by 3 or 5 or 7 is ______________.
This problem requires the Principle of Inclusion-Exclusion for three sets. We want to find the number of integers from 1 to 500 divisible by 3, 5, or 7.
Let Nk be the count of numbers divisible by k. The formula is: ∣D3∪D5∪D7∣=N3+N5+N7−(N15+N21+N35)+N105
Calculating each term using floor division: N3=⌊500/3⌋=166 N5=⌊500/5⌋=100 N7=⌊500/7⌋=71 N15=33,N21=23,N35=14,N105=4
The total is (166+100+71)−(33+23+14)+4=337−70+4=271.
Q58GATE 0NAT2MData Structure
Let A be an array of 31 numbers consisting of sequence of 0's followed by a sequence of 1's. The problem is to find the smallest index i that A[i] is 1 by probing the minimum numbers of locations in A. The worst case number of probes performed by an optimal algorithm is _____________.
The array is sorted, containing a sequence of 0s followed by 1s. The goal is to find the index of the first '1'. The most efficient method for searching in a sorted array is binary search.
The worst-case number of probes (comparisons) for a binary search on an array of size N is given by ⌈log2(N+1)⌉.
For this problem, N = 31.
The number of probes is ⌈log2(31+1)⌉=⌈log2(32)⌉=5.
Q59GATE 0NAT2MComputer Organization
Consider a RISC machine where each instruction is exactly 4 bytes long. Conditional and unconditional branch instructions use PC- relative addressing mode with Offset specified in bytes to the target location of the branch instruction. Further the Offset is always with respect to the address of the next instruction in the program sequence. Consider the following instruction sequence. If the target of the branch instruction is i, then the decimal value of the Offset is __________
The branch instruction is at address i+3. The target of the branch is address i. PC-relative addressing calculates the offset from the address of the next instruction, which is at i+4. Each instruction is 4 bytes long.
The formula is: Target Address = (Address of Next Instruction) + Offset.
Let Ak be the memory address of instruction k. Ai=Ai+4+Offset
Since instructions are contiguous and 4 bytes each, Ai+4=Ai+4×4=Ai+16.
Substituting this in, we get: Ai=(Ai+16)+Offset
Solving for the offset gives: Offset=−16.
Q60GATE 0NAT2MComputer Organization
Instructions execution in a processor is divided into 5 stages. Instruction Fetch (IF), Instruction Decode (ID) , Operand Fetch (OF), Execute (EX), and Write Back (WB), These stages take 5,4,20, 10 and 3 nanoseconds (ns) respectively. A pipelined implementation of the processor requires buffering between each pair of consecutive stages with a delay of 2ns. Two pipelined implementations of the processor are contemplated. (i) a naive pipeline implementation (NP) with 5 stages and (ii) an efficient pipeline (EP) where the OF stage id divided into stages OF1 and OF2 with execution times of 12 ns and 8 ns respectively. The speedup (correct to two decimals places) achieved by EP over NP in executing 20 independent instructions with no hazards is ________________.
For the Naive Pipeline (NP), the clock cycle time is determined by the longest stage (OF) plus the buffer delay: TNP=20+2=22 ns. The time to execute 20 instructions in this 5-stage pipeline is ENP=(k+n−1)TNP=(5+20−1)×22=528 ns.
For the Efficient Pipeline (EP), the OF stage is split into OF1 (12 ns) and OF2 (8 ns). The pipeline now has 6 stages. The new longest stage is OF1. The clock cycle time is TEP=12+2=14 ns. The execution time is EEP=(6+20−1)×14=350 ns.
Speedup is the ratio of execution times: Speedup = ENP/EEP=528/350≈1.508.
Q61GATE 0NAT2MComputer Organization
Consider a 2-way set associative cache with 256 blocks and uses LRU replacement, Initially the cache is empty. Conflict misses are those misses which occur due the contention of multiple blocks for the same cache set. Compulsory misses occur due to first time access to the block. The following sequence of accesses to memory blocks. (0,128,256,128,0,128,256,128,1,129,257,129,1,129,257,129) is repeated 10 times. The number of conflict misses experienced by the cache is ___________.
The cache has 256 blocks and is 2-way set associative, so it has 256/2=128 sets. A memory block b maps to set b mod 128.
The blocks {0, 128, 256} all map to Set 0.
The blocks {1, 129, 257} all map to Set 1.
The access sequence is repeated 10 times.
In the first iteration:
Accesses to 0, 128, 1, and 129 cause 4 compulsory misses.
Subsequent accesses to blocks that map to the same set (e.g., 256 to Set 0, 257 to Set 1) will cause conflict misses. In the first iteration, there are 4 such conflict misses.
In the remaining 9 iterations:
All blocks have been accessed before, so there are no more compulsory misses.
Each iteration has 8 misses (4 for Set 0 accesses, 4 for Set 1 accesses), all of which are conflict misses.
Total conflict misses = (Conflict misses in 1st iteration) + (Misses in 9 other iterations)
Total = 4+(8×9)=4+72=76.
Q62GATE 0NAT2MCompiler Design
Consider the expression ( a-1)* (((b + c) / 3) + d)) . Let X be the minimum number of registers required by an optimal code generation (without any register spill) algorithm for a load/store architecture in which (i) only loads and store instructions can have memory operands and (ii) arithmetic instructions can have only register or immediate operands. The value of X is _________.
The minimum number of registers required to evaluate an expression tree without spills can be determined using the Sethi-Ullman algorithm. We assign a number to each node, representing the registers needed for its subtree.
The expression is (a-1) * (((b+c)/3) + d).
For the subtree (b+c), both b and c are variables, needing 1 register each. Since the register needs are equal, the result (b+c) needs 1+1=2 registers.
For (b+c)/3, the left side needs 2 registers and the right side (constant 3) needs 0. The result needs max(2,0) = 2 registers.
For ((b+c)/3) + d, the left side needs 2 registers and d needs 1. The result needs max(2,1) = 2 registers.
For (a-1), a needs 1 register and 1 needs 0. The result needs max(1,0) = 1 register.
For the final multiplication, the left side needs 1 register and the right side needs 2. The entire expression needs max(1,2) = 2 registers.
Thus, the minimum number of registers required is 2.
Q63GATE 0NAT2MC Programming
Consider the following C program. #include < stdio.h > #include < string.h >
void printlength (char *s, char *t) {
unsigned int c = 0;
int len = ((strlen(s) - strlen (t)) > c) ? strlen(s): strlen(t);
printf ("%d\n", len);
}
void main ( ) { char *x = "abc"; char *y ="defgh"; printlength (x,y); Recall that strlen is defined in string.h as returning a value of type size_t, which is an unsigned int. The output of the program is _____________.
The function strlen returns a value of type size_t, which is an unsigned integer.
In the printlength function:
strlen(s) where s is "abc" returns 3u.
strlen(t) where t is "defgh" returns 5u.
The condition in the ternary operator is (strlen(s) - strlen(t)) > c.
This becomes (3u - 5u) > 0u.
In unsigned arithmetic, 3u - 5u does not result in -2. Instead, it underflows and wraps around to a very large positive value (e.g., 232−2 on a 32-bit system). This large positive value is greater than c (which is 0).
Since the condition is true, the ternary operator evaluates to its first expression, which is strlen(s).
The value of strlen(s) is 3, which is assigned to len and then printed.
Q64GATE 0NAT2MComputer Organization
A cache memory unit with capacity of N words and block size of B words is to be designed. If it is designed as a direct mapped cache, the length of the TAG field is 10 bits. If the cache unit is now designed as a 16-way set-associative cache, the length of the TAG field is ______bits.
Let the main memory address size be M bits, cache capacity be N words, and block size be B words. The address is split into (Tag, Index, Offset). The number of offset bits is log2(B).
Case 1: Direct Mapped
Number of sets = Number of blocks = N/B.
Index bits = log2(N/B).
Tag bits = M−Index−Offset=M−log2(N/B)−log2(B)=M−log2(N).
Given Tag = 10, so 10=M−log2(N).
Case 2: 16-way Set-Associative
Number of sets = (Number of blocks) / 16 = (N/B)/16.
Index bits = log2((N/B)/16)=log2(N/B)−4.
Tag bits = M−Index−Offset=M−(log2(N/B)−4)−log2(B)=M−log2(N)+4.
From Case 1, we know M−log2(N)=10.
Substituting this, Tag bits = 10+4=14.
Q65GATE 0NAT2MC Programming
The output of executing the following C program is ________. # include
int total (int v) {
while (v) {
static int count + = v & 1;
v>> = 1;
}
return count;
}
void main ( ) {
static int x = 0;
int i = 5;
for (; i> 0; i--) {
x=x + total (i) ;
}
printf ("%d\n", x) ;
}
The key to this program is the static int count variable inside the total function. A static local variable is initialized only once and retains its value across function calls.
The total(v) function adds the number of set bits of v to the persistent count and returns the new count. The main function then adds this returned value to x.
Let's trace the values of count (in total) and x (in main):
Initially: count = 0, x = 0.
i=5: total(5) adds 2 (for bits in '101') to count. count becomes 2. total returns 2. x = 0 + 2 = 2.
i=4: total(4) adds 1 (for bit in '100') to count. count becomes 2+1=3. total returns 3. x = 2 + 3 = 5.
i=3: total(3) adds 2 (for bits in '011') to count. count becomes 3+2=5. total returns 5. x = 5 + 5 = 10.
i=2: total(2) adds 1 (for bit in '010') to count. count becomes 5+1=6. total returns 6. x = 10 + 6 = 16.
i=1: total(1) adds 1 (for bit in '001') to count. count becomes 6+1=7. total returns 7. x = 16 + 7 = 23.