Question 1
Consider the polynomial p(x) = a0 + a1x + a2x2 + a3x3 , where ai ≠ 0 ∀i. The minimum number of multiplications needed to evaluate p on an input x is:
 A 3 B 4 C 6 D 9
Numerical Methods and Calculus    GATE-CS-2006
Discuss it

Question 1 Explanation:
Background Explanation : Horner's rule for polynomial division is an algorithm used to simplify the process of evaluating a polynomial f(x) at a certain value x = x0 by dividing the polynomial into monomials (polynomials of the 1st degree). Each monomial involves a maximum of one multiplication and one addition processes. The result obtained from one monomial is added to the result obtained from the next monomial and so forth in an accumulative addition fashion. To explain the above, let is re-write the polynomial in its expanded form; f(x0) = a0 + a1x0+ a2x0^2+ ... + anx0^n This can, also, be written as: f(x0) = a0 + x0(a1+ x0(a2+ x0(a3+ ... + (an-1 + anx0)....) The algorithm proposed by this rule is based on evaluating the monomials formed above starting from the one in the inner-most parenthesis and move out to evaluate the monomials in the outer parenthesis. Solution : Using Horner's Rule, we can write the polynomial as following a0 + (a1 + (a2 + a3x)x)x In the above form, we need to do only 3 multiplications

p = a3 X x    ------------ (1)

q = (a2 + p) X x  ---------(2)

r = (a1 + q) X x  ---------(3)

result = a0 + r 
Reference : http://www.geeksforgeeks.org/horners-method-polynomial-evaluation/ This solution is contributed by Nitika Bansal.
 Question 2
Let X, Y, Z be sets of sizes x, y and z respectively. Let W = X x Y. Let E be the set of all subsets of W. The number of functions from Z to E is:
 A z2xy B z x 2 xy C z2x + y D 2xyz
Set Theory & Algebra    GATE-CS-2006
Discuss it

Question 2 Explanation:
Number of functions from a set A of size m to set B of size n is nm$n^m$, because each of the m elements of A has n choices for mapping. Now here m=|Z|=z$m = |Z| = z$, and n=|E|=2xy$n = |E| = 2^{xy}$ because number of subsets of a set of size n is 2n$2^n$, and here set W has size of xy$xy$.
So number of functions from Z to E = (2xy)z=2xyz$(2^{xy})^z = 2^{xyz}$. So option (D) is correct. Source: http://www.cse.iitd.ac.in/~mittal/gate/gate_math_2006.html
 Question 3
The set {1, 2, 3, 5, 7, 8, 9} under multiplication modulo 10 is not a group. Given below are four plausible reasons. Which one of them is false?
 A It is not closed B 2 does not have an inverse C 3 does not have an inverse D 8 does not have an inverse
Set Theory & Algebra    GATE-CS-2006
Discuss it

Question 3 Explanation:
A is not closed under multiplication as we may get 0 after multiplication and 0 is not present in set. 2 doesn't have an inverse as there is no x such that (2*x) mod 10 is 1. 3 has an inverse as (3*7) mod 10 is 1. 8 doesn't have an inverse as there is no x such that (2*x) mod 10 is 1.
 Question 4
A relation R is defined on ordered pairs of integers as follows: (x,y) R(u,v) if x < u and y > v. Then R is: Then R is:
 A Neither a Partial Order nor an Equivalence Relation B A Partial Order but not a Total Order C A Total Order D An Equivalence Relation
Set Theory & Algebra    GATE-CS-2006
Discuss it

Question 4 Explanation:
A relation R is defined on ordered pairs of integers as follows: (x,y) R(u,v) if x < u and y > v. Then R is: Then R is: (A) Neither a Partial Order nor an Equivalence Relation (B) A Partial Order but not a Total Order (C) A Total Order (D) An Equivalence Relation

Solution:

An equivalence relation on a set x is a subset of x*x, i.e., a collection R of ordered pairs of elements of x, satisfying certain properties. Write “x R y" to mean (x,y) is an element of R, and we say "x is related to y," then the properties are 1. Reflexive: a R a for all a Є R, 2. Symmetric: a R b implies that b R a for all a,b Є R 3. Transitive: a R b and b R c imply a R c for all a,b,c Є R.

An partial order relation on a set x is a subset of x*x, i.e., a collection R of ordered pairs of elements of x, satisfying certain properties. Write “x R y" to mean (x,y) is an element of R, and we say "x is related to y," then the properties are

1. Reflexive: a R a for all a Є R, 2. Anti-Symmetric: a R b and b R a implies that for all a,b Є R 3. Transitive: a R b and b R c imply a R c for all a,b,c Є R.

An total order relation a set x is a subset of x*x, i.e., a collection R of ordered pairs of elements of x, satisfying certain properties. Write “x R y" to mean (x,y) is an element of R, and we say "x is related to y," then the properties are

1. Reflexive: a R a for all a Є R, 2. Symmetric: a R b implies that b R a for all a,b Є R 3. Transitive: a R b and b R c imply a R c for all a,b,c Є R. 4. Comparability : either a R b or b R a for all a,b Є R.

As given in question, a relation R is defined on ordered pairs of integers as follows: (x,y) R(u,v) if x < u and y > v , reflexive property is not satisfied here , because there is > or < relationship between (x ,y) pair set and (u,v) pair set . Other way , if there would have been x <= u and y>= v (or x=u and y=v) kind of relation amongs elements of sets then reflexive property could have been satisfied. Since reflexive property in not satisfied here , so given realtion can not be equivalence ,partial order or total order relation.So ,Answer (A) is true .

This solution is contributed by Nirmal Bharadwaj.

 Question 5
For which one of the following reasons does Internet Protocol (IP) use the timeto- live (TTL) field in the IP datagram header
 A Ensure packets reach destination within that time B Discard packets that reach later than that time C Prevent packets from looping indefinitely D Limit the time for which a packet gets queued in intermediate routers.
Network Layer    GATE-CS-2006
Discuss it

Question 5 Explanation:
following are lines from wikipedia Time to live (TTL) or hop limit is a mechanism that limits the lifespan or lifetime of data in a computer or network. TTL may be implemented as a counter or timestamp attached to or embedded in the data. Once the prescribed event count or timespan has elapsed, data is discarded. In computer networking, TTL prevents a data packet from circulating indefinitely.
 Question 6
Consider three CPU-intensive processes, which require 10, 20 and 30 time units and arrive at times 0, 2 and 6, respectively. How many context switches are needed if the operating system implements a shortest remaining time first scheduling algorithm? Do not count the context switches at time zero and at the end.
 A 1 B 2 C 3 D 4
GATE-CS-2006    CPU Scheduling
Discuss it

Question 6 Explanation:
Shortest remaining time, also known as shortest remaining time first (SRTF), is a scheduling method that is a pre-emptive version of shortest job next scheduling. In this scheduling algorithm, the process with the smallest amount of time remaining until completion is selected to execute. Since the currently executing process is the one with the shortest amount of time remaining by definition, and since that time should only reduce as execution progresses, processes will always run until they complete or a new process is added that requires a smaller amount of time. Solution: Let three process be P0, P1 and P2 with arrival times 0, 2 and 6 respectively and CPU burst times 10, 20 and 30 respectively. At time 0, P0 is the only available process so it runs. At time 2, P1 arrives, but P0 has the shortest remaining time, so it continues. At time 6, P2 also arrives, but P0 still has the shortest remaining time, so it continues. At time 10, P1 is scheduled as it is the shortest remaining time process. At time 30, P2 is scheduled. Only two context switches are needed. P0 to P1 and P1 to P2. See question 1 of http://www.geeksforgeeks.org/operating-systems-set-14/ This solution is contributed by Nitika Bansal
 Question 7
Consider the following grammar.
S -> S * E
S -> E
E -> F + E
E -> F
F -> id
Consider the following LR(0) items corresponding to the grammar above.
(i) S -> S * .E
(ii) E -> F. + E
(iii) E -> F + .E 
Given the items above, which two of them will appear in the same set in the canonical sets-of-items for the grammar?
 A (i) and (ii) B (ii) and (iii) C (i) and (iii) D None of the above
Parsing and Syntax directed translation    GATE-CS-2006
Discuss it

Question 7 Explanation:
Let's make the LR(0) set of items. First we need to augment the grammar with the production rule S' -> .S , then we need to find closure of items in a set to complete a set. Below are the LR(0) sets of items.
 Question 8
You are given a free running clock with a duty cycle of 50% and a digital waveform f which changes only at the negative edge of the clock. Which one of the following circuits (using clocked D flip-flops) will delay the phase of f by 180°?
 A A B B C C D D
Digital Logic & Number representation    GATE-CS-2006
Discuss it

Question 8 Explanation:
We assume the D flip-flop to be negative edge triggered.

In option (A), during the negative edge of the clock, first flip-flop inverts complement of ‘f’. But, the output of first flip-flop has the same phase as ‘f’. Now, we give this output as input to the second flip-flop, which is enabled by ‘clk’. Thus, we get a double inverted output having same phase as the input. So, A is not the correct option.

In option (B) and (D), the output is inverted ‘f’. But, we want ‘f’ as the output. So, (B) and (D) can’t be the answer.

In option (C), the first flip-flop is activated by ‘clk’. So, the output of first flip-flop has the same phase as ‘f’. But, the second flip-flop is enabled by complement of ‘clk’. Since the clock ‘clk’ has a duty cycle of 50% , we get the output having phase delay of 180 degrees.

Therefore, (C) is the correct answer.

Please comment below if you find anything wrong in the above post.
 Question 9
A CPU has 24-bit instructions. A program starts at address 300 (in decimal). Which one of the following is a legal program counter (all values in decimal)?
 A 400 B 500 C 600 D 700
Computer Organization and Architecture    GATE-CS-2006
Discuss it

Question 9 Explanation:
Here, size of instruction  =  24/8 = 3 bytes.

Program Counter can shift 3 bytes at a time to jump to next instruction.

So the given options must be divisible by 3. only 600 is satisfied.
 Question 10
In a binary max heap containing n numbers, the smallest element can be found in time
 A O(n) B O(Logn) C O(LogLogn) D O(1)
GATE-CS-2006
Discuss it

Question 10 Explanation:
 Question 11
Consider a weighted complete graph G on the vertex set {v1, v2, ..vn} such that the weight of the edge (vi, vj) is 2|i-j|. The weight of a minimum spanning tree of G is: (GATE CS 2006)
 A n — 1 B 2n — 2 C nC2 D 2
GATE-CS-2006
Discuss it

 Question 12
To implement Dijkstra’s shortest path algorithm on unweighted graphs so that it runs in linear time, the data structure to be used is:
 A Queue B Stack C Heap D B-Tree
GATE-CS-2006
Discuss it

Question 12 Explanation:
 Question 13
A scheme for storing binary trees in an array X is as follows. Indexing of X starts at 1 instead of 0. the root is stored at X[1]. For a node stored at X[i], the left child, if any, is stored in X[2i] and the right child, if any, in X[2i+1]. To be able to store any binary tree on n vertices the minimum size of X should be.
 A log2n B n C 2n + 1 D 2^n — 1
GATE-CS-2006
Discuss it

Question 13 Explanation:
 Question 14
Which one of the following in place sorting algorithms needs the minimum number of swaps?
 A Quick sort B Insertion sort C Selection sort D Heap sort
GATE-CS-2006    QuickSort
Discuss it

Question 14 Explanation:
Let's try to analyse the number of swaps in each of the given sorting algorithms. Quick sort – Worst Case input for maximum number of swaps will be already sorted array in decreasing order. Recurrence for Total number of swaps in this case : T(n) = T(n-1) + O(n) // O(n) swaps will occur in alternate calls to partition algorithm. = O(n2) Insertion sort - Worst Case input for maximum number of swaps will be already sorted array in ascending order.When a new element is inserted into an already sorted array of k size, it can lead to k swaps (in case it is the smallest of all) in worst case. For n-1 iterations of insertion sort, total swaps will be O(n2). Selection sort – There is no Worst case input for selection sort. Since it searches for the index of kth minimum element in kth iteration and then in one swap, it places that element into its orrect position. For n-1 iterations of selection sort, it can have O(n) swaps. Heap sort – Total number of swaps in Heap sort can be O(nlogn) as after performing Build-heap which may require O(n) swaps, it performs n-1 extract-min operations resulting into O(nlogn) swaps. See Question 3 of http://www.geeksforgeeks.org/data-structures-and-algorithms-set-7/ This solution is contributed by Pranjul Ahuja
 Question 15
Consider the following C-program fragment in which i, j and n are integer variables.
for (i = n, j = 0; i >0; i /= 2, j += i);

Let val(j) denote the value stored in the variable j after termination of the for loop. Which one of the following is true? (A) val(j) = (logn) (B) vaI(j) = (sqrt(n)) (C) val(j) = (n) (D) val(j) = (nlogn)
 A A B B C C D D
Analysis of Algorithms    GATE-CS-2006
Discuss it

Question 15 Explanation:
The variable j is initially 0 and value of j is sum of values of i. i is initialized as n and is reduced to half in each iteration. j = n/2 + n/4 + n/8 + .. + 1 = Θ(n) Note the semicolon after the for loop, so there is nothing in the body. Same as question 1 of http://www.geeksforgeeks.org/c-language-set-6/
 Question 16
Let S be an NP-complete problem and Q and R be two other problems not known to be in NP. Q is polynomial time reducible to S and S is polynomial-time reducible to R. Which one of the following statements is true?
 A R is NP-complete B R is NP-hard C Q is NP-complete D Q is NP-hard
GATE-CS-2006
Discuss it

Question 16 Explanation:
 Question 17
An element in an array X is called a leader if it is greater than all elements to the right of it in X. The best algorithm to find all leaders in an array.
 A Solves it in linear time using a left to right pass of the array B Solves it in linear time using a right to left pass of the array C Solves it using divide and conquer in time Theta(nlogn) D Solves it in time Theta(n^2)
GATE-CS-2006
Discuss it

Question 17 Explanation:
Please see this post for explanation.
 Question 18
We are given a set X = {x1, .... xn} where xi = 2i. A sample S ⊆ X is drawn by selecting each xi independently with probability pi = 1/2. The expected value of the smallest number in sample S is:
 A 1/n B 2 C sqrt(n) D n
Probability    GATE-CS-2006
Discuss it

Question 18 Explanation:
E = (1/(2^1))*(2^1) + (1/(2^2))*(2^2) + … (1/(2^n))*(2^n) = 1+1+…1 (n times addition of 1) = n
 Question 19
 A L1 only B L3 Only C L1 and L2 D L2 and L3
Context free languages and Push-down automata    GATE-CS-2006
Discuss it

Question 19 Explanation:
A PDA can be built only for L1. It is not possible to build PDA for L2 and L3.
 Question 20
Consider the following log sequence of two transactions on a bank account, with initial balance 12000, that transfer 2000 to a mortgage payment and then apply a 5% interest.
  1. T1 start
2. T1 B old=12000 new=10000
3. T1 M old=0 new=2000
4. T1 commit
5. T2 start
6. T2 B old=10000 new=10500
7. T2 commit 
Suppose the database system cra shes just before log record 7 is written. When the system is restarted, which one statement is true of the recovery procedure?
 A We must redo log record 6 to set B to 10500 B We must undo log record 6 to set B to 10000 and then redo log records 2 and 3. C We need not redo log records 2 and 3 because transaction T1 has committed. D We can apply redo and undo operations in arbitrary order because they are idempotent
Transactions and concurrency control    GATE-CS-2006
Discuss it

Question 20 Explanation:
We must undo log record 6 to set B to 10000 and then redo log records 2 and 3 bcoz system fail before commit operation. So we need to undone active transactions(T2) and redo committed transactions (T1) Note:Here we are not using checkpoints. Checkpoint : Checkpoint is a mechanism where all the previous logs are removed from the system and stored permanently in a storage disk. Checkpoint declares a point before which the DBMS was in consistent state, and all the transactions were committed. Recovery: When a system with concurrent transactions crashes and recovers, it behaves in the following manner − =>The recovery system reads the logs backwards from the end to the last checkpoint. =>It maintains two lists, an undo-list and a redo-list. =>If the recovery system sees a log with and or just , it puts the transaction in the redo-list. =>If the recovery system sees a log with but no commit or abort log found, it puts the transaction in undo-list. All the transactions in the undo-list are then undone and their logs are removed. All the transactions in the redo-list and their previous logs are removed and then redone before saving their logs. So Answer is B redo log records 2 and 3 and undo log record 6
 Question 21
For each element in a set of size 2n, an unbiased coin is tossed. The 2n coin tosses are independent. An element is chosen if the corresponding coin toss were head. The probability that exactly n elements are chosen is:
 A (2nCn) / (4^n) B (2nCn) / (2^n) C 1 / (2nCn) D 1/2
Probability    GATE-CS-2006
Discuss it

Question 21 Explanation:
The question is mainly about probability of n heads out of 2n coin tosses. P = 2nCn∗((1/2)^n)∗((1/2)^n) = (2nCn) / (4^n)
 Question 22
Let E, F and G be finite sets. Let X = (E ∩ F) - (F ∩ G) and Y = (E - (E ∩ G)) - (E - F). Which one of the following is true?
 A X ⊂ Y B X ⊃ Y C X = Y D X - Y ≠ φ and Y - X ≠ φ
Set Theory & Algebra    GATE-CS-2006
Discuss it

Question 22 Explanation:
If we draw the venn diagrams of both X and Y, we find that both cover exactly same region (shown in gigure below). So option (C) is correct. Source: http://www.cse.iitd.ac.in/~mittal/gate/gate_math_2006.html
 Question 23
F is an n*n real matrix. b is an n*1 real vector. Suppose there are two n*1 vectors, u and v such that, u ≠ v and Fu = b, Fv = b. Which one of the following statements is false?
 A Determinant of F is zero. B There are an infinite number of solutions to Fx = b C There is an x≠0 such that Fx = 0 D F must have two identical rows
GATE-CS-2006
Discuss it

Question 23 Explanation:
Since Fu = b, and also Fv = b, so we have (Fu - Fb) = 0 i.e. F(u-v) = 0. Since u≠v, F is a singular matrix i.e. its determinant is 0. Now for a singular matrix F, either Fx = b has no solution or infinitely many solutions, but as we are already given two solutions u and v for x, Fx = b has to have infinitely many solutions. Moreover, by definition of singular matrix, there exists an x≠0 such that Fx = 0 . So options (A), (B), and (C) are true. Option (D) is false because it may not be necessary that two rows are identical, instead, two columns can be identical and we can get F as singular matrix then. So option (D) is correct answer. Source: http://www.cse.iitd.ac.in/~mittal/gate/gate_math_2006.html
 Question 24
Given a set of elements N = {1, 2, ..., n} and two arbitrary subsets A⊆N and B⊆N, how many of the n! permutations π from N to N satisfy min(π(A)) = min(π(B)), where min(S) is the smallest integer in the set of integers S, and π(S) is the set of integers obtained by applying permutation π to each element of S?
 A (n - |A ∪ B|) |A| |B| B (|A|2+|B|2)n2 C n! |A∩B| / |A∪B| D |A∩B|2nC|A∪B|
Set Theory & Algebra    GATE-CS-2006
Discuss it

Question 24 Explanation:
First let us understand what question is asking. So π is a function from N to N, which just permutes the elements of N, so there will be n! such permutations. Now given a particular π i.e. given a particular permutation scheme, we have to find number of permutations out of these n! permuations in which minimum elements of A and B after applying π to them are same. So for example, if N = {1,2,3}, π is {2,3,1}, and if A is {1,3}, then π(A) = {2,1}. Now number of elements in A ∪ B is |A ∪ B|. We can choose permutations for A ∪ B in nC|A∪B| ways. Note that here we are just choosing elements for permutation, and not actually permuting. Let this chosen set be P. Now once we have chosen numbers for permutations, we have to select mapping from each element of A ∪ B to some element of P. So first of all, to achieve required condition specified in question, we have to map minimum number in P to any of the number in A ∩ B, so that min(π(A)) = min(π(B)). We can do this in |A∩B| ways, since we can choose any element of |A∩B| to be mapped to minimum number in P. Now we come to permutation. We can permute numbers in P in |A∪B-1|! ways, since one number (minimum) is already fixed. Moreover, we can also permute remaining n - |A∪B-1| in (n - |A∪B-1|)! ways, so total no. of ways = nC|A∪B|∗|A∩B|∗|A∪B−1|!∗(n−|A∪B−1|)!=n!|A∩B||A∪B| So option (C) is correct. Note: Some answer keys on web have shown answer as option (D), which is clearly incorrect. Suppose |A ∪ B| = 3, and |A ∩ B| = 1, and n = 4, then option (D) evaluates to 14=0.25, which doesn't make sense. Source: http://www.cse.iitd.ac.in/~mittal/gate/gate_math_2006.html
 Question 25
 A 3m B 3n C 2m + 1 D 2n + 1
Set Theory & Algebra    GATE-CS-2006
Discuss it

Question 25 Explanation:
First of all, number of subsets of S of size 3 is mC3 i.e. n=mC3. Now we count number of subsets in which a particular element i appears, that will be (m−1)C2, because 1 element is already known, and we have to choose 2 elements from remaining m-1 elements. [Tex]\sum\limits_{i=1}^{m} f(i) = m * ^{m-1}\mathrm{C}_2 = 3 * ^m\mathrm{C}_3 = 3n[/Tex]
 Question 26
Which one of the first order predicate calculus statements given below correctly express the following English statement?
Tigers and lions attack if they are hungry or threatened.
 A A B B C C D D
Propositional and First Order Logic.    GATE-CS-2006
Discuss it

Question 26 Explanation:
The statement "Tigers and lions attack if they are hungry or threatened" means that if an animal is either tiger or lion, then if it is hungry or threatened, it will attack. So option (D) is correct. Don't get confused by "and" between tigers and lions in the statement. This "and" doesn't mean that we will write "tiger(x) ∧ lion(x) ", because that would have meant that an animal is both tiger and lion, which is not what we want. Source: www.cse.iitd.ac.in/~mittal/gate/gate_math_2006.html
 Question 27
Consider the following propositional statements: P1 : ((A ∧ B) → C)) ≡ ((A → C) ∧ (B → C)) P2 : ((A ∨ B) → C)) ≡ ((A → C) ∨ (B → C)) Which one of the following is true?
 A P1 is a tautology, but not P2 B P2 is a tautology, but not P1 C P1 and P2 are both tautologies D Both P1 and P2 are not tautologies
Propositional and First Order Logic.    GATE-CS-2006
Discuss it

Question 27 Explanation:
The easiest way to solve this question by creating truth tables for the expressions given. Note that P1 will be a tautology if truth table for left expression is exactly same as truth table for right expression. Same holds for P2 also.
A B C ((A ∧ B) → C)) ((A → C) ∧ (B → C)) ((A ∨ B) → C)) ((A → C) ∨ (B → C))
0 0 0 T T T T
0 0 1 T T T T
0 1 0 T F F T
0 1 1 T T T T
1 0 0 T F F T
1 0 1 T T T T
1 1 0 F F F F
1 1 1 T T T T
So as we see from table, none of the P1 or P2 are tautologies, so option (D) is correct. Source: www.cse.iitd.ac.in/~mittal/gate/gate_math_2006.html
 Question 28
A logical binary relation □ ,is defined as follows: Let ~ be the unary negation (NOT) operator, with higher precedence than □. Which one of the following is equivalent to A∧B ?
(A) (~A □ B)
(B) ~(A □ ~B)
(C) ~(~A □ ~B)
(D) ~(~A □ B) 
 A A B B C C D D
Propositional and First Order Logic.    GATE-CS-2006
Discuss it

Question 28 Explanation:
In A∧B, we have 3 entries as False, and one as True. In table, it is opposite case, so we have to negate A □ B, moreover, we want True only when both A and B are true, so in 3rd entry (which becomes true after negation), we want both true, so we have to negate A also. So A ∧ B ≡ ~(~A □ B), so option (D) is correct. Source: www.cse.iitd.ac.in/~mittal/gate/gate_math_2006.html
 Question 29
If s is a string over (0 + 1)* then let n0(s) denote the number of 0’s in s and n1(s) the number of 1’s in s. Which one of the following languages is not regular? 7" />
 A A B B C C D D
Regular languages and finite automata    GATE-CS-2006
Discuss it

Question 29 Explanation:
Languages in option (A) And (D) are finite so both the options are eliminated. For option A: There are finite no. of 3 digit prime numbers. There exists a FA for every finite set. Hence FA is possible. For option D: Possible remainders for 7 is 0 to 6, and for 5 its 0 to 4. Using 35 states, FA can be made. For option B: We can have 6 states (including 1 reject state) state 1: difference is 0 state 2: difference is 1 (more 1s) state 3: difference is 1 (more 0s) state 4: difference is 2 (more 1s) state 5: difference is 2 (more 0s) state 6: reject state for difference >= 3 Suppose the string is 000101 Scan 0 -> state 3 Scan 0 -> state 5 Scan 0 -> reject (since diff. is 3 now) Similarly if we try for string: 010100, this will be accepted.
 Question 30
For S ∈ (0 + 1) * let d(s) denote the decimal value of s (e.g. d(101) = 5). Let L = {s ∈ (0 + 1)* d(s)mod5 = 2 and d(s)mod7 != 4}. Which one of the following statements is true?
 A L is recursively enumerable, but not recursive B L is recursive, but not context-free C L is context-free, but not regular D L is regular
Recursively enumerable sets and Turing machines    GATE-CS-2006
Discuss it

Question 30 Explanation:
It is regular L1=d(s) mod 5 =2 is regular with 5 states L2=d(s) mod 7 =4 is regular with 7 states therefore L1 ^ L2' should be regular because regular grammar are closed under intersection and compliment
 Question 31
Let SHAM3 be the problem of finding a Hamiltonian cycle in a graph G = (V,E) with V divisible by 3 and DHAM3 be the problem of determining if a Hamiltonian cycle exists in such graphs. Which one of the following is true?
 A Both DHAM3 and SHAM3 are NP-hard B SHAM3 is NP-hard, but DHAM3 is not C DHAM3 is NP-hard, but SHAM3 is not D Neither DHAM3 nor SHAM3 is NP-hard
NP Complete    GATE-CS-2006
Discuss it

Question 31 Explanation:
The problem of finding whether there exist a Hamiltonian Cycle or not is NP Hard and NP Complete Both. Finding a Hamiltonian cycle in a graph G = (V,E) with V divisible by 3 is also NP Hard.
 Question 32
Consider the following statements about the context free grammar
G = {S → SS, S → ab, S → ba, S → Ε}
I. G is ambiguous
II. G produces all strings with equal number of a’s and b’s
III. G can be accepted by a deterministic PDA.
Which combination below expresses all the true statements about G?
 A I only B I and III only C II and III only D I, II and III
Context free languages and Push-down automata    GATE-CS-2006
Discuss it

Question 32 Explanation:
Statement I: G is ambiguous because, as shown in the image below there can be two decision tree for string S = ababab [TRUE] Statement II: G produces all strings with equal number of a’s and b’s [FALSE] string 'aabb' cannot be produced by G Statement III: G can be accepted by a deterministic PDA [TRUE] Assume there is a PDA which pushes if top of the stack is $(bottom most alphabet of the stack) and pops otherwise. A string is rejected while popping if the current letter and top of the stack are same. This PDA can derive G. Hence, correct answer should be (B) I and III only Reference: Ambiguity in Context free Grammar and Context free Languages This solution is contributed by Vineet Purswani.  Question 33 Let L1 be a regular language, L2 be a deterministic context-free language and L3 a recursively enumerable, but not recursive, language. Which one of the following statements is false?  A L1 ∩ L2 is a deterministic CFL B L3 ∩ L1 is recursive C L1 ∪ L2 is context free D L1 ∩ L2 ∩ L3 is recursively enumerable GATE-CS-2006 Discuss it Question 33 Explanation: (A) This statement is true because deterministic context free languages are closed under intersection with regular languages. (B) This statement is false because L1 is recursive and every recursive language is decidable. L3 is recursively enumerable but not recursive. So, L3 is undecidable. Intersection of recursive language and recursive enumerable language is recursively enumerable . (C) This statement is true because L1 is regular. Every regular language is also a context free languages. L2 is a deterministic context free language and every DCFL is also a context free languages. Every context free language is closed under Union. (D) This statement is true beacuse L1 is regular hence it is also recursively enumerable. L2 is deterministic context free language so, it is also recursively enumerable . Recursively enumerable languages are closed under intersection. Thus, problem mentioned in option (A) is undecidable. Please comment below if you find anything wrong in the above post.  Question 34 Consider the regular language L = (111 + 11111)*. The minimum number of states in any DFA accepting this languages is:  A 3 B 5 C 8 D 9 Regular languages and finite automata GATE-CS-2006 Discuss it Question 34 Explanation: The finite state automata is : Thus, option (D) is correct. Please comment below if you find anything wrong in the above post.  Question 35 Consider the circuit above. Which one of the following options correctly represents f (x, y, z)?  A xz' + xy + y'z B xz' + xy + (yz)' C xz + xy + (yz)' D xz + xy' + y'z Digital Logic & Number representation GATE-CS-2006 Discuss it Question 35 Explanation: Output from MUX 1=> Z’X+ZY’ Output from MUX2=> Y’(Z’X+ZY’)+YX =>Y’Z+Y’Z’X+YX =>Y’Z+X(Y’Z’+Y) =>Y’Z+X(Y+Z’) USING A+A’B=(A+B) =>Y’Z+XY+XZ’ So Ans is (A).  Question 36 Given two three bit numbers a2a1a0 and b2b1b0 and c, the carry in, the function that represents the carry generate function when these two numbers are added is:  A A B B C C D D Digital Logic & Number representation GATE-CS-2006 Discuss it Question 36 Explanation: For carry look ahead adder we know carry generate function--- Where As we are having two 3 bits number to add so final carry out will be C3- Putting value of Pi,Gi in 3 C3=(A2.B2)+(A1.B1)(A2+B2)+(A0.B0)(A1+B1)(A2+B2) (TAKING C0=0) C3=A2.B2 +A1A2B1+A1B2B1+(A0B0)(A1A2+A1B2+B1A2+B1B2) C3=A2B2+A1A2B1+A1B2B1+A0A1A2B0+A0A1B0B2+A0A2B1B0+A0B0B1B2 SO ANS IS (A) PART.  Question 37 Consider the circuit in the diagram. The ⊕ operator represents Ex-OR. The D flipflops are initialized to zeroes (cleared). The following data: 100110000 is supplied to the “data” terminal in nine clock cycles. After that the values of q2q1q0 are:  A 000 B 001 C 010 D 101 Digital Logic & Number representation GATE-CS-2006 Discuss it Question 37 Explanation: The D flipflops are initialized to zeroes. This implies q0 = 0, q1 = 0 and q2 = 0 initially. Clock cycle 1 : q0 = data = 1 , q1 = q0before XOR q2before = 0 XOR 0 = 0 , q2 = q1before = 0 Clock cycle 2 : q0 = data = 0 , q1 = q0before XOR q2before = 1 XOR 0 = 1 , q2 = q1before = 0 Clock cycle 3 : q0 = data = 0 , q1 = q0before XOR q2before = 0 XOR 0 = 0 , q2 = q1before = 1 Clock cycle 4 : q0 = data = 1 , q1 = q0before XOR q2before = 0 XOR 1 = 1 , q2 = q1before = 0 Clock cycle 5 : q0 = data = 1 , q1 = q0before XOR q2before = 1 XOR 0 = 1 , q2 = q1before = 1 Clock cycle 6 : q0 = data = 0 , q1 = q0before XOR q2before = 1 XOR 1 = 0 , q2 = q1before = 1 Clock cycle 7 : q0 = data = 0 , q1 = q0before XOR q2before = 0 XOR 1 = 1 , q2 = q1before = 0 Clock cycle 8 : q0 = data = 0 , q1 = q0before XOR q2before = 0 XOR 0 = 0 , q2 = q1before = 1 Clock cycle 9 : q0 = data = 0 , q1 = q0before XOR q2before = 0 XOR 1 = 1 , q2 = q1before = 0 Thus, option (C) is correct. Please comment below if you find anything wrong in the above post.  Question 38 Consider a Boolean function f (w, x, y, z). suppose that exactly one of its inputs is allowed to change at a time. If the function happens to be true for two input vectors i1 = (w1, x1, y1, z1) and i2 = (w2, x2, y2, z2) we would like the function to remain true as the input changes from i1 to i2 (i1 and i2 differ in exactly one bit position), without becoming false momentarily. Let f (w, x, y, z) = ∑(5,7,11,12,13,15). Which of the following cube covers of f will ensure that the required property is satisfied?  A w'xz, wxy', xy'z, xyz,wyz B wxy,w'xz,wyz C wx(yz)', xz, wx'yz D wzy, wyz, wxz, w'xz, xy'z, xyz Digital Logic & Number representation GATE-CS-2006 Discuss it Question 38 Explanation: We construct the K - Map as : After simplification of this K - Map we get answer as : w'xz, wxy', xy'z, xyz, wyz Thus, option (A) is the answer. Please comment below if you find anything wrong in the above post.  Question 39 We consider the addition of two 2’s complement numbers bn-1bn-2...b0 and an-1an-2...a0. A binary adder for adding unsigned binary numbers is used to add the two numbers. The sum is denoted by cn-1cn-2...c0 and the carry-out by cout. Which one of the following options correctly identifies the overflow condition?  A A B B C C D D Digital Logic & Number representation GATE-CS-2006 Discuss it Question 39 Explanation: When two signed 2's complement numbers are added, overflow is detected if: 1. both operands are positive and the result is negative, or 2. both operands are negative and the result is positive. • INPUTS OUTPUTS Asign Bsign CARRY IN CARRY OUT Cn OVERFLOW 0 0 0 0 0 0 0 0 1 0 1 1 0 1 0 0 1 0 0 1 1 1 0 0 1 0 0 0 1 0 1 0 1 1 0 0 1 1 0 1 0 1 1 1 1 1 1 0 We may note here that overflow occurs only when CARRYin ≠ CARRYout Overflow = Cin XOR Cout or Cn-1 XOR Cout  Question 40 Consider numbers represented in 4-bit gray code. Let h3h2h1h0 be the gray code representation of a number n and let g3g2g1g0 be the gray code of (n + 1) (modulo 16) value of the number. Which one of the following functions is correct?  A A B B C C D D Digital Logic & Number representation GATE-CS-2006 Discuss it Question 40 Explanation: Write gray code (n) numbers from 0 to 15 and make another column for (n+1) numbers by shifting the next number on top. As shown in the table: Now to determine the min terms for g3, g2, g1, g0, we see the '1s' in the corresponding columns. The digit they correspond to give the min terms of the function. Thus the answers we will be: G3(h3h2h1h0)= ∑(4,12,13,15,14,10,11,9) G2(h3h2h1h0)= ∑(2,6,7,5,4,12,13,15) G1(h3h2h1h0)= ∑(1,3,2,6,13,15,14,10) G0(h3h2h1h0)= ∑(0,1,6,7,12,13,10,11) Thus g2 is given correctly in the options. Read about K-Maps to know about mapping, SOP and POS forms: K-Map (Karnaugh Map) Watch NPTEL videos to learn more about: Code converters Logic Minimization Using Karnaugh Maps Karnaugh Map Minimization Using Maxterms This explanation has been contributed by Kriti Kushwaha.  Question 41 A CPU has a cache with block size 64 bytes. The main memory has k banks, each bank being c bytes wide. Consecutive c − byte chunks are mapped on consecutive banks with wrap-around. All the k banks can be accessed in parallel, but two accesses to the same bank must be serialized. A cache block access may involve multiple iterations of parallel bank accesses depending on the amount of data obtained by accessing all the k banks in parallel. Each iteration requires decoding the bank numbers to be accessed in parallel and this takes. k/2 ns The latency of one bank access is 80 ns. If c = 2 and k = 24, the latency of retrieving a cache block starting at address zero from main memory is:  A 92 ns B 104 ns C 172 ns D 184 ns Computer Organization and Architecture GATE-CS-2006 Discuss it Question 41 Explanation: Explanation: Size of cache block=64 B No. of main memory banks K=24 Size of each bank C=2 bytes i.e each bank in memory is 2 bytes and there are 24 such banks. So, in one iteration we can get 2*24 = 48 bytes and getting 64 bytes requires 2 iterations. So time taken for parallel access T=decoding time +latency time. T = (K/2)+latency = 12+80 = 92 ns But C=2 for accesses =2*92=184ns (since in each iteration we need to select the banks and the bank decoding time (k/2) is independent of the number of banks we are going to access) This solution is contributed by Nitika Bansal.  Question 42 A CPU has a five-stage pipeline and runs at 1 GHz frequency. Instruction fetch happens in the first stage of the pipeline. A conditional branch instruction computes the target address and evaluates the condition in the third stage of the pipeline. The processor stops fetching new instructions following a conditional branch until the branch outcome is known. A program executes 109 instructions out of which 20% are conditional branches. If each instruction takes one cycle to complete on average, the total execution time of the program is:  A 1.0 second B 1.2 seconds C 1.4 seconds D 1.6 seconds Computer Organization and Architecture GATE-CS-2006 Discuss it Question 42 Explanation: In the 3rd stage of pipeline, there will be 2 stall cycles i.e. 2 delay slots. Total number of instructions = 109 20% out of 109 are conditional branches. Therefore, Cycle penalty = 0.2 * 2 * 109 = 4 * 109 Clock speed is 1 GHz and each instruction on average takes 1 cycle. Total execution time = (109 / 109) + 4 * (108 / 109) = 1.4 seconds Thus, total execution time of the program is 1.4 seconds. Please comment below if you find anything wrong in the above post.  Question 43 Consider a new instruction named branch-on-bit-set (mnemonic bbs). The instruction “bbs reg, pos, label” jumps to label if bit in position pos of register operand reg is one. A register is 32 bits wide and the bits are numbered 0 to 31, bit in position 0 being the least significant. Consider the following emulation of this instruction on a processor that does not have bbs implemented. temp¬reg & mask Branch to label if temp is non-zero. The variable temp is a temporary register. For correct emulation, the variable mask must be generated by:  A mask ← 0 x 1 ο pos B mask ← 0 x ffffffff ο pos C mask ← pos D mask ← 0 × f GATE-CS-2006 Discuss it  Question 44 Station A uses 32 byte packets to transmit messages to Station B using a sliding window protocol. The round trip delay between A and B is 80 milliseconds and the bottleneck bandwidth on the path between A and B is 128 kbps. What is the optimal window size that A should use?  A 20 B 40 C 160 D 320 Data Link Layer GATE-CS-2006 Discuss it Question 44 Explanation: Round Trip propagation delay = 80ms Frame size = 32*8 bits Bandwidth = 128kbps Transmission Time = 32*8/(128) ms = 2 ms Let n be the window size. UtiliZation = n/(1+2a) where a = Propagation time / transmission time = n/(1+80/2) For maximum utilization: n = 41 which is close to option (B)  Source : Question 1 of http://www.geeksforgeeks.org/computer-networks-set-11/  Question 45 Two computers C1 and C2 are configured as follows. C1 has IP address 203.197.2.53 and netmask 255.255.128.0. C2 has IP address 203.197.75.201 and netmask 255.255.192.0. which one of the following statements is true?  A C1 and C2 both assume they are on the same network B C2 assumes C1 is on same network, but C1 assumes C2 is on a different network C C1 assumes C2 is on same network, but C2 assumes C1 is on a different network D C1 and C2 both assume they are on different networks. Network Layer GATE-CS-2006 Discuss it Question 45 Explanation:  Question 46 Station A needs to send a message consisting of 9 packets to Station B using a sliding window (window size 3) and go-back-n error control strategy. All packets are ready and immediately available for transmission. If every 5th packet that A transmits gets lost (but no acks from B ever get lost), then what is the number of packets that A will transmit for sending the message to B?  A 12 B 14 C 16 D 18 Network Layer GATE-CS-2006 Discuss it Question 46 Explanation:  Question 47 Consider the following graph: Which one of the following cannot be the sequence of edges added, in that order, to a minimum spanning tree using Kruskal’s algorithm?  A (a—b),(d—f),(b—f),(d—c),(d—e) B (a—b),(d—f),(d—c),(b—f),(d—e) C (d—f),(a—b),(d—c),(b—f),(d—e) D (d—f),(a—b),(b—f),(d—e),(d—c) GATE-CS-2006 Discuss it Question 47 Explanation: The edge (d-e) cannot be considered before (d-c) in Kruskal's minimum spanning tree algorithm because Kruskal’s algorithm picks the edge with minimum weight from the current set of edges at each step.  Question 48 Let T be a depth first search tree in an undirected graph G. Vertices u and n are leaves of this tree T. The degrees of both u and n in G are at least 2. which one of the following statements is true?  A There must exist a vertex w adjacent to both u and n in G B There must exist a vertex w whose removal disconnects u and n in G C There must exist a cycle in G containing u and n D There must exist a cycle in G containing u and all its neighbours in G. Graph Traversals GATE-CS-2006 Discuss it Question 48 Explanation: Below example shows that A and B are FALSE: Below example shows C is false:  Question 49 An implementation of a queue Q, using two stacks S1 and S2, is given below: void insert(Q, x) { push (S1, x); } void delete(Q){ if(stack-empty(S2)) then if(stack-empty(S1)) then { print(“Q is empty”); return; } else while (!(stack-empty(S1))){ x=pop(S1); push(S2,x); } x=pop(S2); }  Let n insert and m (<=n) delete operations be performed in an arbitrary order on an empty queue Q. Let x and y be the number of push and pop operations performed respectively in the process. Which one of the following is true for all m and n?  A n+m <= x < 2n and 2m <= y <= n+m B n+m <= x < 2n and 2m<= y <= 2n C 2m <= x < 2n and 2m <= y <= n+m D 2m <= x <2n and 2m <= y <= 2n GATE-CS-2006 Discuss it Question 49 Explanation:  Question 50 A set X can be represented by an array x[n] as follows: Consider the following algorithm in which x,y and z are Boolean arrays of size n: algorithm zzz(x[] , y[], z []) { int i; for (i=O; i<n; ++i) z[i] = (x[i] ^ ~y[i]) V (~x[i] ^ y[i]) }  The set Z computed by the algorithm is:  A (X ∩ Y) B (X ∪ Y) C (X-Y) ∩ (Y-X) D (X-Y) ∪ (Y-X) GATE-CS-2006 Discuss it Question 50 Explanation:  Question 51 Consider the following recurrence: Which one of the following is true? (A) T(n) = (loglogn) (B) T(n) = (logn) (C) T(n) = (sqrt(n)) (D) T(n) = (n)  A A B B C C D D GATE-CS-2006 Discuss it Question 51 Explanation: Background Required - Recurrence Solving using Substitution Method. Answer - B Unrolling the recursion, T(n) = 2T(n^(1/2)) + 1 = 2^2T(n^(1/4)) + 2 = 2^3T(n^(1/8)) + 3 . . k steps . = 2^kT(n^(1/2k)) + k …………. (1) Using the Base case, n^(1/2k) = 2 Taking log on both sides log2n = 2k k = log2log2n From (1), T(n) = log2n + log2log2n = Theta(log2n) Here log2n : log(base 2) n Related : http://geeksquiz.com/algorithms-analysis-of-algorithms-question-17-2/ This solution is contributed by Pranjul Ahuja .  Question 52 Suppose we have a O(n) time algorithm that finds median of an unsorted array. Now consider a QuickSort implementation where we first find median using the above algorithm, then use median as pivot. What will be the worst case time complexity of this modified QuickSort.  A O(n^2 Logn) B O(n^2) C O(n Logn Logn) D O(nLogn) GATE-CS-2006 QuickSort Discuss it Question 52 Explanation: When we choose median as pivot element then after the partition algorithm it will go in the middle of the array having half of the elements to left the left and half in the right. Thus after partition algorithm the array will be divided into two equal parts of n/2 elements each. Hence the resultant recurrence relation would be- T(n) = O(n) (for selecting median) + O(n) (for partition) + T(n/2) + T(n/2) T(n) = O(n) + 2T(n/2) We can solve the above recurrence relation using master method Reference: https://en.wikipedia.org/wiki/Master_theorem Same as http://geeksquiz.com/algorithms-searching-and-sorting-question-3/ This solution is contributed by Parul Sharma.  Question 53 Consider the following C-function in which a[n] and b[m] are two sorted integer arrays and c[n + m] be another integer array. void xyz(int a[], int b [], int c[]) { int i, j, k; i = j = k = O; while ((i<n) && (j<m)) if (a[i] < b[j]) c[k++] = a[i++]; else c[k++] = b[j++]; }  Which of the following condition(s) hold(s) after the termination of the while loop? (GATE CS 2006) (i) j < m, k = n+j-1, and a[n-1] < b[j] if i = n (ii) i < n, k = m+i-1, and b[m-1] <= a[i] if j = m  A only (i) B only (ii) C either (i) or (ii) but not both D neither (i) nor (ii) GATE-CS-2006 Discuss it Question 53 Explanation:  Question 54 Given two arrays of numbers a1, a2, a3,...an and b1, b2, .. bn where each number is 0 or 1, the fastest algorithm to find the largest span(i, j) such that ai + ai+1, ....aj = bi + bi+1, .. bj. or report that there is not such span,  A Takes O(n3) and Ω(2n) time if hashing is permitted B Takes O(n3) and Ω(n2.5) time in the key comparison model C Takes θ(n) time and space D Takes O(√n) time only if the sum of the 2n elements is an even number Bit Algorithms GATE-CS-2006 Discuss it Question 54 Explanation: The problem can be solved in Takes θ(n) time and space. The idea is based on below observations. 1. Since there are total n elements, maximum sum is n for both arrays. 2. Difference between two sums varies from -n to n. So there are total 2n + 1 possible values of difference. 3. If differences between prefix sums of two arrays become same at two points, then subarrays between these two points have same sum. Below is Complete Algorithm. 1. Create an auxiliary array of size 2n+1 to store starting points of all possible values of differences (Note that possible values of differences vary from -n to n, i.e., there are total 2n+1 possible values) 2. Initialize starting points of all differences as -1. 3. Initialize maxLen as 0 and prefix sums of both arrays as 0, preSum1 = 0, preSum2 = 0 4. Travers both arrays from i = 0 to n-1. 1. Update prefix sums: preSum1 += arr1[i], preSum2 += arr2[i] 2. Compute difference of current prefix sums: curr_diff = preSum1 – preSum2 3. Find index in diff array: diffIndex = n + curr_diff // curr_diff can be negative and can go till -n 4. If curr_diff is 0, then i+1 is maxLen so far 5. Else If curr_diff is seen first time, i.e., starting point of current diff is -1, then update starting point as i 6. Else (curr_diff is NOT seen first time), then consider i as ending point and find length of current same sum span. If this length is more, then update maxLen 5. Return maxLen See Longest Span with same Sum in two Binary arrays for complete running code  Question 55 Consider these two functions and two statements S1 and S2 about them int work1(int *a, int i, int j) { int x = a[i+2]; a[j] = x+1; return a[i+2] – 3; } int work2(int *a, int i, int j) { int t1 = i+2; int t2 = a[t1]; a[j] = t2+1; return t2 – 3; }  S1: The transformation form work1 to work2 is valid, i.e., for any program state and input arguments, work2 will compute the same output and have the same effect on program state as work1 S2: All the transformations applied to work1 to get work2 will always improve the performance (i.e reduce CPU time) of work2 compared to work1  A S1 is false and S2 is false B S1 is false and S2 is true C S1 is true and S2 is false D S1 is true and S2 is true GATE-CS-2006 Discuss it Question 55 Explanation: S1 is true because even by adding an extra variable (t1) instead of directly computing, the output will be obviously be same. S2 is false: Adding an extra variable can NOT improve the performance in anyway So Answer is C  Question 56 Consider the following code written in a pass-by-reference language like FORTRAN and these statements about the code. subroutine swap(ix,iy) it = ix L1 : ix = iy L2 : iy = it end ia = 3 ib = 8 call swap (ia, 1b+5) print *, ia, ib end  S1: The compiler will generate code to allocate a temporary nameless cell, initialize it to 13, and pass the address of the cell swap S2: On execution the code will generate a runtime error on line L1 S3: On execution the code will generate a runtime error on line L2 S4: The program will print 13 and 8 S5: The program will print 13 and -2 Exactly the following set of statement(s) is correct:  A S1 and S2 B S1 and S4 C S3 D S1 and S5 Principles of Programming Languages GATE-CS-2006 Discuss it Question 56 Explanation: Pass-by-reference nature of FORTRAN makes it pass pointers: 1. to bound cells to its subroutines, if they are already present 2. to unnamed temporary cells later to be bound, if they are not there Now let's analyse the given statements: (S1) Because the second argument is an expression, which could be evaluated easily by compiler SDT rules to a value 13, compiler itself will generate code to define and declare an unnamed temporary cell with value 13 and pass it to swap subroutine. [CORRECT] (S2) 'ix' and 'iy' are variables bound to valid mutable cells, thus there is no reason to get a run time error on line L1. [INCORRECT] (S3) Incorrect due to same reason as of S2 [INCORRECT] (S4) Due to the pass-by-reference nature of the language, the cell bound to variable 'ia' will get value 13 and the temporary unnamed cell which was allocated and passed to the swap subroutine will get value 3. Seemingly, cell bound to variable 'ib' is unchanged, thus printing 13 and 8 at the end of this routine. [CORRECT] (S5) Incorrect due to same reason as of S4 [INCORRECT]  Hence, answer should be (B) S1 and S4 This explanation has been contributed by Vineet Purswani.  Question 57 Consider this C code to swap two integers and these five statements after it: void swap(int *px, int *py) { *px = *px - *py; *py = *px + *py; *px = *py - *px; }  S1: will generate a compilation error S2: may generate a segmentation fault at runtime depending on the arguments passed S3: correctly implements the swap procedure for all input pointers referring to integers stored in memory locations accessible to the process S4: implements the swap procedure correctly for some but not all valid input pointers S5: may add or subtract integers and pointers.  A S1 B S2 and S3 C S2 and S4 D S2 and S5 GATE-CS-2006 Discuss it Question 57 Explanation:  Question 58 Consider the following grammar: S → FR R → S | ε F → id In the predictive parser table, M, of the grammar the entries M[S, id] and M[R,$] respectively.
 A {S → FR} and {R → ε } B {S → FR} and { } C {S → FR} and {R → *S} D {F → id} and {R → ε}
Parsing and Syntax directed translation    GATE-CS-2006
Discuss it

Question 58 Explanation:
Here representing the parsing table as M[ X , Y ], where X represents rows( Non terminals) and Y represents columns(terminals). Here are the rules to fill the parsing table. For each distinct production rule A->α, of the grammar, we need to apply the given rules: Rule 1: if A --> α is a production, for each terminal 'a' in FIRST(α), add A-->α to M[ A , a ] Rule 2 : if ' ε ' is in FIRST(α), add A --> α to M [ A , b ] for each 'b' in FOLLOW(A). As Entries have been asked corresponding to Non-Terminal S and R, hence we only need to consider their productions to get the answer. For S → FR, according to rule 1, this production rule should be placed at the entry M[ S, FIRST(FR) ], and from the given grammar, FIRST(FR) ={id}, hence S->FR is placed in the parsing table at entry M[S , id]. Similarly, For R → S, this production rule should be placed at entry M[ R, FIRST(S) ], and as FIRST(S) = FIRST(F) = {id} hence, R->S is placed at entry M[R,id] and For R->ε, as FIRST(ε) = {ε}, hence rule 2 should be applied, therefore, this production rule should be placed in the parsing table at entry M[R,FOLLOW(R)], and FOLLOW(R) = FOLLOW(S) = {$}, hence R->ε is placed at entry M[ R,$ ]. Therefore Answer is option A. Visit the Following links to Learn how to find First and Follow sets. http://geeksquiz.com/compiler-design-first-in-syntax-analysis/ http://geeksquiz.com/compiler-design-follow-set-in-syntax-analysis/
 Question 59
Consider the following translation scheme. S → ER R → *E{print("*");}R | ε E → F + E {print("+");} | F F → (S) | id {print(id.value);} Here id is a token that represents an integer and id.value represents the corresponding integer value. For an input '2 * 3 + 4', this translation scheme prints
 A 2 * 3 + 4 B 2 * +3 4 C 2 3 * 4 + D 2 3 4+*
Parsing and Syntax directed translation    GATE-CS-2006
Discuss it

Question 59 Explanation:
Background Required to solve the question - Syntax Directed Translation and Parse Tree Construction.
Explanation : We are given L-Attributed Syntax Directed Translation as
semantic actions like printf statements are inserted anywhere on the
RHS of production (R → *E{print(“*”);}R). After constructing the parse tree
as shown below from the given grammar, we will follow depth first order left
to right evaluation in order to generate the final output.

Parse Tree:
Just follow the arrows in the picture (This is actually Depth first
left to right evaluation ) and the moment we take exit from any child
which is printf statement in this question, we print that symbol which
can be a integer value or ‘*’ or ‘+’.

Evaluation : This explanation has been contributed by Pranjul Ahuja.
 Question 60
Consider the following C code segment.
for (i = 0, i<n; i++)
{
for (j=0; j<n; j++)
{
if (i%2)
{
x += (4*j + 5*i);
y += (7 + 4*j);
}
}
}

Which one of the following is false?
 A The code contains loop invariant computation B There is scope of common sub-expression elimination in this code C There is scope of strength reduction in this code D There is scope of dead code elimination in this code
Code Generation and Optimization    GATE-CS-2006
Discuss it

Question 60 Explanation:

4*j is common subexpression elimination so B is true.

5*i can be moved out of inner loop so can be i%2.
Means, A is true as we have loop invariant computation.

Next, 4*j as well as 5*i can be replaced with a = - 4;
before j loop then a = a + 4; where 4*j is computed,
likewise for 5*i. C is true as there is scope of strength
reduction.

By choice elimination, we have D.
 Question 61
The atomic fetch-and-set x, y instruction unconditionally sets the memory location x to 1 and fetches the old value of x n y without allowing any intervening access to the memory location x. consider the following implementation of P and V functions on a binary semaphore S.
void P (binary_semaphore *s)
{
unsigned y;
unsigned *x = &(s->value);
do
{
fetch-and-set x, y;
}
while (y);
}
void V (binary_semaphore *s)
{
S->value = 0;
} 
Which one of the following is true?
 A The implementation may not work if context switching is disabled in P B Instead of using fetch-and –set, a pair of normal load/store can be used C The implementation of V is wrong D The code does not implement a binary semaphore
Process Management    GATE-CS-2006
Discuss it

Question 61 Explanation:
 Question 62
A CPU generates 32-bit virtual addresses. The page size is 4 KB. The processor has a translation look-aside buffer (TLB) which can hold a total of 128 page table entries and is 4-way set associative. The minimum size of the TLB tag is:
 A 11 bits B 13 bits C 15 bits D 20 bits
Memory Management    GATE-CS-2006
Discuss it

Question 62 Explanation:
Virtual Memory would not be very effective if every memory address had to be translated by looking up the associated physical page in memory. The solution is to cache the recent translations in a Translation Lookaside Buffer (TLB). A TLB has a fixed number of slots that contain page table entries, which map virtual addresses to physical addresses. Solution Size of a page = 4KB = 2^12 means 12 offset bits CPU generates 32-bit virtual addresses Total number of bits needed to address a page frame = 32 – 12 = 20 If there are ‘n’ cache lines in a set, the cache placement is called n-way set associative. Since TLB is 4 way set associative and can hold total 128 (2^7) page table entries, number of sets in cache = 2^7/4 = 2^5. So 5 bits are needed to address a set, and 15 (20 – 5) bits are needed for tag. Option (C) is the correct answer. See Question 3 of http://www.geeksforgeeks.org/operating-systems-set-14/ This solution is contributed by Nitika Bansal
 Question 63
A computer system supports 32-bit virtual addresses as well as 32-bit physical addresses. Since the virtual address space is of the same size as the physical address space, the operating system designers decide to get rid of the virtual memory entirely. Which one of the following is true?
 A Efficient implementation of multi-user support is no longer possible B The processor cache organization can be made more efficient now C Hardware support for memory management is no longer needed D CPU scheduling can be made more efficient now
Memory Management    GATE-CS-2006
Discuss it

Question 63 Explanation:
 Question 64
Consider three processes (process id 0, 1, 2 respectively) with compute time bursts 2, 4 and 8 time units. All processes arrive at time zero. Consider the longest remaining time first (LRTF) scheduling algorithm. In LRTF ties are broken by giving priority to the process with the lowest process id. The average turn around time is:
 A 13 units B 14 units C 15 units D 16 units
GATE-CS-2006
Discuss it

Question 64 Explanation:
Background Explanation: Turn around time of a process is total time between submission of the process and its completion.LRTF(Longest Remaining Time First), means the process which has remaining time largest, will run first and in case of same remaining time, lowest process with will be given priority to run. Solution: Let the processes be p0, p1 and p2. These processes will be executed in following order. Gantt chart is as follows:
  p2  p1  p2  p1  p2  p0  p1   p2   p0   p1   p2
0   4   5   6   7   8   9   10    11   12   13   14


First 4 sec, p2 will run, then remaining time p2=4, p1=4, p0=2. Now P1 will get chance to run for 1 sec, then remaining time. p2=4,p1=3,p0=2. Now p2 will get chance to run for 1 sec, then remaining time. p2=3,p1=3,p0=2. By doing this way, you will get above gantt chart. Scheduling table: AT=Arrival Time, BT=Burst Time, CT=Completion Time, TAT=Turn Around Time As we know, turn around time is total time between submission of the process and its completion. i.e turn around time=completion time-arrival time. i.e. TAT=CT-AT Turn around time of p0 = 12 (12-0) Turn around time of p1 = 13 (13-0) Turn around time of p2 = 14 (14-0) Average turn around time is (12+13+14)/3 = 13. Option (A) is the correct answer. See question 1 of http://www.geeksforgeeks.org/operating-systems-set-15/ This solution is contributed by Nitika Bansal
 Question 65
Consider three processes, all arriving at time zero, with total execution time of 10, 20 and 30 units, respectively. Each process spends the first 20% of execution time doing I/O, the next 70% of time doing computation, and the last 10% of time doing I/O again. The operating system uses a shortest remaining compute time first scheduling algorithm and schedules a new process either when the running process gets blocked on I/O or when the running process finishes its compute burst. Assume that all I/O operations can be overlapped as much as possible. For what percentage of time does the CPU remain idle?
 A 0% B 10.6% C 30.0% D 89.4%
GATE-CS-2006
Discuss it

Question 65 Explanation:
Shortest remaining time ( SRT ) scheduling algorithm selects the process for execution which has the smallest amount of time remaining until completion. Let three processes be p0, p1 and p2. Their execution time is 10, 20 and 30 respectively. p0 spends first 2 time units in I/O, 7 units of CPU time and finally 1 unit in I/O. p1 spends first 4 units in I/O, 14 units of CPU time and finally 2 units in I/O. p2 spends first 6 units in I/O, 21 units of CPU time and finally 3 units in I/O. AT- Arrival Time, IO-input/output, BT-Burst Time first process p0 will spend 2 units in IO, next 7 units in BT, then process p1 will spend 14 units in BT (as its 4 units of IO has been spent already when previous process was running) and ten process p2 will spend 21 units in BT (as its 6 units of IO has been spent already when previous processes were running) and atlast 3 units in IO (process p0,p1,p2’s last IO included.)
idle   p0    p1     p2    idle
0    2     9     23     44     47

Total time spent = 47
Idle time = 2 + 3 = 5
Percentage of idle time = (5/47)*100 = 10.6 %

See Question 2 of http://www.geeksforgeeks.org/operating-systems-set-15/ This solution is contributed by Nitika Bansal
 Question 66
Consider the following snapshot of a system running n processes. Process i is holding Xi instances of a resource R, 1 <= i <= n. currently, all instances of R are occupied. Further, for all i, process i has placed a request for an additional Yi instances while holding the Xi instances it already has. There are exactly two processes p and q such that Yp = Yq = 0. Which one of the following can serve as a necessary condition to guarantee that the system is not approaching a deadlock?
 A min (Xp, Xq) < max (Yk) where k != p and k != q B Xp + Xq >= min (Yk) where k != p and k != q C max (Xp, Xq) > 1 D min (Xp, Xq) > 1
Discuss it

Question 66 Explanation:
Deadlock refers to a specific condition when two or more processes are each waiting for another to release a resource, or more than two processes are waiting for resources. Solution: Necessary condition to guarantee no deadlock which means without satisfying this condition, no deadlock is possible. Both the process p and q have no additional requirement; they both can be finished releasing Xp + Xq resources without asking for any additional resource. Using this, we can finish one more process only if condition B is satisfied. If the resources released by p and q are sufficient for another process waiting for Yk resources, then system is not approaching deadlock. i.e Xp+Xq > min (Yk) where k != p and k != q Note: Option B just ensured that the system can proceed from the current state. It does not guarantee that there won’t be a deadlock before all processes are finished. See question 4 of http://www.geeksforgeeks.org/operating-systems-set-15/ Reference : https://www.cs.uic.edu/~jbell/CourseNotes/OperatingSystems/7_Deadlocks.html This solution is contributed by Nitika Bansal
 Question 67
Consider the relation account (customer, balance) where customer is a primary key and there are no null values. We would like to rank customers according to decreasing balance. The customer with the largest balance gets rank 1. ties are not broke but ranks are skipped: if exactly two customers have the largest balance they each get rank 1 and rank 2 is not assigned
Query1:
select A.customer, count(B.customer)
from account A, account B
where A.balance <=B.balance
group by A.customer

Query2:
select A.customer, 1+count(B.customer)
from account A, account B
where A.balance < B.balance
group by A.customer 
Consider these statements about Query1 and Query2.
1. Query1 will produce the same row set as Query2 for
some but not all databases.
2. Both Query1 and Query2 are correct implementation
of the specification
3. Query1 is a correct implementation of the specification
but Query2 is not
4. Neither Query1 nor Query2 is a correct implementation
of the specification
5. Assigning rank with a pure relational query takes
less time than scanning in decreasing balance order
assigning ranks using ODBC. 
Which two of the above statements are correct?
 A 2 and 5 B 1 and 3 C 1 and 4 D 3 and 5
SQL    GATE-CS-2006
Discuss it

Question 67 Explanation:
Query 1 and Query 2 will give the same result if all the customers have distinct balance. So, for some databases, the result of query 1 and query 2 will be same.
Now, let us consider a fact that all the entries in the database have the same value for balance. Ideally, all the customers should have rank 1, but both the queries will give all the customers a rank equal to the number of customers in the database. So, both the queries do not give us the required output.
Thus, C is the correct choice.
Please comment below if you find anything wrong in the above post.
 Question 68
Consider the relation "enrolled(student, course)" in which (student, course) is the primary key, and the relation "paid(student, amount)" where student is the primary key. Assume no null values and no foreign keys or integrity constraints. Given the following four queries:
Query1: select student from enrolled where
student in (select student from paid)
Query2: select student from paid where
student in (select student from enrolled)
Query3: select E.student from enrolled E, paid P
where E.student = P.student
Query4:  select student from paid where exists
(select * from enrolled where enrolled.student
= paid.student) 
Which one of the following statements is correct?
 A All queries return identical row sets for any database B Query2 and Query4 return identical row sets for all databases but there exist databases for which Query1 and Query2 return different row sets. C There exist databases for which Query3 returns strictly fewer rows than Query2 D There exist databases for which Query4 will encounter an integrity violation at runtime.
SQL    GATE-CS-2006
Discuss it

Question 68 Explanation:
 Question 69
Consider the relation enrolled(student, course) in which (student, course) is the primary key, and the relation paid(student, amount), where student is the primary key. Assume no null values and no foreign keys or integrity constraints. Assume that amounts 6000, 7000, 8000, 9000 and 10000 were each paid by 20% of the students. Consider these query plans (Plan 1 on left, Plan 2 on right) to "list all courses taken by students who have paid more than x". A disk seek takes 4ms, disk data transfer bandwidth is 300 MB/s and checking a tuple to see if amount is greater than x takes 10 micro-seconds. Which of the following statements is correct?
 A Plan 1 and Plan 2 will not output identical row sets for all databases. B A course may be listed more than once in the output of Plan 1 for some databases C For x = 5000, Plan 1 executes faster than Plan 2 for all databases. D For x = 9000, Plan I executes slower than Plan 2 for all databases.
GATE-CS-2006
Discuss it

Question 69 Explanation:
 Question 70
The following functional dependencies are given:
AB   CD, AF   D, DE   F, C  G , F   E, G   A

Which one of the following options is false?
 A CF+ = {ACDEFG} B BG+ = {ABCDG} C AF+ = {ACDEFG} D AB+ = {ABCDFG}
GATE-CS-2006
Discuss it

Question 70 Explanation:
 Question 71
The 2n vertices of a graph G corresponds to all subsets of a set of size n, for n >= 6 . Two vertices of G are adjacent if and only if the corresponding sets intersect in exactly two elements. The number of vertices of degree zero in G is:
 A 1 B n C n+1 D 2n
Graph Theory    GATE-CS-2006
Discuss it

Question 71 Explanation:
There are n nodes which are single and 1 node which belong to empty set. And since they are not having 2 or more elements so they won’t be connected to anyone hence total number of nodes with degree 0 are n+1 hence answer should be none. Thanks to roger for the explanation.
 Question 72
The 2n vertices of a graph G corresponds to all subsets of a set of size n, for n >= 6. Two vertices of G are adjacent if and only if the corresponding sets intersect in exactly two elements. The maximum degree of a vertex in G is:
 A (n/2)C2 x 2n/2 B 2n-2 C 2n-3 x 3 D 2n-1
GATE-CS-2006
Discuss it

Question 72 Explanation:
Let us take an example {a, b, c, d, e, f} The maximum degree would be of any vertex that corresponds to a sunset with half vertices. For example consider {a, b, c}. It has degree as 24. It intersects with 8 subsets with intersection as {a, b}. The subsets are {a, b}, {a, b, d}, {a, b, e}, {a, b, f}, {a, b, d, e}, {a, b, e, f}, {a, b, d, f} and {a, b, d, e, f}. Similarly, it intersects with 8 vertices with intersection as {a, c} and 8 more vertices with intersection as {b, c}. There are n/2 C 2 ways to pick two elements from a subset of size n/2. Every such subset can have intersection with 2n/2 other subsets.
 Question 73
The 2n vertices of a graph G corresponds to all subsets of a set of size n, for n >= 6. Two vertices of G are adjacent if and only if the corresponding sets intersect in exactly two elements. The number of connected components in G is:
 A n B n+2 C 2n/2 D 2n / n
Graph Theory    GATE-CS-2006
Discuss it

Question 73 Explanation:
n+1 nodes of the graph not connected to anyone as explained in question 70 while others are connected so total number of connected components are n+2 (n+1 connected components by each of the n+1 vertices plus 1 connected component by remaining vertices).
 Question 74
Consider two cache organizations: The first one is 32 KB 2-way set associative with 32-byte block size. The second one is of the same size but direct mapped. The size of an address is 32 bits in both cases. A 2-to-1 multiplexer has a latency of 0.6 ns while a kbit comparator has a latency of k/10 ns. The hit latency of the set associative organization is h1 while that of the direct mapped one is h2. The value of h1 is:
 A 2.4 ns B 2.3 ns C 1.8 ns D 1.7 ns
Computer Organization and Architecture    GATE-CS-2006
Discuss it

Question 74 Explanation:
Cache size = 32 KB = 32 * 210 bytes Cache block size = 32 bytes Number of blocks = 2
Total combinations are : = cache size / (Number of blocks * block size) = 32 * 210 / (2 * 32) = 512 = 29
Therefore, number of index bits = 9
Since, cache block size is 32 bytes i.e. 25 bytes. Number of offset bits = 5
So, number of tag bits = 32 – 9 – 5 = 18
Hit latency (h1) = 0.6 + (18 / 10) ns = 2.4 ns

Thus, option (A) is correct.

Please comment below if you find anything wrong in the above post.
 Question 75
Consider two cache organizations: The first one is 32 KB 2-way set associative with 32-byte block size. The second one is of the same size but direct mapped. The size of an address is 32 bits in both cases. A 2-to-1 multiplexer has a latency of 0.6 ns while a kbit comparator has a latency of k/10 ns. The hit latency of the set associative organization is h1 while that of the direct mapped one is h2. The value of h2 is:
 A 2.4 ns B 2.3 C 1.8 D 1.7
Computer Organization and Architecture    GATE-CS-2006
Discuss it

Question 75 Explanation:
Cache size = 32 KB = 32 * 210 bytes Cache block size = 32 bytes Number of blocks = 1
Total combinations are : = cache size / (Number of blocks * block size) = 32 * 210 / (1 * 32) = 1024 = 210
Therefore, number of index bits = 10
Since, cache block size is 32 bytes i.e. 25 bytes. Number of offset bits = 5
So, number of tag bits = 32 – 10 – 5 = 17
Hit latency (h2) = (17 / 10) ns = 1.7 ns

Thus, option (D) is correct.

Please comment below if you find anything wrong in the above post.
 Question 76
A 3-ary max heap is like a binary max heap, but instead of 2 children, nodes have 3 children. A 3-ary heap can be represented by an array as follows: The root is stored in the first location, a[0], nodes in the next level, from left to right, is stored from a[1] to a[3]. The nodes from the second level of the tree from left to right are stored from a[4] location onward. An item x can be inserted into a 3-ary heap containing n items by placing x in the location a[n] and pushing it up the tree to satisfy the heap property. Which one of the following is a valid sequence of elements in an array representing 3-ary max heap?
 A 1, 3, 5, 6, 8, 9 B 9, 6, 3, 1, 8, 5 C 9, 3, 6, 8, 5, 1 D 9, 5, 6, 8, 3, 1
GATE-CS-2006
Discuss it

Question 76 Explanation:
Following 3-ary Max Heap can be constructed from sequence given option (D)
                                      9
/  |   \
/     |     \
5       6      8
/  |
/    |
3      1

 Question 77
A 3-ary max heap is like a binary max heap, but instead of 2 children, nodes have 3 children. A 3-ary heap can be represented by an array as follows: The root is stored in the first location, a[0], nodes in the next level, from left to right, is stored from a[1] to a[3]. The nodes from the second level of the tree from left to right are stored from a[4] location onward. An item x can be inserted into a 3-ary heap containing n items by placing x in the location a[n] and pushing it up the tree to satisfy the heap property. Suppose the elements 7, 2, 10 and 4 are inserted, in that order, into the valid 3- ary max heap found in the above question, Which one of the following is the sequence of items in the array representing the resultant heap?
 A 10, 7, 9, 8, 3, 1, 5, 2, 6, 4 B 10, 9, 8, 7, 6, 5, 4, 3, 2, 1 C 10, 9, 4, 5, 7, 6, 8, 2, 1, 3 D 10, 8, 6, 9, 7, 2, 3, 4, 1, 5
GATE-CS-2006
Discuss it

Question 77 Explanation:
After insertion of 7
                                          9
/   |   \
/     |     \
7       6       8
/ | \
/   |  \
3    1    5

After insertion of 2
                                           9
/    |   \
/      |     \
7        6       8
/ | \       /
/   |  \     /
3    1    5  2

After insertion of 10
                                 10
/    |   \
/      |     \
7         9       8
/ | \       / |
/   |  \     /  |
3    1    5  2    6

After insertion of 4
                                 10
/   |   \
/     |     \
7        9       8
/ | \      / | \
/   |  \    /  |   \
3    1    5  2   6    4

 Question 78
Barrier is a synchronization construct where a set of processes synchronizes globally i.e. each process in the set arrives at the barrier and waits for all others to arrive and then all processes leave the barrier. Let the number of processes in the set be three and S be a binary semaphore with the usual P and V functions. Consider the following C implementation of a barrier with line numbers shown on left.
void barrier (void) {
1:   P(S);
2:   process_arrived++;
3.   V(S);
4:   while (process_arrived !=3);
5:   P(S);
6:   process_left++;
7:   if (process_left==3) {
8:      process_arrived = 0;
9:      process_left = 0;
10:  }
11:  V(S);
} 
The variables process_arrived and process_left are shared among all processes and are initialized to zero. In a concurrent program all the three processes call the barrier function when they need to synchronize globally. The above implementation of barrier is incorrect. Which one of the following is true?
 A The barrier implementation is wrong due to the use of binary semaphore S B The barrier implementation may lead to a deadlock if two barrier in invocations are used in immediate succession. C Lines 6 to 10 need not be inside a critical section D The barrier implementation is correct if there are only two processes instead of three.
Process Management    GATE-CS-2006
Discuss it

Question 78 Explanation:
It is possible that process_arrived becomes greater than 3. It will not be possible for process arrived to become 3 again, hence deadlock.
 Question 79
Barrier is a synchronization construct where a set of processes synchronizes globally i.e. each process in the set arrives at the barrier and waits for all others to arrive and then all processes leave the barrier. Let the number of processes in the set be three and S be a binary semaphore with the usual P and V functions. Consider the following C implementation of a barrier with line numbers shown on left.
void barrier (void) {
1:   P(S);
2:   process_arrived++;
3.   V(S);
4:   while (process_arrived !=3);
5:   P(S);
6:   process_left++;
7:   if (process_left==3) {
8:      process_arrived = 0;
9:      process_left = 0;
10:  }
11:  V(S);
} 
The variables process_arrived and process_left are shared among all processes and are initialized to zero. In a concurrent program all the three processes call the barrier function when they need to synchronize globally. Which one of the following rectifies the problem in the implementation?
 A Lines 6 to 10 are simply replaced by process_arrived-- B At the beginning of the barrier the first process to enter the barrier waits until process_arrived becomes zero before proceeding to execute P(S). C Context switch is disabled at the beginning of the barrier and re-enabled at the end. D The variable process_left is made private instead of shared
Process Management    GATE-CS-2006
Discuss it

Question 79 Explanation:

Step ‘2’ should not be executed when the process enters the barrier second time till other two processes have not completed their 7th step. This is to prevent variable process_arrived becoming greater than 3.
So, when variable process_arrived becomes zero and variable process_left also becomes zero then the problem of deadlock will be resolved.
Thus, at the beginning of the barrier the first process to enter the barrier waits until process_arrived becomes zero before proceeding to execute P(S).

Thus, option (B) is correct.

Please comment below if you find anything wrong in the above post.
 Question 80
A CPU has a 32 KB direct mapped cache with 128-byte block size. Suppose A is a twodimensional array of size 512×512 with elements that occupy 8-bytes each. Consider the following two C code segments, P1 and P2. P1:

for (i=0; i<512; i++) {
for (j=0; j<512; j++) {
x += A[i][j];
}
} 
P2:

for (i=0; i<512; i++) {
for (j=0; j<512; j++) {
x += A[j][i];
}
}
P1 and P2 are executed independently with the same initial state, namely, the array A is not in the cache and i, j, x are in registers. Let the number of cache misses experienced by P1 be M1 and that for P2 be M2 . The value of M1 is:
 A 0 B 2048 C 16384 D 262144
Computer Organization and Architecture    GATE-CS-2006
Discuss it

Question 80 Explanation:
[P1] runs the loops in a way that access elements of A in row major order and [P2] accesses elements in column major order. No of cache blocks = CacheSize/BlockSize = 32KB / 128 Byte = 256 No. of array elements in Each Block = BlockSize/ElementSize = 128 Byte / 8 Byte = 16 Total Misses for [P1] = ArraySize * (No. of array elements in Each Block) / (No of cache blocks) = 512 * 512 * 16 / 256 = 16384
 Question 81
A CPU has a 32 KB direct mapped cache with 128-byte block size. Suppose A is a twodimensional array of size 512×512 with elements that occupy 8-bytes each. Consider the following two C code segments, P1 and P2. P1:

for (i=0; i<512; i++) {
for (j=0; j<512; j++) {
x += A[i][j];
}
} 
P2:

for (i=0; i<512; i++) {
for (j=0; j<512; j++) {
x += A[j][i];
}
}
P1 and P2 are executed independently with the same initial state, namely, the array A is not in the cache and i, j, x are in registers. Let the number of cache misses experienced by P1 be M1 and that for P2 be M2 . The value of the ratio M1/M2 is:
 A 0 B 1/16 C 1/8 D 16
Computer Organization and Architecture    GATE-CS-2006
Discuss it

Question 81 Explanation:
[P2] runs the loops in a way that access elements of A in row major order and [P2] accesses elements in column major order. No of cache blocks = CacheSize/BlockSize = 32KB / 128 Byte = 256 No. of array elements in Each Block = BlockSize/ElementSize = 128 Byte / 8 Byte = 16 Total Misses for [P1] = ArraySize * (No. of array elements in Each Block) / (No of cache blocks) = 512 * 512 * 16 / 256 = 16384 Total Misses for [P2] = Total Number of elements in array (For every element, there would be a miss) = 512 * 512 = 262144. Ration m1/m2 = 16384 / 262144 = 1/16.
 Question 82
Consider the diagram shown below where a number of LANs are connected by (transparent) bridges. In order to avoid packets looping through circuits in the graph, the bridges organize themselves in a spanning tree. First, the root bridge is identified as the bridge with the least serial number. Next, the root sends out (one or more) data units to enable the setting up of the spanning tree of shortest paths from the root bridge to each bridge. Each bridge identifies a port (the root port) through which it will forward frames to the root bridge. Port conflicts are always resolved in favour of the port with the lower index value. When there is a possibility of multiple bridges forwarding to the same LAN (but not through the root port), ties are broken as follows: bridges closest to the root get preference and between such bridges, the one with the lowest serial number is preferred. For the given connection of LANs by bridges, which one of the following choices represents the depth first traversal of the spanning tree of bridges? [2 marks]
 A B1, B5, B3, B4, B2 B B1, B3, B5, B2, B4 C B1, B5, B2, B3, B4 D B1, B3, B4, B5, B2
Discuss it

Question 82 Explanation:
Spanning tree is
                B1
/  \
/      \
B5      B3
/  \
/     \
B4     B2 
Note that B4 and B2 are connected through B3 (Not B5) because B3 has lower serial number than B5. One DFS traversal of tree is B1 B5 B3 B4 B2 Hence Option A is the Answer
 Question 83
Consider the data given in above question. Consider the correct spanning tree for the previous question. Let host H1 send out a broadcast ping packet. Which of the following options represents the correct forwarding table on B3?[2 marks] (A)
 Hosts Port H1, H2, H3, H4 3 H5, H6, H9, H10 1 H7, H8, H11, H12 2
(B)
 Hosts Port H1, H2 4 H3, H4 3 H5, H6 1 H7, H8, H9, H10,H11,H12 2
(C)
 Hosts Port H3, H4 3 H5, H6, H9, H10 1 H1, H2 4 H7, H8, H11, H12 2
(D)
 Hosts Port H1, H2, H3, H4 3 H5, H7, H9, H10 1 H7, H8, H11, H12 4
 A A B B C C D D
Discuss it

 Question 84
Which one of the following grammars generates the language L = {aibj | i ≠ j}


 A A B B C C D D
Context free languages and Push-down automata    GATE-CS-2006
Discuss it

Question 84 Explanation:
Language L contains the strings : {abb, aab, abbb, aabbb, aaabb, aa, bb, .......}, i.e, all a's appear before b's in a string, and "number of a's" is not equal to "number of b's", So i ≠ j.
Here Grammar A, B & C also generate the string "ab", where i = j, and many more strings with i = j, hence these grammars do not generate the language L, because for a string that belongs to language L, exponent i should not be equal to exponent  j.
Grammar D : This Grammar never generates a string with equal no of a's and b's, i.e. i=j. Hence this grammar generates the language L. Hence Option D.
 Question 85
In the correct grammar of above question, what is the length of the derivation (number of steps starring from S) to generate the string albm with l ≠ m?
 A max(l,m) + 2 B l + m + 2 C l + m + 3 D max(l, m) + 3
Context free languages and Push-down automata    GATE-CS-2006
Discuss it

Question 85 Explanation:
Correct grammar of the last question was (D), which is:
S -> AC|CB
C -> aCb|epsilon
A -> aA|a
B -> Bb|b

Now, the most optimal and intuitive way to generate a string of the form albm would be to first use "C -> aCb|epsilon" production rule to get as many a and b as we can, which would be min(l,m). To get the rest of the string, we could just use latter two production rules accordingly. Formally deriving the string of the general format albm from the above grammar -
1.	  S -> AC
2.          -> A(aCb)
3.          -> ....
4.          -> ....
5.          -> A(am C bm)
6.          -> A(am bm)
7.          -> aA(am bm)
8.          -> ....
9.          -> ....
10.         -> a(l-m-1)A(am bm)
11.         -> al bm


From above set of derivation steps we can count the total steps as follows:

Production 1 took 1 step       : 1                   [using S->AC]
Production 2-5 took steps      : min(l,m)            [using C->aCb]
Production 6 took 1 step       : 1                   [using C->epsilon]
Production 7-11 took steps     : max(l,m)-min(l,m)   [using A -> aA|a or B -> Bb|b]

Total steps   : max(l,m) + 2

Hence, answer should be (A): max(l,m) + 2 This explanation is contributed by Vineet Purswani.
There are 85 questions to complete.

## GATE CS Corner

See Placement Course for placement preparation, GATE Corner for GATE CS Preparation and Quiz Corner for all Quizzes on GeeksQuiz.