Question 1 
Consider the following C function.
float f(float x, int y) { float p, s; int i; for (s=1, p=1, i=1; i < y; i ++) { p*= x/i; s+=p; } return s; }For large values of y, the return value of the function f best approximates
x^y  
e^x  
ln(1 + x)  
x^x 
Discuss it
Question 1 Explanation:
See question 1 of http://www.geeksforgeeks.org/datastructuresandalgorithmsset5/
Question 2 
Assume the following C variable declaration
int *A [10], B[10][10];Of the following expressions I A[2] II A[2][3] III B[1] IV B[2][3] which will not give compiletime errors if used as left hand sides of assignment statements in a C program?
I, II, and IV only  
II, III, and IV only
 
II and IV only
 
IV only

Discuss it
Question 2 Explanation:
Question 3 
Let P(E) denote the probability of the event E. Given P(A) = 1, P(B) = 1/2, the values of P(A  B) and P(B  A) respectively are
1/4, 1/2  
1/2, 1/14  
1/2, 1  
1, 1/2 
Discuss it
Question 3 Explanation:
Conditional probability measures the probability of an event given that another event has occurred.
P(A  B) is Probability of A given B has occurred which is 1.
P(B  A) is probability of B given that A has occurred which is 1/2
Question 4 
Let A be a sequence of 8 distinct integers sorted in ascending order. How many distinct pairs of sequences, B and C are there such that (i) each is sorted in ascending order, (ii) B has 5 and C has 3 elements, and (iii) the result of merging B and C gives A?
2  
30  
56  
256 
Discuss it
Question 4 Explanation:
Suppose you have selected 3 elements from 8 in 8C3 ways, the remaining elements are treated as another array and merging both the arrays gives the sorted array. Here, you can select either 3 or 5.
=> 8C3 = 8C5 = 8!/(3!5!) = 7*8 = 56 Ways.
This solution is contributed by Anil Saikrishna Devarasetty
Question 5 
n couples are invited to a party with the condition that every husband should be accompanied by his wife. However, a wife need not be accompanied by her husband. The number of different gatherings possible at the party is
A  
B  
C  
D 
Discuss it
Question 5 Explanation:
There are three options for every couple.
1) Nobody goes to gathering 2) Wife alone goes 2) Both goSince there are n couples, total possible ways of gathering are 3^{n}
Question 6 
nk+1  
nk  
nk1  
nk2 
Discuss it
Question 6 Explanation:
The idea is to make a key root, put (k1) keys in one subtree and remaining nk keys in other subtree.
A Binary Search Tree (BST) is a tree in which all the nodes follow the belowmentioned properties −
 The left subtree of a node has a key less than or equal to its parent node's key.
 The right subtree of a node has a key greater than to its parent node's key.
Question 7 
Consider the set ∑* of all strings over the alphabet ∑ = {0, 1}. ∑* with the concatenation operator for strings
does not form a group  
forms a noncommutative group  
does not have a right identity element  
forms a group if the empty string is removed from ∑* 
Discuss it
Question 8 
Let G be an arbitrary graph with n nodes and k components. If a vertex is removed from G, the number of components in the resultant graph must necessarily lie between
k and n  
k  1 and k + 1  
k  1 and n  1  
k + 1 and n  k 
Discuss it
Question 8 Explanation:
Minimum: The removed vertex itself is a separate connected component. So removal of a vertex creates k1 components.
Maximum: It may be possible that the removed vertex disconnects all components. For example the removed vertex is center of a star. So removal creates n1 components.
Question 9 
Assuming all numbers are in 2's complement representation, which of the following numbers is divisible by 11111011?
11100111  
11100100  
11010111  
11011011 
Discuss it
Question 9 Explanation:
Since most significant bit is 1, all numbers are negative.
2's complement of divisor (11111011) = 1's complement + 1 = 00000100 + 1 = 00000101
So the given number is 5
The decimal value of option A is 25
Question 10 
For a pipelined CPU with a single ALU, consider the following situations
1. The j + 1st instruction uses the result of the jth instruction as an operand 2. The execution of a conditional jump instruction 3. The jth and j + 1st instructions require the ALU at the same timeWhich of the above can cause a hazard ?
1 and 2 only  
2 and 3 only  
3 only  
All of above 
Discuss it
Question 10 Explanation:
Case 1: Is of data dependency .this can’t be safe with single ALU so read after write.
Case 2:Conditional jumps are always hazardous they create conditional dependency in pipeline.
Case 3:This is write after read problem or concurrency dependency so hazardous
All the three are hazardous
So (D) is correct option.
Question 11 
Consider an array multiplier for multiplying two n bit numbers. If each gate in the circuit has a unit delay, the total delay of the multiplier is
Θ(1)  
Θ(log n)  
Θ(n)  
Θ(n^{2}) 
Discuss it
Question 11 Explanation:
Number of gates used in ‘n’ bit array multiplier (n * n) = (2n – 1)
Each gate in the circuit has a unit delay.
Total delay = 1 * (2n – 1 ) = O(2n – 1) = O(n)
Thus, option (C) is correct.
Please comment below if you find anything wrong in the above post.
Each gate in the circuit has a unit delay.
Total delay = 1 * (2n – 1 ) = O(2n – 1) = O(n)
Thus, option (C) is correct.
Please comment below if you find anything wrong in the above post.
Question 12 
Ram and Shyam have been asked to show that a certain problem Π is NPcomplete. Ram shows a polynomial time reduction from the 3SAT problem to Π, and Shyam shows a polynomial time reduction from Π to 3SAT. Which of the following can be inferred from these reductions ?
Π is NPhard but not NPcomplete  
Π is in NP, but is not NPcomplete  
Π is NPcomplete  
Π is neither NPhard, nor in NP 
Discuss it
Question 12 Explanation:
Since polynomial time reduction from the 3SAT problem to Π is possible, it is NP hard.
Since polynomial time reduction from Π to 3SAT is possible, it is NPComplete.
Question 13 
Nobody knows yet if P = NP. Consider the language L defined as follows :
Which of the following statements is true ?
L is recursive  
L is recursively enumerable but not recursive  
L is not recursively enumerable  
Whether L is recursive or not will be known after we find out if P = NP 
Discuss it
Question 13 Explanation:
Answer is A. in both case(P = NP or P != NP) L is regular, so L is recursive.
Thanks to Vikrant for the above explanation.
Question 14 
The regular expression 0*(10*)* denotes the same set as
(1*0)*1*  
0 + (0 + 10)*  
(0 + 1)* 10(0 + 1)*  
none of these 
Discuss it
Question 14 Explanation:
Given regular expression is 0*(10*)* A: (1*0)*1* All strings that can be generated from given regular expression can also be generated from this. B: 0 + (0 + 10)* and C: (0 + 1)* 10(0 + 1)* We can generate 11 from given regular expression which is not possible with B and C C: (0 + 1)* 10(0 + 1)* Not possible as we can produce {epsilon} from the given Regular Expression but not from C
Question 15 
If the strings of a language L can be effectively enumerated in lexicographic (i.e., alphabetic) order, which of the following statements is true ?
L is necessarily finite  
L is regular but not necessarily finite  
L is context free but not necessarily regular  
L is recursive but not necessarily context free 
Discuss it
Question 15 Explanation:
The strings of a language L can be effectively enumerated means a Turing machine exists for language L which will enumerate all valid strings of the language.
If the string is in lexicographic order then TM will accept the string and halt in the final state. But, if the string is not lexicographic order then TM will reject the string and halt in nonfinal state.
Thus, L is recursive language.
We can not construct PDA for language L. So, the given language is not context free.
Thus, option (D) is correct.
Please comment below if you find anything wrong in the above post.
Question 16 
Which of the following suffices to convert an arbitrary CFG to an LL(1) grammar?
Removing left recursion alone  
Factoring the grammar alone  
Removing left recursion and factoring the grammar  
None of these 
Discuss it
Question 16 Explanation:
Removing left recursion and factoring the grammar do not suffice to convert an arbitrary CFG to LL(1) grammar.
http://pages.cpsc.ucalgary.ca/~robin/class/411/LL1.3.html
Question 17 
Assume that the SLR parser for a grammar G has n1 states and the LALR parser for G has n2 states. The relationship between n1 and n2 is:
n1 is necessarily less than n2  
n1 is necessarily equal to n2  
n1 is necessarily greater than n2  
none of these 
Discuss it
Question 17 Explanation:
Question 18 
In a bottomup evaluation of a syntax directed definition, inherited attributes can
always be evaluated  
be evaluated only if the definition is Lattributed  
be evaluated only if the definition has synthesized attributes  
never be evaluated 
Discuss it
Question 18 Explanation:
A Syntax Directed Definition (SDD) is called S Attributed if it has only synthesized attributes.
LAttributed Definitions contain both synthesized and inherited attributes but do not need to build a dependency graph to evaluate them.
References:
http://cse.iitkgp.ac.in/~bivasm/notes/SDD.pdf
Question 19 
Suppose the numbers 7, 5, 1, 8, 3, 6, 0, 9, 4, 2 are inserted in that order into an initially empty binary search tree. The binary search tree uses the usual ordering on natural numbers. What is the inorder traversal sequence of the resultant tree ?
7 5 1 0 3 2 4 6 8 9  
0 2 4 3 1 6 5 9 8 7  
0 1 2 3 4 5 6 7 8 9  
9 8 6 4 2 3 0 1 5 7 
Discuss it
Question 19 Explanation:
Inorder traversal of Binary Search Tree always produces keys in increasing order.
Question 20 
Consider the following three claims
1. (n + k)^{m} = Θ(n^{m}), where k and m are constants 2. 2^{n + 1} = O(2^{n}) 3. 2^{2n + 1} = O(2^{n})Which of these claims are correct ?
1 and 2  
1 and 3  
2 and 3  
1, 2, and 3 
Discuss it
Question 20 Explanation:
(n + k)^{m} and Θ(n^{m}) are asymptotically same as theta notation can always be written by taking the leading order term in a polynomial expression.
2^{n + 1} and O(2^{n}) are also asymptotically same as 2^{n + 1} can be written as 2 * 2^{n} and constant multiplication/addition doesn't matter in theta notation.
2^{2n + 1} and O(2^{n}) are not same as constant is in power.
See Asymptotic Notations for more details.
Question 21 
Consider the following graph
Among the following sequences
I) a b e g h f
II) a b f e h g
III) a b f h g e
IV) a f g h b e Which are depth first traversals of the above graph? (GATE CS 2003)
Among the following sequences
I) a b e g h f
II) a b f e h g
III) a b f h g e
IV) a f g h b e Which are depth first traversals of the above graph? (GATE CS 2003)
I, II and IV only  
I and IV only  
II, III and IV only  
I, III and IV only 
Discuss it
Question 21 Explanation:
DFS of a graph
1) Visits a node. 2) Do following for every unvisited adjacent. a) Completely explores all vertices through current adjacent using recursive call to DFS.There can be any DFS possible as we may pick different vertices as starting points and we may pick adjacents in different orders. (i) a b e g h f [Visit a, explore all adjacents through b, and so on..]. In this b's adjacent e is picked first (iii) a b f h g e [Visit a, explore all adjacents through b, and so on..]. In this b's adjacent f is picked first (iv) a f g h b e [Visit a, explore all adjacents through f, and so on..]. In this f's adjacent g is picked first (ii) a b f e h g can not be an answer as e is visited after f [e is not an adjacent of f and all adjcents of f are not explored yet]
Question 22 
The usual Θ(n^{2}) implementation of Insertion Sort to sort an array uses linear search to identify the position where an element is to be inserted into the already sorted part of the array. If, instead, we use binary search to identify the position, the worst case running time will
1)
2)
3)
become Θ(n log n)
4) become Θ(n)
remain Θ(n^{2})  
become Θ(n (log n)^{2})  
become Θ(n log n)  
become Θ(n) 
Discuss it
Question 22 Explanation:
See Question 1 of http://www.geeksforgeeks.org/datastructuresandalgorithmsset6/
Also see Binary Insertion Sort
Question 23 
In a heap with n elements with the smallest element at the root, the 7th smallest element can be found in time
Θ(n log n)  
Θ(n)  
Θ(log n)  
Θ(1) 
Discuss it
Question 23 Explanation:
In order to find out the kth smallest element, we have to first extract 6 elements from heap and then root of the resultant heap will be the kth smallest.Total time complexity = 6 Extractmin operations = 6*log2n = O(log2n)
But we can find out kth smallest from heap using a clever approach by extracting elements from heap nondestructively. We will use extra space to create a new minheap which will contain maximum k elements at any time.
Algorithm :
Initialize the root element of newheap with the root of old heap (minimum element)
For k1 times repeat the following :
Extract the root of the new minheap using extractmin and insert the 2 children of the extracted root from the original heap into the new heap. Resulting heap will contain k elements and root of which will be our kth smallest in the original heap. This grows the new heap by one on every removal (remove one, add two), which means it will never hold more than K elements, and so the removeoneaddtwo will take O(3*log(K)). After k iterations, it is O(3*k*logk) = O(k*logk).
In order to implement this, Nodes in the new heap should store indexes of their corresponding nodes in the original heap, rather than the node values themselves.
For 7 elements, it will take 7log7 = O(1) time as new heap will create only 7 elements.
See question 1 of http://www.geeksforgeeks.org/datastructuresandalgorithmsset9/
This solution is contributed by Pranjul Ahujka
Question 24 
Which of the following statements is FALSE ?
In statically typed language, each variable in a program has a fixed type  
In untyped languages, values do not have any types  
In dynamically typed languages, variables have no types  
In all statically typed languages, each variable in a program is associated with values of only a single type during the execution of the program 
Discuss it
Question 24 Explanation:
This is an ambiguous question. "Untyped language" has no standard wellformulated definition, thus answering this question would be a bit difficult.
(A) Statically typed languages have one type associated to a variable, which is fixed once it has been deduced. Though, types could either be specified while code editing by the coder (Eg. C, Java), or it can be inferred at compile time (Eg. C++11, Haskell). Hence, after compiletime, every variable is bound to one fixed type, making this statement [TRUE]
(B) According to one definition, untype languages store values in form of bits, thus neither variables nor values have any types associated to them. Hence this statement becomes [TRUE]
(C) Dynamically typed languages deduce types of values and bind them to the variables storing those values. Hence, values sure have fixed types, but variables don't have fixed types bound to them. Although we can say that binding a type to a variable according to values makes them typeful, but they don't have one fixed type. This statement has some ambiguity. [TRUE/FALSE]
(D) Same reason as of (A) [TRUE]
Hence, correct answer should be (C)
This solution is contributed by Vineet Purswani.
Question 25 
Using a larger block size in a fixed block size file system leads to :
better disk throughput but poorer disk space utilization  
better disk throughput and better disk space utilization  
poorer disk throughput but better disk space utilization  
poorer disk throughput and poorer disk space utilization 
Discuss it
Question 25 Explanation:
Using larger block size makes disk utilization poorer as more space would be wasted for small data in a block. It may make throughput better as the number of blocks would decrease.
A larger block size guarantees that more data from a single file can be written or read at a time into a single block without having to move the disk ́s head to another spot on the disk. The less time you spend moving your heads across the disk, the more continuous reads/writes per second. The smaller the block size, the more frequent it is required to move before a read/write can occur. Larger block size means less number of blocks to fetch and hence better throughput. But larger block size also means space is wasted when only small size is required and hence poor utilization.
This solution is contributed by Nitika Bansal
This solution is contributed by Nitika Bansal
Question 26 
In a system with 32 bit virtual addresses and 1 KB page size, use of onelevel page tables for virtual to physical address translation is not practical because of
the large amount of internal fragmentation  
the large amount of external fragmentation  
the large memory overhead in maintaining page tables  
the large computation overhead in the translation process 
Discuss it
Question 26 Explanation:
See question 4 of http://www.geeksforgeeks.org/operatingsystemsset4/
Question 27 
Which of the following assertions is FALSE about the Internet Protocol (IP) ?
It is possible for a computer to have multiple IP addresses  
IP packets from the same source to the same destination can take different routes in the network  
IP ensures that a packet is discarded if it is unable to reach its destination within a given number of hops  
The packet source cannot set the route of an outgoing packets; the route is determined only by the routing tables in the routers on the way 
Discuss it
Question 27 Explanation:
See following liens from http://en.wikipedia.org/wiki/Source_routing
In computer networking, source routing allows a sender of a packet to partially or completely specify the route the packet takes through the network.
In the Internet Protocol, two header options are available which are rarely used: "strict source and record route" (SSRR) and "loose source and record route" (LSRR). Because of security concerns, packets marked LSRR are frequently blocked on the Internet. If not blocked, LSRR can allow an attacker to spoof its address but still successfully receive response packets.
Question 28 
Which of the following functionalities must be implemented by a transport protocol over and above the network protocol ?
Recovery from packet losses  
Detection of duplicate packets  
Packet delivery in the correct order  
End to end connectivity 
Discuss it
Question 28 Explanation:
End to end connectivity is the required functionality provided by Trnasport protocol. UDP of transport layer protocol that doesn't implement other three functionalities, they are implemented only in TCP.
Question 29 
Which of the following scenarios may lead to an irrecoverable error in a database system ?
A transaction writes a data item after it is read by an uncommitted transaction  
A transaction reads a data item after it is read by an uncommitted transaction  
A transaction reads a data item after it is written by a committed transaction  
A transaction reads a data item after it is written by an uncommitted transaction 
Discuss it
Question 29 Explanation:
Option C is a normal operation.
Option B is also fine as no write operation is involved.
Option A can be recovered, but option D can't be.
See this for an example.
Question 30 
Consider the following SQL query
select distinct al, a2,........., an from r1, r2,........, rm where PFor an arbitrary predicate P, this query is equivalent to which of the following relational algebra expressions ?
A  
B  
C  
D 
Discuss it
Question 30 Explanation:
Cross product (x) combines the tuples of one relation with all the tuples of the other relation. Thus, tuples of relation r1, r2 …. rn are combined.
Select operator is used to select resultant tuples.
Projection operator is used to select a subset of attributes from the resultant tuples by specifying the names of the attributes. So attributes a1, a2, an are projected from the resultant tuples.
Thus, option (A) is correct.
Please comment below if you find anything wrong in the above post.
Question 31 
Let (5, ≤) be a partial order with two minimal elements a and b, and a maximum element c.
Let P : S → {True, False} be a predicate defined on S. Suppose that P(a) = True, P(b) = False and P(x) ⇒ P(y) for all x, y ∈ S satisfying x ≤ y, where ⇒ stands for logical implication.Which of the following statements CANNOT be true ?
P(x) = True for all x ∈ S such that x ≠ b  
P(x) = False for all x ∈ S such that x ≠ a and x ≠ c  
P(x) = False for all x ∈ S such that b ≤ x and x ≠ c  
P(x) = False for all x ∈ S such that a ≤ x and b ≤ x 
Discuss it
Question 31 Explanation:
'a' and 'b' are given as minimal elements. No other element in S is of lower order than either a or b. 'c' is given as maximum element. So, c is of higher order than any other element in S.
P(a) = True means all elements 'x' which have an edge from element 'a' have to be true. Since there is an edge from 'a', we have to satisfy formula P(a) => P(x), which can only be done by setting P(x) = True.
Elements which have an edge from b can be anything because formula P(b) => P(x) is satisfied as P(b) = False.
(A) This statement is true because making all elements true trivially satisfy formula P(x) => P(y).
(B) This statement is true if all elements are connected from b then all elements can be false.
(C) This statement is true because b<=x ensures x!=a and for all other elements P(x) can be false without violating the given implication.
(D) This statement is false. Since, P(a) = true , for all 'x' such that a<=x, P(x) must be true. We do have at least one such 'x', which is 'c' as it is the maximum element.
Thus, option (D) is the answer.
Please comment below if you find anything wrong in the above post.
Question 32 
Which of the following is a valid first order formula ? (Here α and β are first order formulae with x as their only free variable)
A  
B  
C  
D 
Discuss it
Question 33 
Consider the following formula a and its two interpretations I1 and I2
Which of the following statements is true?
I1 satisfies α, I2 does not  
I2 satisfies α, I1 does not  
Neither I2 nor I2 satisfies α  
Both I1 and I2 satisfy α 
Discuss it
Question 33 Explanation:
First of all, note that, in α, ¬Qyy is always false, because every number divides itself. Also not that rightmost formula (∀x)[¬Px] is always false, because clearly it is not the case that every number is not the prime number (in case of I1), nor it is the case that every number is not the composite number (in case of I2). Also note that, variable x in this expression is not same as variable x in leftside expression, they are independent. In fact, we can rewrite α as α:(∀x)[Px⇔(∀y)[Qxy⇔¬Qyy]]⇒(∀z)[¬Pz].
Let us consider I1 first. So let us assign some value to x, and see if it satisfies α. We can partition assignments of x into 3 parts : when x is prime, when x is composite, when x is 1.
 When x is prime : Px is true, also Qxy is false for all y except 1, because only 1 divides x. So formula Qxy⇔¬Qyy is true for all y except 1, but due to ∀y outside this, whole formula ∀y[Qxy⇔¬Qyy] becomes false, because it would have been true if Qxy⇔¬Qyy was true for every y. So now [Px⇔(∀y)[Qxy⇔¬Qyy]] becomes false for all x whenever x is prime. Since for some x (where x is prime), [Px⇔(∀y)[Qxy⇔¬Qyy]] is false, so (∀x)[Px⇔(∀y)[Qxy⇔¬Qyy]] is definitely false, since false⇒ false is true, so α is true in I1, and we don't need other cases of x.
 Now consider I2. Here also we can argue in the same way as we did in cases of I1, here case of x being composite leads to false⇒false, and so α is also true in I2, hence option (D) is correct.
Question 34 
m identical balls are to be placed in n distinct bags. You are given that m ≥ kn, where, k is a natural number ≥ 1. In how many ways can the balls be placed in the bags if each bag must contain at least k balls?
A  
B  
C  
D 
Discuss it
Question 34 Explanation:
This is very simple application of stars and bars. Since we want atleast k balls in each bag, so first we put kn balls into bags, k balls in each bag. Now we are left with m  kn balls, and we have to put them into n bags such that each bag may receive 0 or more balls. So applying theorem 2 of stars and bars with m  nk stars and n bars, we get number of ways to be ^{m−kn+n1} C_{n−1}. So option (B) is correct.
Source: http://www.cse.iitd.ac.in/~mittal/gate/gate_math_2003.html
Question 35 
(m/6) (21m  39) + 4  
(m/6) (4m^{2}  3m + 5)  
(m/2) (m^{2.5}  11m + 20)  5  
(m/6) (5m^{3}  34m^{2} + 137m  104) + (5/6) 
Discuss it
Question 35 Explanation:
One easy way to solve this is to try putting different values of m. For example, we know T(1) = 1. If we put m = 1, only A and B satisfy the result. m = 2 T(2) = T(1) + 1 = 2 T(3) = T(2) + 1 = 3 T(4) = T(3) + 2 = 5 Both A & B produce 5 m = 3 T(9) = T(4) + 2*5 + 1 = 5 + 10 + 1 = 16 Both A & B produce 16 m = 4 T(16) = T(9) + 3*7 + 1 = 16 + 21 + 1 = 38 Only B produces 38, A produces 34 which doesn't match
Question 36 
How many perfect matchings are there in a complete graph of 6 vertices ?
15  
24  
30  
60 
Discuss it
Question 36 Explanation:
A perfect matching, every vertex of the graph is incident to exactly one edge of the matching. A perfect matching is therefore a matching of a graph containing n/2 edges, the largest possible, meaning perfect matchings are only possible on graphs with an even number of vertices. (Source http://mathworld.wolfram.com/PerfectMatching.html)
Question 37 
Let f : A → B be an injective (onetoone) function.
Define g : 2^{A} → 2^{B} as : g(C) = {f(x)  x ∈ C}, for all subsets C of A. Define h : 2^{B} → 2^{A} as : h(D) = {x  x ∈ A, f(x) ∈ D}, for all subsets D of B.Which of the following statements is always true ?
g(h(D)) ⊆ D  
g(h(D)) ⊇ D  
g(h(D)) ∩ D = ф  
g(h(D)) ∩ (B  D) ≠ ф 
Discuss it
Question 38 
Consider the set {a, b, c} with binary operators + and × defined as follows :
For example, a + c = c, c + a = a, c × b = c and b × c = a. Given the following set of equations :
+  a  b  c  ×  a  b  c  
a  b  a  c  a  a  b  c  
b  a  b  c  b  b  c  a  
c  a  c  b  c  c  c  b 
(a × x) + (a × y) = c (b × x) + (c × y) = cThe number of solution(s) (i.e., pair(s) (x, y)) that satisfy the equations is :
0  
1  
2  
3 
Discuss it
Question 38 Explanation:
For this question, we will have to consider each case separately and check whether it satisfies both the conditions or not.
(a,a) ⇒ (a*a) + (a*a) = a + a = b ≠ c ⇒ (a,a) is not a solution.
(a,b) ⇒ (a*a) + (a*b) = a + b = a ≠ c ⇒ (a,b) is not a solution.
(a,c) ⇒ (a*a) + (a*c) = a + c = c
(b*a) + (c*c) = b + b = b ≠ c ⇒ (a,c) is not a solution.
(b,a) ⇒ (a*b) + (a*a) = b + a = a ≠ c ⇒ (b,a) is not a solution. (b,b) ⇒ (a*b) + (a*b) = b + b = b ≠ c ⇒ (b,b) is not a solution. (b,c) ⇒ (a*b) + (a*c) = b + c = c(b*b) + (c*c) = c + b = c ⇒ (b,c) is a solution
(c,a) ⇒ (a*c) + (a*a) = c + a = a ≠ c ⇒ (c,a) is not a solution. (c,b) ⇒ (a*c) + (a*b) = c + b = c(b*c) + (c*b) = a + c = c ⇒ (c,b) is a solution
(c,c) ⇒ (a*c) + (a*c) = c + c = b ≠ c ⇒ (c,c) is not a solution. Thus, we have 2 solutions, (b,c) and (c,b). Hence, C is the correct choice. Please comment below if you find anything wrong in the above post.Question 39 
Let ∑ = (a, b, c, d, e) be an alphabet. We define an encoding scheme as follows :
g(a) = 3, g(b) = 5, g(c) = 7, g(d) = 9, g(e) = 11.
Which of the following numbers is the encoding h of a nonempty sequence of strings ?
2^{7} 3^{7} 5^{7}  
2^{8} 3^{8} 5^{8}  
2^{9} 3^{9} 5^{9}  
2^{10} 5^{10} 7^{10} 
Discuss it
Question 39 Explanation:
Since, the answer is a product of three prime numbers 2, 3 and 5. So, we have three nonempty sequence of strings : "a", "a" and "a".
f(s) = 2^{x} for some x Since, 7 and 9 are not multiple of 2. So, options (A) and (C) are eliminated.
f(a) = 2^{3} = 8 h = 2^{8} 3^{8}5^{8}
Thus, option (B) is correct.
Please comment below if you find anything wrong in the above post.
Question 40 
A graph G = (V, E) satisfies E ≤ 3 V  6. The mindegree of G is defined as . Therefore, mindegree of G cannot be
3  
4  
5  
6 
Discuss it
Question 40 Explanation:
Question 41 
Consider the following system of linear equations
Notice that the second and the third columns of the coefficient matrix are linearly dependent. For how many values of a, does this system of equations have infinitely many solutions?
0  
1  
2  
infinitely many 
Discuss it
Question 42 
A piecewise linear function f(x) is plotted using thick solid lines in the figure below (the plot is drawn to scale).
If we use the NewtonRaphson method to find the roots of f(x) = 0 using x0, x1 and x2 respectively as initial guesses, the roots obtained would be
1.3, 0.6, and 0.6 respectively  
0.6, 0.6, and 1.3 respectively  
1.3, 1.3, and 0.6 respectively  
1.3, 0.6, and 1.3 respectively 
Discuss it
Question 42 Explanation:
First of all, There is a mistake in coordinates of a given point. I have corrected that in red color.
Now in NewtonRaphson method, we draw a tangent from our guess point, and our new guess would be the point where this tangent cuts xaxis. Now we choose initial guess points one by one :
x0 : Tangent at this point is line AB itself, and that would cut xaxis at point (1.0,0.0) (found using equation of line AB). So our next guess would be 1.0. Point on the curve corresponding to this new guess 1.0 is shown as F. Now tangent at point F is line DE, which cuts xaxis at 1.3, and at this point, value of function is zero, so we found the root as 1.3. x1 : Tangent at this point is line BE, which cuts xaxis at 0.6, also function value is zero here, so we find root as 0.6. x2 : Tangent at this point is line CD, which cuts xaxis at 1.05 (again found by finding equation of line CD). Point on the curve corresponding to this new guess 1.05 is shown as G. Now tangent at point G is line DE, which cuts xaxis at 1.3, and at this point, value of function is zero, so we found the root as 1.3.Source: Question 60 of http://www.cse.iitd.ac.in/~mittal/gate/gate_math_2003.html
Question 43 
The following is a scheme for floating point number representation using 16 bits.
Bit position 15 14 . . . 9 8 . . . . .0 s e m Sign Exponent MantissaLet s,e, and m be the numbers represented in binary in the sign, exponent, and mantissa fields respectively. Then the floating point number represented is: What is the maximum difference between two successive real numbers representable in this system?
2^{40}  
2^{9}  
2^{22}  
2^{31} 
Discuss it
Question 43 Explanation:
Question 44 
A 1input, 2output synchronous sequential circuit behaves as follows :
Let zk, nk denote the number of 0's and 1's respectively in initial k bits of the input (zk + nk = k). The circuit outputs 00 until one of the following conditions holds.
zk  nk = 2. In this case, the output at the kth and all subsequent clock ticks is 10. nk  zk = 2. In this case, the output at the kth and all subsequent clock ticks is 01.What is the minimum number of states required in the state transition graph of the above circuit?
5  
6  
7  
8 
Discuss it
Question 44 Explanation:
The answer must be 5 to this question as we just need to count the difference of the number of 0's and 1's in the first k bit of a number. And we just need to count till this count reaches 2 or 2 (negative when number of 0's is less than number of 1's) . So, the possibilities are 2, 1, 0, 1 and 2 which represents the five states of the state transition diagram.
For state 2, the output of the circuit will be 01, for state 2, output will be 10 (both these states not having any outgoing transitions) and for other 3 states, output will be 00 as per the given description of the circuit.
Question 45 
The literal count of a boolean expression is the sum of the number of times each literal appears in the expression. For example, the literal count of (xy + xz') is 4. What are the minimum possible literal counts of the productofsum and sumofproduct representations respectively of the function given by the following Karnaugh map ? Here, X denotes "don't care"
(11, 9)  
(9, 13)  
(9, 10)  
(11, 11) 
Discuss it
Question 46 
Consider the ALU shown below.
If the operands are in 2's complement representation, which of the following operations can be performed by suitably setting the control lines K and C0 only (+ and  denote addition and subtraction respectively) ?
A + B, and A  B, but not A + 1  
A + B, and A + 1, but not A  B  
A + B, but not A  B, or A + 1  
A + B, and A  B, and A + 1 
Discuss it
Question 46 Explanation:
We can set value of k and c as 0 or 1
Two things we need to know
 If we take xor of any number with 1 we get it in its complement form.
 If we take xor of any number with 0 we get that number itself.
Question 47 
Consider the following circuit composed of XOR gates and noninverting buffers.
The noninverting buffers have delays d1 = 2 ns and d2 = 4 ns as shown in the figure. Both XOR gates and all wires have zero delay. Assume that all gate inputs, outputs and wires are stable at logic level 0 at time 0. If the following waveform is applied at input A, how many transition(s) (change of logic levels) occur(s) at B during the interval from 0 to 10 ns ?
1  
2  
3  
4 
Discuss it
Question 48 
Consider the following assembly language program for a hypothetical processor. A, B, and C are 8 bit registers. The meanings of various instructions are shown as comments.
MOV B, # 0  ;  B ← 0  
MOV C, # 8  ;  C ← 8  
Z :  CMP C, # 0  ;  compare C with 0 
JZX  ;  jump to X if zero flag is set  
SUB C, # 1  ;  C ← C  1  
RRC A, # 1  ;  right rotate A through carry by one bit. Thus:  
;  if the initial values of A and the carry flag are a_{7}...a_{0} and  
;  c_{0} respectively, their values after the execution of this  
;  instruction will be c_{0}a_{7}...a_{1} and a_{0} respectively.  
JC Y  ;  jump to Y if carry flag is set  
JMP Z  ;  jump to Z  
Y :  ADD B, # 1  ;  B ← B + 1 
JMP Z  ;  jump to Z  
X : 
the number of 0 bits in A0  
the number of 1 bits in A0  
A0  
8 
Discuss it
Question 48 Explanation:
Answer: (B)
Explanation:
Explanation: Here value of B incremented by 1 only if carry flag is 1 and carry is filled always using right rotation. So B will store the no. of 1s in A0. RRC instruction is( Each binary bit of the accumulator is rotated right by one position. Bit D0 is placed in the position of D7 as well as in the Carry flag. CY is modified according to bit D0. Any other bit is not affected). So A=A0, and after execution RRC A,#1, carry flag is set,it goes to Y,which is B=B+1,Which becomes B=0+1=1 So (B) is correct option
Question 49 
Consider the following assembly language program for a hypothetical processor. A, B, and C are 8 bit registers. The meanings of various instructions are shown as comments.
Which of the following instructions when inserted at location X will ensure that the value of register A after program execution is the same as its initial value ?
MOV B, # 0  ;  B ← 0  
MOV C, # 8  ;  C ← 8  
Z :  CMP C, # 0  ;  compare C with 0 
JZX  ;  jump to X if zero flag is set  
SUB C, # 1  ;  C ← C  1  
RRC A, # 1  ;  right rotate A through carry by one bit. Thus:  
;  if the initial values of A and the carry flag are a_{7}...a_{0} and  
;  c_{0} respectively, their values after the execution of this  
;  instruction will be c_{0}a_{7}...a_{1} and a_{0} respectively.  
JC Y  ;  jump to Y if carry flag is set  
JMP Z  ;  jump to Z  
Y :  ADD B, # 1  ;  B ← B + 1 
JMP Z  ;  jump to Z  
X : 
RRC A, #  
NOP ; no operation  
LRC A, # 1 ; left rotate A through carry flag by one bit  
ADD A, # 1 
Discuss it
Question 49 Explanation:
Explanation
In the end of program execution to check whether both initial and final value of register A is A0,we need to right rotate register A through carry by one bit because RRC instruction is( Each binary bit of the accumulator is rotated right by one position. Bit D0 is placed in the position of D7 as well as in the Carry flag. CY is modified according to bit D0. Any other bit is not affected).
So (A) is correct option
Question 50 
Consider the following deterministic finite state automaton M.
Let S denote the set of seven bit binary strings in which the first, the fourth, and the last bits are 1. The number of strings in S that are accepted by M is
1  
5  
7  
8 
Discuss it
Question 50 Explanation:
Given a language of 7 bit strings where 1st, 4th and 7th bits are 1.
The following are 7 strings of language that can be accepted by DFA.
1001001
1001011
1001101
1001111
1101001
1111001
1011001
Question 51 
Let G = ({S}, {a, b} R, S) be a context free grammar where the rule set R is
S → a S b  SS  ε
Which of the following statements is true?
G is not ambiguous  
There exist x, y, ∈ L (G) such that xy ∉ L(G)  
There is a deterministic pushdown automaton that accepts L(G)  
We can find a deterministic finite state automaton that accepts L(G) 
Discuss it
Question 51 Explanation:
An ambiguous grammar can be converted to unambiguous one. Here we can get grammar in partial GNF form as S > ab  abS  aSb  aSbS We can convert this into GNF too but no need for PDA reasoning so, above grammar is not a ambiguous thus a definite PDA possible Trick for this is but just deriving 34 strings from grammar, we can easily understand its (a^{n}b^{n})* above expression a^{n}b^{n} is in CFL thus closure of DCFG is a DCFG i.e., you can get L = {ε, ab, abab, aabb, aabbab, abaabb, ababab,......} PDA will push "a" until "b" is read, start popping "a" for the "b" read. If "a" is read again from the tape then push only when stack is empty else terminate. Repeat this until string is read. Remember fastest way to get answer is by elimination other options.
Question 52 
Consider two languages L1 and L2 each on the alphabet ∑. Let f : ∑ → ∑ be a polynomial time computable bijection such that (∀ x) [x ∈ L1 iff f(x) ∈ L2].
Further, let f^{1} be also polynomial time computable.
Which of the following CANNOT be true?
L1 ∈ P and L2 is finite  
L1 ∈ NP and L2 ∈ P  
L1 is undecidable and L2 is decidable  
L1 is recursively enumerable and L2 is recursive 
Discuss it
Question 52 Explanation:
We have one to one mapping for all instances of L1 to L2.
L1 is given to be undecidable. Further L1 is polynomial time reducible to L2. (By given mapping). Now if L2 is decidable then there is algorithm to solve L2 in polytime. But then we can solve every instance of L1 in polytime, making L1 also decidable. Contradiction
Question 53 
A single tape Turing Machine M has two states q0 and q1, of which q0 is the starting state. The tape alphabet of M is {0, 1, B} and its input alphabet is {0, 1}. The symbol B is the blank symbol used to indicate end of an input string. The transition function of M is described in the following table
The table is interpreted as illustrated below.
The entry (q1, 1, R) in row q0 and column 1 signifies that if M is in state q0 and reads 1 on the current tape square, then it writes 1 on the same tape square, moves its tape head one position to the right and transitions to state q1.
Which of the following statements is true about M ?
0  1  B  
q0  q1, 1, R  q1, 1, R  Halt 
q1  q1, 1, R  q0, 1, L  q0, B, L 
M does not halt on any string in (0 + 1)+  
M does not halt on any string in (00 + 1)*  
M halts on all string ending in a 0  
M halts on all string ending in a 1 
Discuss it
Question 53 Explanation:
Whenever B is given as a input, turing machine halts. This implies epsilon is only accepted when B occurs as an input.
In positive closure, epsilon is not present. So, Turing machine never halts in case of (0+1)^{+}.
Thus, option (A) is correct.
Please comment below if you find anything wrong in the above post.
Question 54 
Define languages L0 and L1 as follows :
L0 = {< M, w, 0 >  M halts on w} L1 = {< M, w, 1 >  M does not halts on w}Here < M, w, i > is a triplet, whose first component. M is an encoding of a Turing Machine, second component, w, is a string, and third component, i, is a bit. Let L = L0 ∪ L1. Which of the following is true ?
L is recursively enumerable, but L' is not  
L' is recursively enumerable, but L is not  
Both L and L' are recursive  
Neither L nor L' is recursively enumerable 
Discuss it
Question 55 
Consider the NFA M shown below.
Let the language accepted by M be L. Let L1 be the language accepted by the NFA M1, obtained by changing the accepting state of M to a nonaccepting state and by changing the nonaccepting state of M to accepting states. Which of the following statements is true ?
L1 = {0, 1}*  L  
L1 = {0, 1}*  
L1 ⊆ L  
L1 = L 
Discuss it
Question 55 Explanation:
In case of a Deterministic Finite Automata (DFA) when we change the accepting states into nonaccepting states and nonaccepting states into accepting states, the new DFA obtained accepts the complement of the language accepted by the initial DFA. It is because we have one single movement for a particular input alphabet from one state so the strings accepted by the transformed DFA will be all those which are not accepted by the actual DFA.
But it is not the case with the NFA’s (NonDeterministic Finite Automata). In case of NFA we need to have a check on the language accepted by the NFA. The NFA obtained by changing the accepting states to nonaccepting states and nonaccepting states to accepting states is as follows:
Here we can see that as i. The initial state is an accepting state hence null string is always accepted by the NFA. ii. There is a movement from state 1 to state 2 on both {0, 1} input alphabets and further any number of 1’s and 0’s or even none in the string lets the string be at an accepting state(state 2). Hence the language accepted by the NFA can be any string with any combination of 0’s and 1’s including a null string i.e. {null, 0, 1, 00, 01, 10, 11,……………..} so L1= {0, 1}*.This Explanation has been contributed by Yashika Arora.
Question 56 
Consider the grammar shown below
S → i E t S S'  a
S' → e S  ε
E → b
In the predictive parse table. M, of this grammar, the entries M[S', e] and M[S', $] respectively are
{S' → e S} and {S' → e}  
{S' → e S} and {}  
{S' → ε} and {S' → ε}  
{S' → e S, S'→ ε} and {S' → ε} 
Discuss it
Question 56 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 NonTerminal S', hence we only need to consider its productions to get the answer.
For S' → eS, according to rule 1, this production rule should be placed at the entry M[ S', FIRST(eS) ], and from the given grammar, FIRST(eS) ={e}, hence S'>eS is placed in the parsing table at entry M[S' , e].
Similarly,
For S'>ε, as FIRST(ε) = {ε}, hence rule 2 should be applied, therefore, this production rule should be placed in the parsing table at entry M[S',FOLLOW(S')], and FOLLOW(S') = FOLLOW(S) = { e, $ }, hence R>ε is placed at entry M[ S', e ] and M[ S' , $ ].
Therefore Answer is option D.
Visit the Following links to Learn how to find First and Follow sets.
http://geeksquiz.com/compilerdesignfirstinsyntaxanalysis/
http://geeksquiz.com/compilerdesignfollowsetinsyntaxanalysis/
Question 57 
Consider the grammar shown below.
S → C C C → c C  dThe grammar is
LL(1)  
SLR(1) but not LL(1)  
LALR(1) but not SLR(1)  
LR(1) but not LALR(1) 
Discuss it
Question 57 Explanation:
Since there is no conflict, the grammar is LL(1). We can construct a predictive parse table with no conflicts. This grammar also LR(0), SLR(1), CLR(1) and LALR(1).
Question 58 
Consider the translation scheme shown below
S → T R R → + T {print ('+');} R  ε T → num {print (num.val);}Here num is a token that represents an integer and num.val represents the corresponding integer value. For an input string '9 + 5 + 2', this translation scheme will print
9 + 5 + 2  
9 5 + 2 +  
9 5 2 + +  
+ + 9 5 2 
Discuss it
Question 58 Explanation:
Let us make the parse tree for 9+5+2 in top down manner, left first derivation.
Steps: 1) Exapnd S>TR 2) apply T>Num... 3) apply R > +T... 4) appy T>Num... 5) apply R> +T.. 6) apply T> Num.. 7) apply R> epsilonAfter printing through the print statement in the parse tree formed you will get the answer as 95+2+
Question 59 
Consider the syntax directed definition shown below.
S → id : = E {gen (id.place = E.place;);} E → E1 + E2 {t = newtemp ( ); gen (t = El.place + E2.place;); E.place = t} E → id {E.place = id.place;}Here, gen is a function that generates the output code, and newtemp is a function that returns the name of a new temporary variable on every call. Assume that ti's are the temporary variable names generated by newtemp. For the statement 'X: = Y + Z', the 3address code sequence generated by this definition is
X = Y + Z  
t1 = Y + Z; X = t1  
t1 =Y; t2 = t1 + Z; X = t2  
t1 = Y; t2 = Z; t3 = t1 + t2; X = t3 
Discuss it
Question 59 Explanation:
It must be B. The production E > E + E is used only one time and hence only one temporary variable is generated.
Question 60 
A program consists of two modules executed sequentially. Let f1(t) and f2(t) respectively denote the probability density functions of time taken to execute the two modules. The probability density function of the overall time taken to execute the program is given by :
A) f1(t) + f2(t) B) C) D) max {f1(t), f2(t)}
A  
B  
C  
D 
Discuss it
Question 60 Explanation:
We assume the total time to be ‘t’ units and f1 executes for 'x’ units.
Since, f1(t) and f2(t) are executed sequentially. So, f2 is executed for ‘t – x’ units.
We apply convolution on the sum of two independent random variables to get probability density function of the overall time taken to execute the program.
f1(t) * f2(t – x) =
Thus, option (C) is correct.
Please comment below if you find anything wrong in the above post.
Question 61 
In a permutation a1.....an of n distinct integers, an inversion is a pair (ai, aj) such that i < j and ai > aj. If all permutations are equally likely, what is the expected number of inversions in a randomly chosen permutation of 1.....n ?
n(n  1)/2
 
n(n  1)/4  
n(n + 1)/4  
2n[log2 n] 
Discuss it
Question 61 Explanation:
There are n(n1)/2 pairs such that i < j. For a pair (ai, aj), probability of being inversion is 1/2. Therefore expected value of inversions = 1/2 * (n(n1)/2) = n(n1)/4
Question 62 
In a permutation a1.....an of n distinct integers, an inversion is a pair (ai, aj) such that i < j and ai > aj. What would be the worst case time complexity of the Insertion Sort algorithm, if the inputs are restricted to permutations of 1.....n with at most n inversions?
Θ (n^{2})  
Θ (n log n)  
Θ (n^{1.5})  
Θ (n) 
Discuss it
Question 62 Explanation:
Insertion sort runs in Θ(n + f(n)) time, where f(n) denotes the number of inversion initially present in the array being sorted.
Source: http://cs.xidian.edu.cn/jpkc/Algorithm/down/Solution%20to%2024%20Inversions.pdf
Question 63 
A data structure is required for storing a set of integers such that each of the following operations can be done in (log n) time, where n is the number of elements in the set.
o Delection of the smallest element o Insertion of an element if it is not already present in the setWhich of the following data structures can be used for this purpose?
A heap can be used but not a balanced binary search tree  
A balanced binary search tree can be used but not a heap  
Both balanced binary search tree and heap can be used  
Neither balanced binary search tree nor heap can be used 
Discuss it
Question 63 Explanation:
First we’ll discuss about heap and balanced bst and its time complexities for basic operations like
insertion, deletion, find.
Heap:
Let us consider it as min heap
1) Insertion: O(logn)
2) Delete Min: O(logn) (Just replace root with INT_MAX and heapify)
3) Find: O(n)
Balanced BST:
1) Insertion: O(logn)
2) Delete Min: O(logn)
3) Find: O(logn)
Statement 1:
1) Deletion of smallest element can be done in O(logn) in both data structures
Statement 2:
1) Insertion of an element if it is not already present in the set
In heap, we can perform this operation in O(n) because we have to perform linear search here, where as in BST we can perform this in O(logn)
See Question 4 of http://www.geeksforgeeks.org/datastructuresandalgorithmsset3/
This solution is contributed by Anil Saikrishna Devarasetty
Question 64 
Let S be a stack of size n ≥ 1. Starting with the empty stack, suppose we push the first n natural numbers in sequence, and then perform n pop operations. Assume that Push and pop operation take X seconds each, and Y seconds elapse between the end of one such stack operation and the start of the next operation. For m ≥ 1, define the stacklife of m as the time elapsed from the end of Push(m) to the start of the pop operation that removes m from S. The average stacklife of an element of this stack is
n (X + Y)  
3Y + 2X  
n (X + Y)  X  
Y + 2X 
Discuss it
Question 64 Explanation:
Background required  Stack and Basic Maths
Let Tn be time span of nth element of stack. Let us first find out the sum of Tn for n = 1 to n
Stack Lifetime of last element, Tn = Y (Since it is popped as soon as it is pushed on the stack) Stack Lifetime of last element, Tn1 = Tn + 2X + 2Y (The time needed to push and then pop nth element plus two pauses Y each). = 2X + 3Y Stack Lifetime of last element, Tn2 = Tn1 + 2X + 2Y (Using the Same reasoning above) = 4X + 5Y . . . Stack Lifetime of 1st element = 2(n1)X + (2n1)Y (Generalizing the pattern) Sum of all the time spans of all the elements = (Σ 2(n1)X) + (Σ (2n1)Y) for n = 1 to n = 2X(1 + 2 + . . . + n1) + Y(1 + 3 + 5 + . . . + (2n1))Using 2 identities
 Sum of n natural numbers = (n*(n+1))/2 for the first summation
 Sn = (n/2)(a+l) Sum of AP series with a as first term and l being last for second summation
Question 65 
Consider the following 234 tree (i.e., Btree with a minimum degree of two) in which each data item is a letter. The usual alphabetical ordering of letters is used in constructing the tree.
What is the result of inserting G in the above tree ?
A) B) C) D) None of the above
A  
B  
C  
D 
Discuss it
Question 65 Explanation:
Since the given B tree is 234 tree, there can be atmost 4 children or 3 keys.
In B Tree insertion, we start from root and traverse till the leaf node where key is to be inserted. While traversing, if we find a a node which full, we split it. When we insert G, we find root itself is full, so we split it. When we come down to leftmost leaf, we find that the leaf is also full, so we split the leaf also.
Question 66 
The cube root of a natural number n is defined as the largest natural number m such that m^{3} ≤ n. The complexity of computing the cube root of n (n is represented in binary notation) is:
O(n) but not O(n^{0.5})  
O(n^{0.5}) but not O((log n)^{k}) for any constant k > 0  
O((log n)^{k}) for some constant k > 0, but not O ((log log n)^{m}) for any constant m > 0  
O((log log n)^{m}) for some constant k > 0.5, but not O((log log n)^{0.5}) 
Discuss it
Question 66 Explanation:
Question 67 
Let G = (V, E) be an undirected graph with a subgraph G1 = (V1, El). Weights are assigned to edges of G as follows :
A singlesource shortest path algorithm is executed on the weighted graph (V, E, w) with an arbitrary vertex ν1 of V1 as the source. Which of the following can always be inferred from the path costs computed?
The number of edges in the shortest paths from ν1 to all vertices of G  
G1 is connected  
V1 forms a clique in G  
G1 is a tree 
Discuss it
Question 67 Explanation:
When shortest path shortest path from v1 (one of the vertices in V1) is computed. G1 is connected if the distance from v1 to any other vertex in V1 is greater than 0, otherwise G1 is disconnected.
Question 68 
29  
31  
38  
41 
Discuss it
Question 68 Explanation:
(a,c), (a,d), (d,b), (b,g), (g,h), (h,f), (h,i), (i,j), (i,e) = 31
Background required  Minimum Spanning Tree (Prims / Kruskal)
In these type of questions, always go for kruskal’s algorithm to find out the the minimum spanning tree as it is easy and there are less chances of doing silly mistakes.
Algorithm:
Always pick the minimum edge weight and try to add to current forest (Collection of Trees) if no cycle is formed else discard.
As soon as u have added n1 edges to the forest, stop and you have got your minimum spanning tree.
See the below image for construction of MST of this question.
Weight of minimum spanning tree = Sum of all the edges in Minimum Spanning tree
= 31
This explanation has been provided by Pranjul Ahuja.
Visit the following links to learn more:
http://www.ics.uci.edu/~eppstein/161/960206.html
https://en.wikipedia.org/wiki/Minimum_spanning_tree
Question 69 
The following are the starting and ending times of activities A, B, C, D, E, F, G and H respectively in chronological order: "a_{s}b_{s}c_{s}a_{e}d_{s}c_{e}e_{s}f_{s}b_{e}d_{e}g_{s}e_{e}f_{e}h_{s}g_{e}h_{e}"
Here, x_{s} denotes the starting time and x_{e} denotes the ending time of activity X. W need to schedule the activities in a set of rooms available to us. An activity can be scheduled in a room only if the room is reserved for the activity for its entire duration. What is the minimum number of rooms required ?
3  
4  
5  
6 
Discuss it
Question 69 Explanation:
Room1  As
Room2  Bs
Room3  As
now A ends (Ae) and now Room3 is free
Room3Ds
now A ends (Ae) and Room1 is free
Room1Es
Room4Fs
now B ends Room2 is free
now D ends Room3 is free
Room2Gs
now E ends Room1 free
now F ends Room4 free
Room1Hs
now G and H ends.
Totally used 4 rooms
Source: https://www.gatementor.com/viewtopic.php?f=267&t=2195
Question 70 
Let G (V, E) be a directed graph with n vertices. A path from v_{i} to v_{j} in G is sequence of vertices (v_{i}, v_{i+1}, ......., v_{j}) such that (vk, v_{k+1}) ∈ E for all k in i through j  1. A simple path is a path in which no vertex appears more than once.
Let A be an n x n array initialized as follow
Consider the following algorithm.
for i = 1 to n for j = 1 to n for k = 1 to n A [j , k] = max (A[j, k] (A[j, i] + A [i, k]);Which of the following statements is necessarily true for all j and k after terminal of the above algorithm ?
A[j, k] ≤ n  
If A[j, k] ≥ n  1, then G has a Hamiltonian cycle  
If there exists a path from j to k, A[j, k] contains the longest path lens from j to k  
If there exists a path from j to k, every simple path from j to k contain most A[j, k] edges 
Discuss it
Question 70 Explanation:
In the original input matrix, A[j , k] is 1 if there is an edge from j to k, else 0. Below expression is important to note: A[j , k] = max(A[j, k] (A[j, i] + A [i, k]); This expression puts the count of maximum edges on a path from j to k. In this expression, we consider every vertex k that can become an intermediate vertex and can give longer path.
Question 71 
Consider the following logic program P
A(x) < B(x, y), C(y)
< B(x,x)
Which of the following first order sentences is equivalent to P?
A  
B  
C  
D 
Discuss it
Question 72 
The following resolution rule is used in logic programming:
Derive clause (P v Q) from clauses (P v R), (Q v ¬ R)Which of the following statements related to this rule is FALSE?
((P v R) ^ (Q v ¬ R)) (P v Q) is logically valid  
(P v Q) ⇒ ((P v R) ^ (Q v ¬ R)) is logically valid  
(P v Q) is satisfiable if and only if (P v R) ^ (Q v ¬ R) is satisfiable  
(P v Q) ⇒ FALSE if and only if both P and Q are unsatisfiable 
Discuss it
Question 73 
The following program fragment is written in a programming language that allows variables and does not allow nested declarations of functions.
global int i = 100, j = 5; void P(x) { int i = 10; print(x + 10); i = 200; j = 20; print(x); } main() { P(i + j); }If the programming language uses static scoping and call by need parameter passing mechanism, the values printed by the above program are
115, 220  
25, 220  
25, 15  
115, 105 
Discuss it
Question 73 Explanation:
Background :
Callbyneed is a declarative and functional language paradigm. As opposed to callbyvalue, it only evaluates the argument given to a function when it is need, and caches it for further use. Callbyname is a bit different from callbyneed in the sense that it evaluates in the lazy fashion only but doesn’t cache the calculated value. Hence, callbyneed requires to evaluate once if the argument is being used, callbyvalue needs to evaluate it no matter if the argument is used or not, and callbyname evaluates the same argument multiple times as and when it is used.
Explanation :
Value of variable x doesn’t change anytime in the function P(x). Hence, whatever its value is when this function is called, only that will be used in all the print statements. Clearly, 100+5+10, 100+5 i.e. 115, 105 will be printed by the program.
This solution is contributed by vineet purswani
Another Solution: Here in main function P(i+j) function is called with arguments values i =100 and j = 5(since static scoping).Now when P(100+5) is called, here in P function, j is a free variable and i is a local variable.Now take a look at the steps in P function : step_1: Local variable i is intialized to value 0. step_2: Here value of x+10 is printed and since it’s call by need,so value of x is calculated to 105 and it’s stored in cache for further use.Also 115 is printed here. step_3: Now, i is assigned value 200. step_4: Here, j is a free variable, So it’s scope is searched in immediate outer block until we find variable j’s declaration.Global variable j’s value is changed from 5 to 20. step_5: x value is printed as 105.Since it’s uses the cache stored value of x. The output would be similar to C programming language as C does static scoping only. This solution is contributed by Nirmal Bharadwaj
Another Solution: Here in main function P(i+j) function is called with arguments values i =100 and j = 5(since static scoping).Now when P(100+5) is called, here in P function, j is a free variable and i is a local variable.Now take a look at the steps in P function : step_1: Local variable i is intialized to value 0. step_2: Here value of x+10 is printed and since it’s call by need,so value of x is calculated to 105 and it’s stored in cache for further use.Also 115 is printed here. step_3: Now, i is assigned value 200. step_4: Here, j is a free variable, So it’s scope is searched in immediate outer block until we find variable j’s declaration.Global variable j’s value is changed from 5 to 20. step_5: x value is printed as 105.Since it’s uses the cache stored value of x. The output would be similar to C programming language as C does static scoping only. This solution is contributed by Nirmal Bharadwaj
Question 74 
The following program fragment is written in a programming language that allows variables and does not allow nested declarations of functions.
global int i = 100, j = 5; void P(x) { int i = 10; print(x + 10); i = 200; j = 20; print(x); } main() { P(i + j); }If the programming language uses dynamic scoping and call by name parameter passing mechanism, the values printed by the above program are :
115, 220  
25, 220  
25, 15  
115, 105 
Discuss it
Question 74 Explanation:
1
Thus, A is the correct option as 115 and 220 are printed.
Please comment below if you find anything wrong in the above post.
Please comment below if you find anything wrong in the above post.
Question 75 
Consider the following class definitions in a hypothetical Object Oriented language that supports inheritance and uses dynamic binding. The language should not be assumed to be either Java or C++, though the syntax is similar.
Class P { void f(int i) { print(i); } } Class Q subclass of P { void f(int i) { print(2*i); } }Now consider the following program fragment:
P x = new Q(); Q y = new Q(); P z = new Q(); x.f(1); ((P)y).f(1); z.f(1);Here ((P)y) denotes a typecast of y to P. The output produced by executing the above program fragment will be
1 2 1  
2 1 1  
2 1 2  
2 2 2 
Discuss it
Question 76 
Which of the following is NOT an advantage of using shared, dynamically linked libraries as opposed to using statically linked libraries ?
Smaller sizes of executable files  
Lesser overall page fault rate in the system  
Faster program startup  
Existing programs need not be relinked to take advantage of newer versions of libraries 
Discuss it
Question 76 Explanation:
Refer Static and Dynamic Libraries
In NonShared (static) libraries, since library code is connected at compile time, the final executable has no dependencies on the the library at run time i.e. no additional runtime loading costs, it means that you don’t need to carry along a copy of the library that is being used and you have everything under your control and there is no dependency.
Question 77 
A uniprocessor computer system only has two processes, both of which alternate 10ms CPU bursts with 90ms I/O bursts. Both the processes were created at nearly the same time. The I/O of both processes can proceed in parallel. Which of the following scheduling strategies will result in the least CPU utilization (over a long period of time) for this system ?
First come first served scheduling  
Shortest remaining time first scheduling  
Static priority scheduling with different priorities for the two processes  
Round robin scheduling with a time quantum of 5 ms 
Discuss it
Question 77 Explanation:
When Round Robin scheduling is used
We are given that the time slice is 5ms. Consider process P and Q.
Say P utilizes 5ms of CPU and then Q utilizes 5ms of CPU. Hence after 15ms P starts with I/O And after 20ms Q also starts with I/O. Since I/O can be done in parallel, P finishes I\O at 105th ms (15 + 90) and Q finishes its I\O at 110th ms (20 + 90). Therefore we can see that CPU remains idle from 20th to 105th ms.
That is when Round Robin scheduling is used,
Idle time of CPU = 85ms
CPU Utilization = 20/105 = 19.05%
When First Come First Served scheduling scheduling or Shortest Remaining Time First is used
Say P utilizes 10ms of CPU and then starts its I/O. At 11th ms Q starts processing. Q utilizes 10ms of CPU.
P completes its I/O at 100ms (10 + 90)
Q completes its I/O at 110ms (20 + 90)
At 101th ms P again utilizes CPU. Hence,
Idle time of CPU = 80ms
CPU Utilization = 20/100 = 20%
Since only two processes are involved and I\O time is much more than CPU time, "Static priority scheduling with different priorities" for the two processes reduces to FCFS or Shortest remaining time first.
Therefore, Round robin will result in least CPU utilization.
Source: http://gateoverflow.in/963/gateoverflow.in
Question 78 
A processor uses 2level page tables for virtual to physical address translation. Page tables for both levels are stored in the main memory. Virtual and physical addresses are both 32 bits wide. The memory is byte addressable. For virtual to physical address translation, the 10 most significant bits of the virtual address are used as index into the first level page table while the next 10 bits are used as index into the second level page table. The 12 least significant bits of the virtual address are used as offset within the page. Assume that the page table entries in both levels of page tables are 4 bytes wide. Further, the processor has a translation lookaside buffer (TLB), with a hit rate of 96%. The TLB caches recently used virtual page numbers and the corresponding physical page numbers. The processor also has a physically addressed cache with a hit rate of 90%. Main memory access time is 10 ns, cache access time is 1 ns, and TLB access time is also 1 ns.
Assuming that no page faults occur, the average time taken to access a virtual address is approximately (to the nearest 0.5 ns)
1.5 ns  
2 ns  
3 ns  
4 ns 
Discuss it
Question 78 Explanation:
The possibilities are TLB Hit*Cache Hit + TLB Hit*Cache Miss + TLB Miss*Cache Hit + TLB Miss*Cache Miss = 0.96*0.9*2 + 0.96*0.1*12 + 0.04*0.9*22 + 0,04*0.1*32 = 3.8 ≈ 4Why 22 and 32? 22 is because when TLB miss occurs it takes 1ns and the for the physical address it has to go through two level page tables which are in main memory and takes 2 memory access and the that page is found in cache taking 1 ns which gives a total of 22
Question 79 
A processor uses 2level page tables for virtual to physical address translation. Page tables for both levels are stored in the main memory. Virtual and physical addresses are both 32 bits wide. The memory is byte addressable. For virtual to physical address translation, the 10 most significant bits of the virtual address are used as index into the first level page table while the next 10 bits are used as index into the second level page table. The 12 least significant bits of the virtual address are used as offset within the page. Assume that the page table entries in both levels of page tables are 4 bytes wide. Further, the processor has a translation lookaside buffer (TLB), with a hit rate of 96%. The TLB caches recently used virtual page numbers and the corresponding physical page numbers. The processor also has a physically addressed cache with a hit rate of 90%. Main memory access time is 10 ns, cache access time is 1 ns, and TLB access time is also 1 ns.
Suppose a process has only the following pages in its virtual address space: two contiguous code pages starting at virtual address 0x00000000, two contiguous data pages starting at virtual address 0×00400000, and a stack page starting at virtual address 0×FFFFF000. The amount of memory required for storing the page tables of this process is:
8 KB  
12 KB  
16 KB  
20 KB 
Discuss it
Question 79 Explanation:
Breakup of given addresses into bit form: 32bits are broken up as 10bits (L2)  10bits (L1)  12bits (offset) first code page: 0x00000000 = 0000 0000 00  00 0000 0000  0000 0000 0000 so next code page will start from 0x00001000 = 0000 0000 00  00 0000 0001  0000 0000 0000 first data page: 0x00400000 = 0000 0000 01  00 0000 0000  0000 0000 0000 so next data page will start from 0x00401000 = 0000 0000 01  00 0000 0001  0000 0000 0000 only one stack page: 0xFFFFF000 = 1111 1111 11  11 1111 1111  0000 0000 0000 Now, for second level page table, we will just require 1 Page which will contain following 3 distinct entries i.e. 0000 0000 00, 0000 0000 01, 1111 1111 11. Now, for each of these distinct entries, we will have 11 page in Level1. Hence, we will have in total 4 pages and page size = 2^12 = 4KB. Therefore, Memory required to store page table = 4*4KB = 16KB.
Question 80 
Suppose we want to synchronize two concurrent processes P and Q using binary semaphores S and T. The code for the processes P and Q is shown below.
Process P: while (1) { W: print '0'; print '0'; X: } Process Q: while (1) { Y: print '1'; print '1'; Z: }Synchronization statements can be inserted only at points W, X, Y and Z. Which of the following will always lead to an output staring with '001100110011' ?
P(S) at W, V(S) at X, P(T) at Y, V(T) at Z, S and T initially 1  
P(S) at W, V(T) at X, P(T) at Y, V(S) at Z, S initially 1, and T initially 0  
P(S) at W, V(T) at X, P(T) at Y, V(S) at Z, S and T initially 1  
P(S) at W, V(S) at X, P(T) at Y, V(T) at Z, S initially 1, and T initially 0 
Discuss it
Question 80 Explanation:
P(S) means wait on semaphore ‘S’ and V(S) means signal on semaphore ‘S’.
1
Wait(S)
{
while (i <= 0)
S;
}
Signal(S)
{
S++;
}
[/sourcecode]
Initially, we assume S = 1 and T = 0 to support mutual exclusion in process P and Q.
Since S = 1, only process P will be executed and wait(S) will decrement the value of S. Therefore, S = 0.
At the same instant, in process Q, value of T = 0. Therefore, in process Q, control will be stuck in while loop till the time process P prints 00 and increments the value of T by calling the function V(T).
While the control is in process Q, semaphore S = 0 and process P would be stuck in while loop and would not execute till the time process Q prints 11 and makes the value of S = 1 by calling the function V(S).
This whole process will repeat to give the output 00 11 00 11 … .
Thus, B is the correct choice.
Please comment below if you find anything wrong in the above post.
Thus, B is the correct choice.
Please comment below if you find anything wrong in the above post.
Question 81 
Suppose we want to synchronize two concurrent processes P and Q using binary semaphores S and T. The code for the processes P and Q is shown below.
Process P: while (1) { W: print '0'; print '0'; X: } Process Q: while (1) { Y: print '1'; print '1'; Z: }Synchronization statements can be inserted only at points W, X, Y and Z Which of the following will ensure that the output string never contains a substring of the form 01n0 or 10n1 where n is odd?
P(S) at W, V(S) at X, P(T) at Y, V(T) at Z, S and T initially 1  
P(S) at W, V(T) at X, P(T) at Y, V(S) at Z, S and T initially 1  
P(S) at W, V(S) at X, P(S) at Y, V(S) at Z, S initially 1  
V(S) at W, V(T) at X, P(S) at Y, P(T) at Z, S and T initially 1 
Discuss it
Question 81 Explanation:
P(S) means wait on semaphore ’S’ and V(S) means signal on semaphore ‘S’. The definition of these functions are :
Initially S = 1 and T = 0 to support mutual exclusion in process ‘P’ and ‘Q’.
Since, S = 1 , process ‘P’ will be executed and function Wait(S) will decrement the value of ‘S’. So, S = 0 now.
Simultaneously, in process ‘Q’ , T = 0 . Therefore, in process ‘Q’ control will be stuck in while loop till the time process ‘P’ prints ‘00’ and increments the value of ‘T’ by calling function V(T).
While the control is in process ‘Q’, S = 0 and process ‘P’ will be stuck in while loop. Process ‘P’ will not execute till the time process ‘Q’ prints ‘11’ and makes S = 1 by calling function V(S).
Thus, process 'P' and 'Q' will keep on repeating to give the output ‘00110011 …… ‘ .
Please comment below if you find anything wrong in the above post.
Wait(S) { while (i <= 0) ; S ; }
Signal(S) { S++ ; }
Initially S = 1 and T = 0 to support mutual exclusion in process ‘P’ and ‘Q’.
Since, S = 1 , process ‘P’ will be executed and function Wait(S) will decrement the value of ‘S’. So, S = 0 now.
Simultaneously, in process ‘Q’ , T = 0 . Therefore, in process ‘Q’ control will be stuck in while loop till the time process ‘P’ prints ‘00’ and increments the value of ‘T’ by calling function V(T).
While the control is in process ‘Q’, S = 0 and process ‘P’ will be stuck in while loop. Process ‘P’ will not execute till the time process ‘Q’ prints ‘11’ and makes S = 1 by calling function V(S).
Thus, process 'P' and 'Q' will keep on repeating to give the output ‘00110011 …… ‘ .
Please comment below if you find anything wrong in the above post.
Question 82 
The subnet mask for a particular network is 255.255.31.0. Which of the following pairs of IP addresses could belong to this network?
172.57.88.62 and 172.56.87.233  
10.35.28.2 and 10.35.29.4  
191.203.31.87 and 191.234.31.88  
128.8.129.43 and 128.8.161.55 
Discuss it
Question 82 Explanation:
Background required  Subnetting and SubNet Mask
Answer  D
Explanation  Suppose we have a host A with IP Address IP_{A} and Subnet mask of the subnet of which A is a part is M_{s}. Now when A wants to send packet to a host B with an IP address say IP_{B}, then A will first AND the subnetMask M_{s} with IP_{A} to find out the subnetid ID_{N} of the subnet in order to identify whether IP_{B} belongs to the same network. Now if B also belongs to the same network, then IP_{B} BITWISEAND M_{s} must be equal to ID_{N} which A has calculated.
If IP_{A} and IP_{B} belongs to same network, we must have
IP_{A} BITWISEAND M_{s} == IP_{B}BITWISEAND M_{s}Out of the 4 options, only option D matches.
128.8.129.43 BITWISEAND 255.255.31.0 = 128.8.1.0 128.8.161.55 BITWISEAND 255.255.31.0 = 128.8.1.0You can check rest of the options. This explanation has been provided by Pranjul Ahuja.
Question 83 
A 2 km long broadcast LAN has 10^{7} bps bandwidth and uses CSMA/CD. The signal travels along the wire at 2 × 10^{8} m/s. What is the minimum packet size that can be used on this network?
50 bytes  
100 bytes  
200 bytes  
None of these 
Discuss it
Question 83 Explanation:
In CSMA/CD, the transmitting node is listening for collisions while it transmits it's frame. Once it has finished transmitting the final bit without hearing a collision, it assumes that the transmission was successful. In this worstcase collision scenario, the time that it takes for a Node to detect that its frame has been collided with is twice the propagation delay. Hence to confirm that the collision has not occurred the condition for the minimum size of the packet is:
RTT = Transmission Time Transmission Time = Length of packet / Bandwidth RTT = 2 (d/v) = 2(2000/2×108) Therefore to find minimum size of the packet, RTT = Length of packet / Bandwidth Length of packet = RTT x Bandwith = 2(2000/2×108) x 107 = 200bits = 25bytes Therefore, minimum size of the packet = 25bytesSource: http://www.btechonline.org/2012/12/gatecomputernetworksethernet.html
Question 84 
Host A is sending data to host B over a full duplex link. A and B are using the sliding window protocol for flow control. The send and receive window sizes are 5 packets each. Data packets (sent only from A to B) are all 1000 bytes long and the transmission time for such a packet is 50 µs. Acknowledgement packets (sent only from B to A) are very small and require negligible transmission time. The propagation delay over the link is 200 us. What is the maximum achievable throughput in this communication?
7.69 × 10^{6} bytes per second  
11.11 × 10^{6} bytes per second  
12.33 × 10^{6} bytes per second  
15.00 × 10^{6} bytes per second 
Discuss it
Question 84 Explanation:
Network throughput ≈ Window size / roundtrip time Roundtrip time = 2 × Packet delivery time + processing delay = ransmission delay+2*propagation delay =50microsec+2*200microsec=450microsec Now Throughput = ((5*1000*bytes)/450microsec) = 11.1111 * 10^{6} bytes per second
Question 85 
Consider the following functional dependencies in a database:
Data_of_Birth → Age Age → Eligibility Name → Roll_number Roll_number → Name Course_number → Course_name Course_number → Instructor (Roll_number, Course_number) → GradeThe relation (Roll_number, Name, Date_of_birth, Age) is:
In second normal form but not in third normal form  
In third normal form but not in BCNF  
In BCNF  
None of the above 
Discuss it
Question 85 Explanation:
The given table is not in 2NF as age is dependent on date of birth.
Question 86 
Consider the set of relations shown below and the SQL query that follows.
Students: (Roll_number, Name, Date_of_birth) Courses: (Course number, Course_name, Instructor) Grades: (Roll_number, Course_number, Grade)
select distinct Name from Students, Courses, Grades where Students. Roll_number = Grades.Roll_number and Courses.Instructor = Korth and Courses.Course_number = Grades.Course_number and Grades.grade = AWhich of the following sets is computed by the above query?
Names of students who have got an A grade in all courses taught by Korth  
Names of students who have got an A grade in all courses  
Names of students who have got an A grade in at least one of the courses taught by Korth  
None of the above 
Discuss it
Question 86 Explanation:
The query gives the name of all the students who have scored "A" grade in any of the courses that are taught by Korth.
So, C is the correct choice.
Please comment below if you find anything wrong in the above post.
Please comment below if you find anything wrong in the above post.
Question 87 
Consider three data items D1, D2 and D3 and the following execution schedule of transactions T1, T2 and T3. In the diagram, R(D) and W(D) denote the actions reading and writing the data item D respectively.
Which of the following statements is correct?
The schedule is serializable as T2; T3; T1  
The schedule is serializable as T2; T1; T3  
The schedule is serializable as T3; T2; T1  
The schedule is not serializable 
Discuss it
Question 87 Explanation:
T1 and T2 have conflicting operations between them forming a cycle in the precedence graph.
R(D2) of T2, and W(D2) of T1 ( ReadWrite Conflict)
R(D1) of T1, and W(D1) of T2 ( ReadWrite Conflict)
Hence in the precedence graph of the schedule there would be a cycle between T1 and T2 vertices. Therefore not a serializable schedule.
Question 88 
In the following C program fragment, j, k n and TwoLog_n are interger variables, and A is an array of integers. The variable n is initialized to an integer ≥ 3, and TwoLog_n is initialized to the value of 2*⌈log2(n)⌉
for (k = 3; k < = n; k++) A[k] = 0; for (k = 2; k < = TwoLog_n; k++) for (j = k + 1; j < = n; j++) A[j] = A[j]  (j % k); for (j = 3; j < = n; j++) if (!A[j]) printf("%d", j);The set of numbers printed by this program fragment is
{m  m ≤ n, (∃ i) [m = i!]} Here i! mean factorial of i  
{m  m ≤ n, (∃ i) [m = i^{2}]}  
{m  m ≤ n, m is prime}  
{} 
Discuss it
Question 88 Explanation:
1
// Initialize all values as 0
for (k = 3; k < = n; k++)
A[k] = 0;
for (k = 2; k < = TwoLog_n; k++)
for (j = k + 1; j < = n; j++)
// If k divides j, then A[j] is
// set as 0, else nonzero
A[j] = A[j]  (j % k);
// Print all numbers where A[j] is 0
for (j = 3; j < = n; j++)
if (!A[j])
printf("%d", j);
[/sourcecode]
Question 89 
Consider the C program shown below.
#include <stdio.h> #define print(x) printf("%d ", x) int x; void Q(int z) { z += x; print(z); } void P(int *y) { int x = *y + 2; Q(x); *y = x  1; print(x); } main(void) { x = 5; P(&x); print(x); }
The output of this program is
12 7 6  
22 12 11  
14 6 6  
7 6 6 
Discuss it
Question 89 Explanation:
x is global so first x becomes 5 by the first line in main(). Then main() calls P() with address of x.
// in main(void) x = 5 // Change global x to 5 P(&x)P() has a local variable named 'x' that hides global variable. P() theb calls Q() by passing value of local 'x'.
// In P(int *y) int x = *y + 2; // Local x = 7 Q(x);In Q(int z), z uses x which is global
// In Q(int z) z += x; // z becomes 5 + 7 printz(); // prints 12After end of Q(), control comes back to P(). In P(), *y (y is address of global x) is changed to x  1 (x is local to P()).
// Back in P() *y = x  1; // *y = 71 print(x); // Prints 7After end of Q(), control comes back to main(). In main(), global x is printed.
// Back in main() print(x); // prints 6 (updated in P() // by *y = x  1 )
Question 90 
Consider the function f defined below.
struct item { int data; struct item * next; }; int f(struct item *p) { return ((p == NULL)  (p>next == NULL)  ((P>data <= p>next>data) && f(p>next))); }For a given linked list p, the function f returns 1 if and only if
the list is empty or has exactly one element  
the elements in the list are sorted in nondecreasing order of data value  
the elements in the list are sorted in nonincreasing order of data value  
not all elements in the list have the same data value. 
Discuss it
Question 90 Explanation:
There are 90 questions to complete.