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

•
.

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

•   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* 2xy
C : z2x+y
D : 2xzy

•
.

Solution :
Number of elements in W = 2xy
Number of elements in Z = z Number of functions from Z to E = z2xy

•   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

•
.

Solution :
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

•
.

Solution :
R is not reflexive

•   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

•
.

Solution :
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

•
.

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 arrives, but P0 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 t

•   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) S -> F. + E
(iii) S -> 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

•
.

•   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

•
.

•   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

•
.

•   Question 10

In a binary max heap containing n numbers, the smallest element can be found in time

A : O(n)
B : O(log n)
C : O(loglogn)
D : O(1)

•
.

Solution :
In a max heap, the smallest element is always present at a leaf node. So we need to check for all leaf nodes for the minimum value. Worst case complexity will be O(n)

•   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:

A : n-1
B : 2n-2
C : nC2
D : 2

•
.

Solution :
Minimum spanning tree of such a graph is
```v1

v2

v3

v4
.
.
.
vn```

Weight of the minimum spanning tree
= 2|2 – 1| + 2|3 – 2| + 2|4 – 3| + 2|5 – 4| …. + 2| n – (n-1) |
= 2n – 2

•   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

•
.

Solution :
The shortest path in an un-weighted graph means the smallest number of edges that must be traversed in order to reach the destination in the graph. This is the same problem as solving the weighted version where all the weights happen to be 1. If we use Queue (FIFO) instead of Priority Queue (Min Heap), we get the shortest path in linear time O(|V| + |E|). Basically we do BFS traversal of the graph to get the shortest paths.

•   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 : log 2n
B : n
C : 2n + 1
D : 2n-1

•
.

Solution :
For a right skewed binary tree, number of nodes will be 2^n – 1. For example, in below binary tree, node ‘A’ will be stored at index 1, ‘B’ at index 3, ‘C’ at index 7 and ‘D’ at index 15

•   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

•
.

Solution :
For selection sort, number of swaps required is minimum ( O(n) ).

•   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);
et 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 : val(j) = θ(√n)
C : val(j) = θ(n)
D : val(j) = θ(n logn)

•
.

Solution :
Note the semicolon after the for loop, so there is nothing in the body. 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)

•   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

A : R is NP-complete
B : R is NP-hard
C : Q is NP-complete
D : Q is NP-hard

•
.

Solution :
(A) Incorrect because R is not in NP. A NP Complete problem has to be in both NP and NP-hard.
(B) Correct because a NP Complete problem S is polynomial time educable to R.
(C) Incorrect because Q is not in NP.
(D) Incorrect because there is no NP-complete problem that is polynomial time Turing-reducible to Q.

•   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 θ(nlogn)
D : Solves it in time Theta(n^2)

•
.

Solution :
Scan all the elements from right to left in array and keep track of maximum till now. When maximum changes it’s value, print it.
So it will take linear time.

•   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 p1 = 1/2. The expected value of the smallest number in sample S is:

A : 1/n
B : 2
C : √n
D : n

•
.

Solution :
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

Let L1={ 0n+m1n0m | n,m>=0 } , L2={ 0n+m1n+m0m | n,m>=0 } and L3={ 0n+m1n+m0n+m | n,m>=0 }
Which of these languages are NOT context free?

A : L1 only
B : L3 only
C : L1 and L2
D : L2 and L3

•
.

Solution :
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 crashes 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

•
.

Solution :
Once a transaction is committed, no need to redo or undo operations.

•   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

•
.

Solution :
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 ≠ ∅

•
.

Solution :
If we draw the venn diagrams of both X and Y, we find that both cover exactly same region

•   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

•
.

Solution :
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

•   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|2 / nC|A ∪ B|

•
.

•   Question 25

Let S = {1,2,3,........,m},m > 3. Let X1.............. Xn be subsets of S each of size 3. Define a function f from S to the set of natural numbers as, f (i ) is the number of sets Xj that contain the element i. That is f(i) =| { j | i ∈ Xj| } |. &sigma of f(i) from i=1 to m is :

A : 3m
B : 3n
C : 2m+1
D : 2n+1

•
.

Solution :
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.Therefore in the same way solution will become 3n

•   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 : ∀x [ (tiger(x) ∧ lion(x)) -> {hungry(x) ∨ threatened(x)) -> attacks(x) } ]
B : ∀x [ (tiger(x) ∨ lion(x)) -> {hungry(x) ∨ threatened(x)) ∧ attacks(x) } ]
C : ∀x [ (tiger(x) ∨ lion(x)) -> {attack(x) ->(hungry(x) ∨ threatened(x)) } ]
D : ∀x [ (tiger(x) ∨ lion(x)) -> {hungry(x) ∨ threatened(x)) -> attacks(x) } ]

•
.

Solution :
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.

•   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

•
.

Solution :
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.

•   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)

•
.

Solution :
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.

•   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?

A : L ={ s ∈ (0 + 1) * | n0 (s) is a 3-digit prime }
B : L ={ s ∈ (0 + 1) * | for every prefix s` of s1 | n0(s`)-n1(s`) <=2 }
C : L ={ s ∈ (0 + 1) * | n0 (s) - n1(s) | <=4 }
D : L ={ s ∈ (0 + 1) * | n0 (s) mod 7 = n1(s) mod 5 =0 }

•
.

Solution :
Languages in option (A) And (D) are finite so both the options are eliminated. Only left options are (B) and (C). Both (B) and (C) look not regular as we don't have memory in DFA.

•   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) mod 5 = 2 and d(s) mod 7 != 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

•
.

Solution :
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

•
.

•   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

•
.

Solution :
II is not right because the grammer cannot produce aabb

•   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

•
.

•   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

•
.

•   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

•
.

•   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 : a2 b2 + a2 a1 b1 + a2 a1 a0 b0 + a2 a0 b1 b0 + a1 b2 b1 + a1 a0 b2 b0 + a0 b2 b1 b0
B : a2 b2 + a2 b1 b0 + a2 a 1b1 b0 + a1 a0 b2 b1 + a1 a0 b2 + a1 a0 b2 b0 + a2 a0 b1 b0
C : a2 + b2 + (a2 ⊕ b2)(a1 + b1 + (a1 ⊕ b1) (a0 +b0))
D : a2 b2 + a2` a1 b1 + (a2 a1)` a0 b0 + a2` a0` b1` b0 + a1 b2` b1 + a1 a0 b2` b0 + a0 (b2 b1)` b0

•
.

•   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

•
.

•   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

•
.

•   Question 39

We consider the addition of two 2’s complement numbers b(n-1)b(n-2)...b0 and a(n-1)a(n-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 : cout (an-1 ⊕ bn-1)`
B : an-1bn-1cn-1` + (an-1bn-1)`cn-1
C : cout ⊕ cn-1
D : an-1 ⊕ bn-1 ⊕ cn-1

•
.

Solution :
Overflow occurs only when Cin != 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 : g0( h3 h2 h1 h0) = ∑ ( 1,2,3,6,10,13,14,15)
B : g1( h3 h2 h1 h0) = ∑(4,9,10,11,12,13,14,15)
C : g2( h3 h2 h1 h0) = ∑(2,4,5,6,7,12,13,15)
D : g3( h3 h2 h1 h0) = ∑(0,1,6,7,10,11,12,13)

•
.

•   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 : 92ns
B : 104ns
C : 172ns
D : 184ns

•
.

Solution :
Size of cache block=64B
No. of main memory banks K=24
Size of each bank C=2B
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 So (D) is correct option

•   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 s
B : 1.2 s
C : 1.4 s
D : 1.6 s

•
.

Solution :
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

•   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.
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
D : mask <- 0 × f

•
.

•   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

•
.

Solution :
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)

•   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

•
.

Solution :

```Network Id of C1 = bitwise '&' of IP of C1 and subnet mask of C1
= (203.197.2.53) & (255.255.128.0)
= 203.197.0.0
C1 sees network ID of C2 as bitwise '&' of IP of C2 and subnet mask of C1
= (203.197.75.201) & (255.255.128.0)
= 203.197.0.0
which is same as Network Id of C1.

Network Id of C2 = bitwise '&' of IP of C2 and subnet mask of C2
= (203.197.75.201) & (255.255.192.0)
= 2```

•   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

•
.

Solution :
Total 16 packets are sent. See following table for sequence of events. Since go-back-n error control strategy is used, all packets after a lost packet are sent again.
```Sender      Receiver
1
2            1
3            2
4            3
5            4
6
7            6
7
[Timeout for 5]

5
6            5
7            6
8
9
8
9
[Timeout for 7]

7       ```

•   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)

•
.

Solution :
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.

•
.

Solution :
Since they are leaves in DFS, they must be separable by a vertex.

•   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

•
.

Solution :
The order in which insert and delete operations are performed matters here. The best case: Insert and delete operations are performed alternatively. In every delete operation, 2 pop and 1 push operations are performed. So, total m+ n push (n push for insert() and m push for delete()) operations and 2m pop operations are performed.
The worst case: First n elements are inserted and then m elements are deleted. In first delete operation, n + 1 pop operations and n push operation are performed

•   Question 50

A set X can be represented by an array x[n] as below in the image:
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)

•
.

Solution :
The expression x[i] ^ ¬ y[i]) results the only 1s in x where corresponding entry in y is 1. The expression ¬ x[i] ^ y[i]) results the only 1s in y where corresponding entry in x is 1.

•   Question 51

Consider the following recurrence: Which one of the following is true?
T(n) = 2T( ⌈√n ⌉) + 1, T(1) = 1

A : T(n) = θ(loglogn)
B : T(n) = θ(logn)
C : T(n) = θ(√n)
D : T(n) = θ(n)

•
.

Solution :
This question can be solved by first change of variable and then Master Method.
Let n = 2^m
T(2^m) = T(2^(m/2)) + 1
Let T(2^m) = S(m)
S(m) = 2S(m/2) + 1
Above expression is a binary tree traversal recursion whose time complexity is (m). You can also prove using Master theorem.
S(m) = (m)
= (logn) /* Since n = 2^m */
Now, let us go back to the original recursive function T(n)
T(n) = T(2^m) = S(m)
=

•   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(n2 Logn)
B : O(n2 )
C : O(n Logn Logn)
D : O(n Logn)

•
.

Solution :
If we use median as a pivot element, then the recurrence for all cases becomes
T(n) = 2T(n/2) + O(n)
The above recurrence can be solved using Master Method. It falls in case 2 of master method.

•   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?
(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)

•
.

Solution :
The function xyz() is similar to merge() of mergeSort(). The condition (i) is true if the last inserted element in c[] is from a[] and condition (ii) is true if the last inserted element is from b[].

•   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

•
.

•   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

•
.

•   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

•
.

•   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

•
.

Solution :
S2: May generate segmentation fault if value at pointers px or py is constant or px or py points to a memory location that is invalid
S4: May not work for all inputs as arithmetic overflow can occur

•   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 → ε}

•
.

•   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+*

•
.

•   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

•
.

•   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

•
.

Solution :
Let us talk about the operation P(). It stores the value of s in x, then it fetches the old value of x, stores it in y and sets x as 1. The while loop of a process will continue forever if some other process doesn’t execute V() and sets the value of s as 0. If context switching is disabled in P, the while loop will run forever as no other process will be able to execute V().

•   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 : 11bits
B : 13bits
C : 15bits
D : 20bits

•
.

Solution :
Size of a page = 4KB = 2^12
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.

•   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

•
.

Solution :
For supporting virtual memory, special hardware support is needed from Memory Management Unit. Since operating system designers decide to get rid of the virtual memory entirely, hardware support for memory management is no longer needed

•   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 : 13units
B : 14units
C : 15units
D : 16units

•
.

Solution :
Let the processes be p0, p1 and p2. These processes will be executed in following order.
```  p2  p1  p2  p1  p2  p0  p1   p2   p0   p1   p2
0   4   5   6   7   8   9   10    11   12   13   14
```

Turn around time of a process is total time between submission of the process and its completion.
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.

•   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

A : 0%
B : 10.6%
C : 30.0%
D : 89.4%

•
.

Solution :
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.
``` idle   p0    p1     p2    idle
0    2     9     23     44     47
```

Total time spent = 47
Idle time = 2 + 3 = 5
Percentage of idle

•   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

•
.

Solution :
Since both p and q don’t need additional resources, they both can finish and release Xp + Xq resources without asking for any additional resource. If the resources released by p and q are sufficient for another process waiting for Yk resources, then system is not approaching deadlock.

•   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

•
.

•   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 Qu
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.

•
.

Solution :
The output of Query2, Query3 and Query4 will be identical. Query1 may produce duplicate rows. But rowset produced by all of them will be same.
Table enrolled
```student   course
---------------
abc      c1
cs_2006      c1
abc      c2
pqr      c1

Table paid
student  amount
-----------------
abc      20000
cs_2006      10000
rst      10000
```

Output of Query 1
abc
abc
cs_2006
Output of Query 2
abc
cs_2006

•   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.

•
.

Solution :
Assuming that large enough memory is available for all data needed. Both plans need to load both tables courses and enrolled. So disk access time is same for both plans.
Plan 2 does lesser number of comparisons compared to plan 1.
1) Join operation will require more comparisons as the second table will have more rows in plan 2 compared to plan 1.
2) The joined table of two tables will will have more rows, so more comparisons are needed to find amounts greater than x.

•   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}

•
.

Solution :
Closure of AF or AF+ = {ADEF}, closure of AF doesn’t contain C and G.
Option (D) also looks correct. AB+ = {ABCDG}, closure of AB doesn’t contain F.

•   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

•
.

Solution :
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.

•   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 * 3
D : 2n-1

•
.

Solution :
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 w

•   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

•
.

Solution :
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.4ns
B : 2.3ns
C : 1.8ns
D : 1.7ns

•
.

•   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.4ns
B : 2.3ns
C : 1.8ns
D : 1.7ns

•
.

•   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

•
.

Solution :
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

•
.

Solution :
After insertion of 7
```
9
/   |
/     |
7       6       8
/ |
/   |
3    1    5
```
After insertion of 2
```                                           9
/    |
```

•   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 immediat
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.

•
.

Solution :
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 b
C : Context switch is disabled at the beginning of the barrier and re-enabled at the end.

•
.

•   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

•
.

Solution :
[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

•
.

Solution :
[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 mis

•   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?

A : B1, B5, B3, B4, B2
B : B1, B3, B5, B2, B4
C : B1, B5, B2, B3, B4
D : B1, B3, B4, B5, B2

•
.

•   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?

A : A
B : B
C : C
D : D

•
.

•   Question 84

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

A : S->AC|CB
C->aCb|a|b
A->aA | ε
B-> Bb|ε

B : S -> aS|Sb|a|b
C : S->AC|CB
C->aCb|&epsioln;
A->aA | ε
B-> Bb|ε

D : S->AC|CB
C->aCb|&epsioln;
A->aA | a
B-> Bb|b

•
.

•   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 labm with l ≠ m?

A : max(l,m) + 2
B : l + m + 2
C : l + m + 3
D : max(l, m) + 3

•
.