cs-gate 2007 1 vijay shekhar academy

33
CS-GATE 2007 1 (Q. NO. 1 – 20) 1 MARKS 1. f(x) x f(x) can be interperted as f(x) = x for x > 0 = –x for x < 0 From the graph we can see that x is continous for all real values of x But x is not differentiable at x = 0 P is true and Q is false (A) is the answer 2. let S = {1,2} , a set of 2 elements. Here , n = 2 A relation is said to be an equivalence relation if it satisfies the following properties i) Reflexive ii) Symmetric iii) Transitive Largest possible equivalence relation on S is S S = {(1,1),(1, 2),(2,1),(2,2)} It has 4 elements i.e. n 2 . Smallest possible equivalence realtaion on S is R = {(1,1),(2,2)} It has 2 elements i.e. n (B) is the answer GATE Subject : CS 2007 - SOLUTIONS VIJAY SHEKHAR ACADEMY

Upload: others

Post on 04-Jun-2022

5 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: CS-GATE 2007 1 VIJAY SHEKHAR ACADEMY

CS-GATE 2007 1

(Q. NO. 1 – 20) 1 MARKS

1. f (x) x

f (x) can be interperted as

f(x) = x for x > 0= –x for x < 0

From the graph we can see that x is continous for all real values of x But x is not differentiableat x = 0

P is true and Q is false(A) is the answer

2. let S = {1,2} , a set of 2 elements.Here , n = 2A relation is said to be an equivalence relation if it satisfies the following propertiesi) Reflexiveii) Symmetriciii) Transitive

Largest possible equivalence relation on S is S S = {(1,1),(1, 2),(2,1),(2,2)}It has 4 elements i.e. n2.Smallest possible equivalence realtaion on S isR = {(1,1),(2,2)}It has 2 elements i.e. n(B) is the answer

GATESubject : CS 2007 - SOLUTIONS

VIJAY SHEKHAR ACADEMY

Page 2: CS-GATE 2007 1 VIJAY SHEKHAR ACADEMY

VIJAY SHEKHAR ACADEMY 2

3. Number of n-ary functions possible with m variables in p–valued algebra are mpnThe question says boolean functions (i.e. p = 2 and m = n)

Maximum such functions possible = n22(C) is the answer.

4. A graph is said to be non–planar if it cannot be drawn in a plane such that no edges cross eachother.The smallest non–planar graph with minimum number of vertices is the complete graph K5

It has 5 vertices and 10 edges.

The smallest non–planar graph with minimum number of edges is the bipartite graph K3,3

It has 6 vertices and 9 edgesThe questions asks for minimum number of edges.So, (B) is the answer.

5. Topological ordering of a Directed acyclic graph (DAG) is a linear ordering of vertices suchthat for every directed edge (u,v), vertex u comes before v in the ordering.Multiple topological orderings are possible for a graph.For the given graph, following topological orderings are possiblei) 1 2 3 4 5 6ii) 1 2 3 4 6 5iii) 1 3 2 4 5 6iv) 1 3 2 4 6 5Clearly (D) is NOT a topological ordering as 3 comes before 1, which is not correct.(D) is the answer.

6. It is undecidable if a confext freee grammar is ambiguous.(B) is the answer.

Page 3: CS-GATE 2007 1 VIJAY SHEKHAR ACADEMY

CS-GATE 2007 3

7. (A) is false. Consdier the regular languages a* b* . One of its subsets S is S = an bn whichis not regular as we cannot have a DFA/NFA for it. Hence , not every subset of a regular setis regular.(B) is true. A finite language / set is always regular. Hence , every finite subset of non–regularset is regular.

(C) is false. Consider two non-regular sets S1 and S2 as S2 = {an bn}| 0n } and S2 = {an

bm | nm}. Now , S1S2 = a*b* which is regular. Hence , it is not always true that the unionof of two non-regular sets is not regular.(D) is false. Consider the infinite union of the following sets : {ab},{aabb}, {aaabbb},....

{ab} {aabb} {aaa bbb} ..... = {an bn | n > 0} Which is not regular but a CFL So,(B) is the answer.

8. Number of m - to - n line decoders needed to construct a p-to-q line decoder = 11

qn

Here m = 3, n = 8 and p = 6 , q = 64 Number of 3 : 8 decoders neede to construct a 6 : 64 decoder

= 64 18 1

637

= 9(C) is the answer.

9. Using K-map,

yz

011110

1 11 11 1

1 1

wx 00

00 01 11 10

( , , , )f w x y z xz xz x z

f is independent of 2 out of 4 variables i.e. w and y

(B) is the answer.

10. For a set associative memory, format isword size = block size = 64 w

word offset = 2log 64

Page 4: CS-GATE 2007 1 VIJAY SHEKHAR ACADEMY

VIJAY SHEKHAR ACADEMY 4

= 6 bits

##

cachelinessetsp way

128

4

= 32

Set offset 2log # sets

2log 32

5 bits

Number of bits in tag = 20 – (set offset + word offset ) = 20 – (5 + 6) =20 – 11 = 9

Here , set offset is referred to as LINE.So, the number of bits in the TAG, LINE and WORD fields are 9,5 and 6 respectively.(D) is the answer.

11. The disk has 16 surfaces 128 tracks per surface 256 sector per track 512B in a sector

Capacity of the disk pack = 16 128 256 512B

4 7 8 92 2 2 2

2819

11

28

4

282 = 256 MBH – surfaceT – tracksS – sectorsD – data in one sector

To access a sector we need to access the surface first, then the track to which that sector belongand then finally the corresponding sector.To access a surface, we need 4 bitsTo access a surface, we need ( 4 + 7) = 11 bitsTo access a surface, we need (4 + 7 + 8) = 19 bitsTo access a surface, we need (4 + 7 + 8 + 9) = 28 bits(A) is the answer.

Page 5: CS-GATE 2007 1 VIJAY SHEKHAR ACADEMY

CS-GATE 2007 5

12. For h = 2, we have 7 nodes i.e. 32 1

For h = 3, we have 15 nodes i.e. 42 1

For height ‘h’ we will have 12 1h nodes in binary treee.(C) is the answer.

13. Maximum number of binary trees that can be formed with ‘n’ unlabelled nodes = 211

nnC

n for n = 3

Number of binary trees = 63

13 1

C

= 1 204

= 5(B) is the answer.Trees will be as follows :

14. Sorting Algorithm Worst case time complexity(A) Merge sort O (nlogn )

(B) Bubble sort O ( 2n )

(C) Quick sort O ( 2n )

(D) Selection sort O ( 2n )

Merge sort has the lowest worst– case time complexity..(A) is the answer.

Page 6: CS-GATE 2007 1 VIJAY SHEKHAR ACADEMY

VIJAY SHEKHAR ACADEMY 6

15. Consider n = 8j = 11 < = 8 True The loop runs 4 times i.e. log2 8+12 < = 8 True4 < = 8 True8 < = 8 True16 < = 8 FalseFor n = 7j = 11 < = 7 True2 < = 7 True4 < = 7 True8 < = 7 False

Here the loop runs 3 times i.e. 2log 7 1

Comparisons made will be 1 more than the numbers of times the loop is executed. Weneed one extra comparison to get out of the loop when the condition in while loop is false.

Total comparisons mode are 2log 2n .

However if we consider successful comparisons, then we have 2log 1 n comparisons as

the last unsuccessful comparison will get us out of the loop.So we choose (D) is the answer.

16. Gang scheduling schedules threads or processes to run simultaneously on differentprocessors i.e. for parallel systems.

Rate monotonic schduling is a priority assignment algorithm used in real time OS (RTOS)with a static–priority scheduling class. The static priorites are assigned according to thecycle duration of the job, so a shorter cycle duration results in a higher job priority.

Fair share scheduling is a scheduling algorithm in which the CPU usages is equallydistributed among system users or groups, as opposed to equal distribution amongprocesses. One common example of fair share scheduling is round–robin schedulingstrategy.(A) is the answer.

17. (A) is true. Kernel level threads are mangaed by OS and kernel maintains lot of data structures.Hence there are many overheads involved in Kernel level thread management, unlike in user levelthreads.(B) is true as user level threads are managed by a user level library. The Kernel does not knowanythings about them.(C) is true. Kernel level threads operate indepedently. Hence , they can also utilize multiprocessor

Page 7: CS-GATE 2007 1 VIJAY SHEKHAR ACADEMY

CS-GATE 2007 7

systems by splitting threads on different processors or cores.(D) is false. If one kernel level thread blocks, it does not cause the entire process to block.Hence, they are a good choice for processes that block frequently.(D) is the answer.

18. Recursive descent parser is nothing but an LL(1) parser which uses top–down approach forparsing. The rest all are bottom–up parsers.(A) is the answer.

19. Manchester encoding is a line code in which the encoding of each data bit is eitherlow then high, or high then low or of equal time.

Baud rate represents the number of times per second a signal (changing from zero to oneor one to zero) changes state or varies.

Bit rate is the number of bits that are conveyed or processed per unit time.In Manchester encoding,

Bit rate 1=2

Baud rate

(A) is the answer.

20. For communication through HTTP, a connection needs to be established and hence it uses TCP,a connectionn oriented protocol.Telnet also uses TCP. Telnet provides bidirectional interactive text–oriented communication facilityusing a virtual terminal connection.DNS is a protocol used to query the server by a large number of people. It simply uses therequest response mechanism. DNS queries consist of a single UDP request from the clientfollowed by a UDP reply from the server i.e. DNS uses UDP. SMTP is used in mail transferwhere reliablity of message is an important factor. Hence, SMTP uses TCP.(C) is the answer.

(Q. NO. 21 – 85) 2 MARKS

21. Numbers of different non–isomorphic Abelian groups of order n are given byw(n)i 1 p ( ai ), where p ( ai ) is the number of partitions of the ith prime number..

Given order = 4Prime factorization of 4 = 22

Number of partitions of 2 are 2 i.e. {2,0} and {1,1}Note : The number of Abelian groups of order pk ( here p is prime ) is the number of partitionsof k.Total partitions of 2 are 2So number of different Abelian groups are 2(A) is the answer.

Page 8: CS-GATE 2007 1 VIJAY SHEKHAR ACADEMY

VIJAY SHEKHAR ACADEMY 8

22. “Not every graph is connected” implies that “There exists a graph which is not connected” Andfirst order logic of the implied statment is :

x (Graph (x) connected (x)) which is option (B)Option (A) is same as the given statement.Also, option (C) is equivalent to option (A).Option (D) elaborates to “ Every graph is not connected” which is not same as the given statement.(D) is the answer.

23. An undirected graph has an Eulerian circuit if and only if every vertex has even degree, and allof its vertices with non–zero degree belong to a single connected componenet.(A) does not have Eulerian circuit as a k–regular graph may not be connected.A disconnected 2– regular graph.

It does not have Eulerian ciruit as there is not path connecting the two components of the graph(B) does not have Euler circuit as degree of each vertex for a complete graph on 90 verticesis 89 which is odd.(C) has an Euler circuit, For a cycle on 25 vertices, degree of each vertex is 2. For its complement, degree of each vertex will be 25 – 2 – 1 = 22. Also the graph will be connected.(C) is the answer.

24. Consider 4 numbers 1,2,3,4When 2 appears at the first position :

2 = 3! = 6

When 2 appears at the second position :2 = 2.2! = 4

When 2 appears of the third position :2 = 2 × 1 = 2

Total cases = 4!

Requires probability =6 4 2 12 1

4! 24 2

Now, consider 6 number 1,2,3,4,5,6When 2 appears at the first position :

2 = 5! = 120

When 2 appears at the second position :

Page 9: CS-GATE 2007 1 VIJAY SHEKHAR ACADEMY

CS-GATE 2007 9

21/3/5

= 3 × 4! = 72

When 2 appears at the third posion :

23

2C

32 2! 3! 36 C

When 2 appears at the fourth position :

2

1/3/5 = 3! 4/6 = 2! 3! 2! 12

Total cases = 6!

Required probability = 120 72 36 12 240 1

6! 720 3

Hence on analyzing

For n = 4, number of even positions = 2 and probability =12

For n = 6, number of even positions = 3 and probability =13

For n = 20, numbers of even positions = 10

and hence probability will be 1

10

(B) is the answer.Also, if you solve using 20 numbers, you will get a complex expresession which would be tediousto evalnate. The expression would be :

19! 10 18! 10 9 17! ...... 10! 9!20!

Hence it is recommended that you decompose the problem into smaller and simlar subproblemsand then try to generalize the solution.

Page 10: CS-GATE 2007 1 VIJAY SHEKHAR ACADEMY

VIJAY SHEKHAR ACADEMY 10

25. We have to find the eigen values of A II A

0A I

I A

2 2– 0 A I

1 1 0A I A I

1 0 A I or 1 0A I

For matrix A, eigen values will satisfy

0 A kI

On comparing, we have

1k or 1k

5, 2,1, 4k is given

4, 3,0,3 or 4, 1, 2,5

2 is one of the eigen values(C) is the answer.

26. Consider two partitions of a set S as

S1 = 1 2 3{a ,a ,a ,.....} and S2 = 1 2 3{b ,b ,b ,.....} . We say that S1 refines S2 if every bi is a subset

of some aj. So, 1 refines 2 , 3 and 4 .Also 2 and 3 refine 4 .

It is given that 1S is a partial order set POSET has the following properties :

i) Reflexiveii) Anti Symmetriciii) TransitiveBut we do not show transitive dependencies in a POSET diagram. The correcrt POSET diagramis :

(C) is the answer.

Page 11: CS-GATE 2007 1 VIJAY SHEKHAR ACADEMY

CS-GATE 2007 11

27. To be basis of subspace X following conditions are to be fulfilled :1) They must span X2) The vectors have to be linearly independent. For x1 + x2 + x3 = 0,

general solution is 2 3 2 3[ , , ] Tx x x x

let 2 1x and 3 0x ,

Now let 3 1x and 2 0x , [ 1, 1, 0] T

1, 1,0 T and [ 1,0,1]T are two linearly indepedent solutions as one can be obtained from

the other by sacalar multiplication.

Since both of these column vectors can be generated by linear combinations of

and [1,0, 1]T it spans X

{[1, 1,0]T , [1,0, 1] }T is basis for subspace X.

(A) is the answer.

28. By Newton Raphson’s method,

1 ' n

n nn

f xx x

f xconvert the given equation in the above form.

19

2 8 nn

n

xxx

19

2 8n

n nn

xx xx

2

1

4 98n

n nn

xx x

x

f 24 9 n nx x

f ' 8n nx x

Roots of 24 9f x x are 32

x

1.5x

But 0x is given as 0.5. So we cannot get any negative value at any time from the eqution

of f x

1.5x (A) is the answer.

Page 12: CS-GATE 2007 1 VIJAY SHEKHAR ACADEMY

VIJAY SHEKHAR ACADEMY 12

29. Note : A minimum state DFA that accepts the language over {0,1} where number of 0’s and1’s are divisible by ‘m’ and ‘n’ respectively has (m * n ) states.In the given question m = 3 and n = 5 Minimum DFA has 3 × 5 = 15 states.(A) is the answer.

30. The language L = { 0i 21i | i 0} is a deterministic CFL.For each 0, we push one X onto the stack.For each 2, we perform no operation.For each 1, we pop one X out of the stack.And we know that CFLs are subset of recursive languages. L is recursive as well(B) is the answer.

31. The language {wxwR | x,w {0,1}+} is regular. It can be thought of as a language having stringsstarting and ending with the same letter i.e. strings of the form 0x0 or 1x1.(C) is the answer.Rest all other options have palindrome as their substring.

32. , , , 0, 4,5,7,8,9,13,15f w x y z

Using K-map,

f xz wyz wx y

xz y y wx y wx y

xyz x yz wyz wx y

f is equivalent to (B) and (C)Now consider option (A),

x y z w x y w y z x z0 0 0 0 0 1 0 0 1 0 0 1 0 1 0 1, 0 1 1 11 0 0 0 0 1 0 1 1 1 0 1 1 1 0 1, 1 1 1 1( 0 , 8 ) ( 4 , 5 ) ( 9 , 1 3 ) ( 5 , 7 , 1 3 , 1 5 )

(0,8) (4,5) (9,13) (5,713,15) = (0,84,5,913,7,15) = f

(A) is also equivalent to fSo (D) is the answer.

Page 13: CS-GATE 2007 1 VIJAY SHEKHAR ACADEMY

CS-GATE 2007 13

33. X * Y = XY + X ' Y ' (given)

* is the EX–NOR operator hereZ = X * Y (given)Consider PX= Y*ZRHS= Y * Z

= YZ + Y ' Z '

= Y (X * Y) + Y ' (X * Y) '

= Y (XY+X ' Y ' )+ YY ' (XY + X ' Y ' )

= XY + 0 + Y ' (X ' Y + X YY ' )

= XY + Y ' X

= X( Y + Y ' ) = X

LHS = RHS = XSo, P is valid.Consider QY= X * ZRHS = X * Z

= X * Z

= XZ + X ' Z '

= X (X * Y) + X ' (X * Y) '

= X(XY+X ' Y ' )+ X ' (XY +X ' Y ' ) '

= XY + 0 + X ' (X ' Y + X YY ' )

= XY + X ' Y + 0

= Y (X + X ' ) = Y

LHS = RHS = YYSo Q is also validconsider RLHS = X * Y * Z

= X * X (As we know Y * Z = X from P)

= XX + XX '

= X + X '

= 1

Page 14: CS-GATE 2007 1 VIJAY SHEKHAR ACADEMY

VIJAY SHEKHAR ACADEMY 14

LHR = RHS i.e X * Y * Z =1So R is also valid. all the statments are valid.(D) is the answer.

34. We can implement the multiplexer by using (n –1) select lines and one variable to the input line.So we need 2n-1 : 1 MUX.(C) is the answer.

35. For a n– bit carry lookahead adder,

Number of AND gates needed = 1

2n n

Number of OR gates needed = nHere, we have a 4–bit carry lookahead adder.

Number of AND gates needed = 4 5

102

and number of OR gates needed = 4(B) is the answer.

36. Initially A4A3A2A1 = 0000clear = A1.A3 When clear = 1 , all the inputs will be cleared to 0clear = 1 when both A1 = 1 and A3 = 1 Starting from 0000, it will count

A4 A3 A2 A10 0 0 0 (0)0 0 0 1 (1)0 0 1 0 (2)0 0 1 1 (3)0 1 0 0 (4)0 1 0 1

Here both A1 and A3 are 1. So all the inputs will be cleared to 0 immediately and 5 will notbe counted. So the counting sequence is 0,1,2,3,4(C) is the answer.

Page 15: CS-GATE 2007 1 VIJAY SHEKHAR ACADEMY

CS-GATE 2007 15

37. IF ID EX WBI1 ADD 1 1 1 1I2 MUL 1 1 3 1I3 SUB 1 1 1 1

Pipeline will be as follows :

IFIF

IF

IDID

ID

EXEX EX EX

EX

WB

WBWB

1 2 3 45 6 7

8

We need 8 clock cycle to execute the given sequence of instructions.(B) is the answer.

38. Initially 8, 2 and 3 are pushed onto the stack in that order

328

when ' ' is encountered, 3 and 2 are popped from the stack. The operation 2 3 is performedi.e. 32 8 and the result ‘8’is pushed onto the stack.

88

Now when ‘/’ operator is encountered, 8/8 = 1 and 1 is pushed onto the stack

1

Now 2 and 3 are pushed onto the stack

321

Now when the first * is encountered , we perform 2 * 3 which is 6 and the result of this operationi.e. 6 is pushed onto the stack. Contents of the stack ofter first * is evaluated are

61

So, (A) is the answer.

Page 16: CS-GATE 2007 1 VIJAY SHEKHAR ACADEMY

VIJAY SHEKHAR ACADEMY 16

39. Pre–order traversal of a binary tree : abdecfg In–order traversal of a binary tree : abeafcg From pre–order traversal, we can say that ‘a’ is the root node.Tree construction :

a

b,d,e f,c,g

abedcfg b is the root

is the corresponding treePost–order traversal of the constructed tree (Visit left – right – root ) is debfgca(A) is the answer.

40. Hash function is h(x) = (3x + 4) % 7. Closed hashing is the other name for open addressing.And open hashing is the other name for closed addressing.So the hash table is

When 1 is to be inserted(3(1) + 4) % 7 = 7 % 7 = 0 Insert at location 0When 1 is to be inserted,(3(3) + 4) % 7 = 13 % 7 = 6 insert at location 6(3(8) + 4) % 7 = 28 % 7 = 0 collision

Check for next open address using linear probing 0 + 1 = 1. Location 1 is empty.. Insert 8.When 10 is to be inserted, (3 (10) + 4) % 7 = 34 % 7 = 6 collisionCheck for next open address

Page 17: CS-GATE 2007 1 VIJAY SHEKHAR ACADEMY

CS-GATE 2007 17

i.e. ( 6 + 1) % 7 = 0 again a collision( 0 + 1 ) % 7 = 1 again a collision( 1 + 1) % 7 = 2 location 2 is empty Insert 10 at location 2.(B) is the answer.

41. To find shortest path from a node S to every other node,Time complexity of Dijkstra’s algorithm = O(E + VlogV)Time complexity of Warshall’s algorithm = O(V3) DFS cannot be used to find shortest paths as it may run into recursion if the depth of the graph keeps on expanding which won’t result in a shortest path from S to every other node.BFS finds the shortest path in O (E + V ) time. So, BFS is the most efficient algorithm to find shortest path in terms of time complexity.(D) is the answer.

42.

f(5)

f(3) + 2 =

f(2) + 5 =

f(1) + 5 =

f(0) + 5 =

1

18

16

11

6

(r = 5 ) and since r is a static variable, it will be shared between function calls. f (5) will return the value 18(D) is the answer.

43. For a n–ary tree,L = (n – 1)I + 1

41 = (n – 10)10 + 1

40 = (n – 1)10

n – 1 = 4

n = 5(C) is the answer.

Page 18: CS-GATE 2007 1 VIJAY SHEKHAR ACADEMY

VIJAY SHEKHAR ACADEMY 18

44. To find GCD of (m, n) , we require time of (log{max (m, n)}) in the worst case. But it ismentioned that n > = m Time complexity = (logn)(A) is the answer.

45. Recurrence relation for the given function is : T(n) = ( )T n + n ; n > 2

We can ignore the floor part

T(n) = ( )T n + n ; n > 2

let n = 2m

So the recurrence relation becomes

22 2m

mT T c

Now let 2 mT S m

( )2

mS m S c

It is the same recurrence relation as that of binary search. S(m) = (log m)But m = log2n (as n = 2m ) T(n) = (log2log2n )(D) is the answer.

46. The given code returns the number of leaf nodes in the tree. As we can see, Getvalue returnsthe value 0 when both its left child and right child are NULL, that is nothing but a leaf node.When there is only one node in a tree, it will return that node because that single nodeserves as the root node as well as the leaf node.(D) is the answer.

47. We know that heaps are stored in complete binary trees Length of the path from root to the newly inserted element will be (log n)Hence the number of elements from new leaf to root will be O(log n) and since it is amax–heap, they will be present in sorted order.Now to perform a binary search on logn elements, time complexity = (log log n)(B) is the answer.

Page 19: CS-GATE 2007 1 VIJAY SHEKHAR ACADEMY

CS-GATE 2007 19

48. It can be easily proved that “ For any formula there is a truth assignment for which atleasthalf the clauses evaluate to true”.Conjunctive nermal Form (CNF) is nothing but maxterm expression or the product of sumexpression. Consider a truth statment having n clauses. For each of its clause i, introduce a randomvariableXi = 1 if clause i is satisfied = 0 otherwise

So, X = 1

n

ii

X is the number of satisfied clauses.

A clause is unsatisfied only if all of its literals evaluate to false (as they are connected by anOR operator inside each term in CNF)Let there be k such literals. Since each literal can take only one among the two truth valuesindependently of the truth values of the other literals, the probability of each literal evaluatingto true is 1/2 .The probability that all k literals are false

1 1 1.....2 2 2

(k times)

12

k

So the probability that the clause is true = 1 – 12k

For one clause,

1 11 1 12 2

i k kE X

For k ( numbers of literals ) = 1 ,2,.....

we get 12

iE X

So, for ‘n’ clauses we have

1 2

n

ii

nE X E X

( )E X is the expected number of true clauses and at least half of them evaluate to true.

(A) is the answer.

49. (A) is true. There will be at least one minimum spanning tree containing the edge e having minimumweight w.(B) is true. As e is not in the minimum spanning tree, all the edges in the minimum spanning treemust have wieght less than or equal to e.(C) is true because a minimum spanning tree must have the edge with minimum wieight.

Page 20: CS-GATE 2007 1 VIJAY SHEKHAR ACADEMY

VIJAY SHEKHAR ACADEMY 20

(D) is false. Not every minimum spanning tree will have the edge e as it is possible that addingthe edge e in a minimum spanning tree may create a cycle if there are other edges in the treehaving the same weight.(D) is the answer.

50. Using divide and conqure strategy, the maximum as well as minimum of n numbers in an arraycan be determined in (n) time.

The number of comparisons required are 32n

–2

The recurrence relation is

( ) 2 22nT n T

n > 2

= 0 n = 1 = 1 n = 2

On solving this recurrence relation,

( ) 2 22nT n T

24 2 2

4nT

1

2 22

kk i

k i

nT

12 2 2

2k k

k

nT

1

12 2 2

ii k

i

Let k = logn – 1 , 1 logk n

log 1 log( ) 2 1 2 2n nT n T

log

log2 1 2 22

nnT

22n n

3 22nT n

(B) is the answer.

51. Worst case will be when n is a prime number

O T n n

Best case will be when n is an even number. So n % 2 = = 0 and the program will return o.

Page 21: CS-GATE 2007 1 VIJAY SHEKHAR ACADEMY

CS-GATE 2007 21

i.e. it gets executed in one step.

(1)T n

(B) is the answer.

52. The given grammar is derived from a left factored grammar.The original left factored grammar is :

| |S iCtS iCtSeS a

C bAnd we know that left factored grammars are ambiguous.

Also, first (iCtS) first (iCtSeS) = {i}

So, the grammar is not LL(1) because it is ambiguous.(C) is the answer.

53. Statement P is false.Consider the regular grammar for the language a+

| aA aA |S aA

The grammar is ambiguous because it has two parse trees for the string ‘a’So, the grammar is not LL(1)Now, consider another grammar for the same language a+

| aA aS aA

This grammar is unambiguous. So it is LL(1). Since it is LL(1), an LR(1) parser can alsoparse it because LR(1) parsers are more powerful than LL(1) parsers. So, every regular set hasa LR(1) parser. Statement Q is true.(C) is the answer.

54. Considering only 2 registers, the code for the given block will be :MOV a, r1ADD b. r1MOV c, r2ADD d, r2SUB e, r2SUB r1,r2MOV r2, m where ‘m’ is a memory location

Page 22: CS-GATE 2007 1 VIJAY SHEKHAR ACADEMY

VIJAY SHEKHAR ACADEMY 22

Total number of MOV instructions = 3(B) is the answer.

55. Process E.T A.T C.T T.A.T W.TP1 20 0 20 20 0P2 25 15 55 40 15P3 10 30 40 10 0P4 15 45 70 25 10

0 15 20 30 40 45 7055P1 P1 P2 P3 P2 P2 P4

Use TAT = CT – AT andWT = TAT– ET

For process P2,TAT = 55 – 15 = 40WT = 40 – 25 = 15

Waiting time for P2 is 15 units.(B) is the answer.

56. P is true. It describes the Belady’s anamoly and it occurs in FIFO pages replacement policy.Q is also true. Locality of reference occurs when we try to access array elements which are palcedin memory in consecutive locations (eg. row major order). HOwever, we can have programs thatdo not exhibit locality of reference like trying to access a 2D array in column major order (asby default, if will be stored in raw major order). So, both statements are true but Q is not theexplanation for P.(B) is the answer.

57. There are 5 units of each resource of type X,Y and Z

X Y Z X YP0 1 2 1 1 0P1 2 0 1 0 1P2 2 2 1 1 2

TOTAL 5 4 3

RequestAllocation

Available or unallocated resources = Total resources – allocated resources = < 5 , 5 , 5 > – < 5, 4, 3 >

= < 0, 1, 2 >

Page 23: CS-GATE 2007 1 VIJAY SHEKHAR ACADEMY

CS-GATE 2007 23

With this availability we can satisfy only the request of P1. After P1 is serviced, it will releaseits allocation < 2, 0, 1 > New availability = < 0, 1, 2 > + < 2, 0, 1 >

= < 2, 1, 3 >Now, request of P2 cannot be satisfied even with this new availability.But we can satisfy request of P0. After P0 is serviced,New availability = < 2, 1, 3 > + < 1, 2, 1 >

= < 3, 3, 4 >Now, we can satisfy the request of P2 P2 will finish LAST..(C) is the answer.

58. P1 P21. while (true){ 1. while (true){2. wants1 = true; 2. wants 2 = true;3. while (wants2 = =true); 3. while (wants1= = true);4. Critical section 4. Critical section5. wants = false; 5. wants2 = flase ;6. } 6. }Remainder section Remainder section

Let P1 and P2 be concurrently executed Initially wants1 = wants2 = false ;P1 excutes statements 1 & 2 wants1 = trueP2 executes statements 1 & 2 wnats2 = trueP1 and P2 both execute statements 3 Deadlock occurs as the conditions inside while loops become true and both processes waitfor each other to finish. To prove mutual exclusion, consider the following : P1 executes statements1, 2, 3 wants1 = trueBut intially wants 2 = falseHence condition inside while loop evaluates to false P1 enters critical section.Now, P2 executes 1, 2, 3wnats2 = trueThe condition inside while loop is true. So it will loop and wait for P1 to fininsh and come outof critical section. As soon as P1 comes out of critical section and executes statement 5 , wants1 = false. P2 will enter the critical section. Hence, mutual exclusion is ensured but we the solution doesnot prevent deadlocks.(D) is the answer.

Page 24: CS-GATE 2007 1 VIJAY SHEKHAR ACADEMY

VIJAY SHEKHAR ACADEMY 24

59. The given query does the following :(i) It initially select all the StudIds of female students and courseIds of all the courses in whichthe students have enrolled in.(ii) The query then performs a cartesian product from, the select columns in step (i).(iii) It then subtracts the enroll table from the result of step (ii).(iv) Finally it projects the courseId of the tuples retrieved in step (iii).Thus, the query will eliminate all the (StudId, courseId) pairs which were initially present in theenroll table i.e. it eliminates the female students which had already registered for a particular course.Hence, the final result will be the courseIds of female students which have enrolled in a particularcourse but not mentioned in the enroll table.So, (B) is the answer.

60 The given query selects employee e such that e is an emplyee and for all x, either x is not anemployee or x. supervisor Name e.name or x is male.This is same as selecting all employees who do not have an immediate female subordinate.

Alternative solution : Apply De Morgan’s theorem and evaluate the query.Since Or (‘ ’ operator) is associative and commutative, we can rewrite the query as

{ e. name | employee (e) x [ employee (x) x.sex = “male” x. supervisor Name

e. name]}

= { e.name | employee (e) x [ employee (x) x.sex “male” )V x. supervisor Name

e. name]}

= { e.name | employee (e) x [(employee) (x) x.sex “male” ) x. supervisor Name

e. name]}

= { e.name | employee (e) x [( employee) (x) x.sex = “female” ) x. supervisor Name

e. name]}Hence it is clear that the query retrieves name of employees with no immediate female subordinates.(C) is the answer.

61. Consider the employee table as :

emp Id name department salarye1 A 4 7000e2 B 2 5000e3 C 5 3000e4 D 3 10000e5 E 5 8000

We want to find the employees who get higher salary than anyone in department 5. i.e. employeeswho get higher salary than the employee having highest salry in departrment 5 So, we should get

Page 25: CS-GATE 2007 1 VIJAY SHEKHAR ACADEMY

CS-GATE 2007 25

e4 as the answerQuery Q1 returns the tuple e4Query Q2 returns the tuples e1,e2,e4Cleary Q1 is the correct query.(A) is the answer.

62. (A) is true. A binary relation or a relation with two attributes is always in BCNF.(B) is true. Since there is only one attribute in every key, there will be no proper subset of keyattribute and hence no such partial dependency as proper subset of key Non key..Hence the relation will be in 2NF.(C) is true. Transitive dependencies are allowed in 3NF but not in BCNF.(D) is false.(D) is the answer.

63. Let ‘p’ be the order of the leaf node. For a B + tree,p * keys + p * record pointers + 1 Block pointer Block size. p * 9B + p * 7B + 6B 1024 B

p * 16 B 1018 B

p 101816

BB

p 63.625 pmax = 63So, the order of the leaf node is 63.(A) is the answer.

64.

S1 S2T1 T2 T1 T2

r( )x r( )xr(y) r(x)

r(x) r(y)w(y)r(y)

w(y)w( )x

r(y)w x( )

Precedence graph of S1 Precedence graph of S2

Cycle Not conflict seralizable No cycle Conflict serializable(C) is the answer.

Page 26: CS-GATE 2007 1 VIJAY SHEKHAR ACADEMY

VIJAY SHEKHAR ACADEMY 26

65. Number of stations in a LAN = nProbability that a station transmits = p Probability that a station does not transmit = 1 – pWe have the find the probability that only one station transmits.This is equivalent to saying that 1 out of n stations transmits and the rest ( n - 1) do not transmit

1 n –1n1

n –1

Required probability = C p 1- p

= np(1- p)

(B) is the answer.

66. Transmission speed = 107 bps107 bits ––– 1 second 1 bit ––– x second

x = 7

110 sec

= 107 secx = 0.1 sec

Propagation speed = 200 metres / sec200 m –––– 1 secx m –––– 0.1 sec x = 200 × 0.1

x= 20 metres

1 – bit delay is equivalent to 20 metres in this network.(C) is the answer.

67. For class B,Default mask = 255.255.0.0We want to split the address of class B into 6–bit subnet number

subnet mask = 255.255. 11111100.00000000subnet bits host bits #subnets = 62 2

= 62#hosts = 210 – 2 (Leaving first address and last address) = 1022

(C) is the answer.

Page 27: CS-GATE 2007 1 VIJAY SHEKHAR ACADEMY

CS-GATE 2007 27

68. Message (M) = 11001001Divisor = x3 + 1 = 1001 Append 3 0’s to the message before performing division.

Messge to be transmitted M ' = M + CRC = 11001001011

(B) is the answer.

69. Distance (d) = L kmPropagation delay (Pt) = t sec/kmFrame length (L) = K bits (BW)Bandwith or channel capacity (BW) = R bps

Transmission time (Tt) = L

BW

= Kb

Rbps

= secKR

Propagation delay (Pt) = t sec / kmt sec –––– 1 Km

x sec ––– L Km

x = t × L sec Pt = t L secFor maximum efficiency in a sliding window protocol,

Page 28: CS-GATE 2007 1 VIJAY SHEKHAR ACADEMY

VIJAY SHEKHAR ACADEMY 28

Window size (W) = 2Tt Pt

Tt

=

2K LtR

KR

2

K LtRW

K

Number of bits for the sequence number field

= 2log W

= 22log K LtRK

(B) is the answer

70. SMTP is an application layer protocol used for e-mail transfer.TCP is a transport layer protocol for end to end communication. BGP is a network layer protocoldesigned to exchange routing and reachability information among autonomous systems on theinternet. PPP is a data link layer protocol used to establish a direct connection between tow nodes.(B) is the answer

71. LOOP is executed 10 times and there are two memory references in each loop (1 memoryreference for MOV instruction) So, total memory references inside the LOOP = 2 × 10

= 20Also, there is one memory reference outside the LOOP (the first MOV instruction )

Total memory references = 20 + 1 = 21(D) is the answer.

72. We know that LOOP is executed 10 times and hence it alters the contents of the memory locations2000 to 2009. The content of memory location 2010 is not altered. It is same as before – 100(A) is the answer.

73. It is given that the interrupt occurs during the execution of the instruction INC R3

Address of instruction INC R3

= 1000 + (2 + 1 + 1 + 1 +1) ×328 bytes

= 1000 + 5 × 4 B

Page 29: CS-GATE 2007 1 VIJAY SHEKHAR ACADEMY

CS-GATE 2007 29

= 1020 BWe know that when an interrupt occurs, it is checked for after the execution of the currentinstruction and contents of PC ( address of next instruction to be fetched ) is pushed onto thestack. Address pushed onto the stack = 1020 + 4 = 1024(C) is the answer.

74. The smallest string accepted by the given automata is ‘a’. Now check which of the regularexpressions accept ‘a’ as the smallest string.(A) accepts smallest string as aaa(B) accepts smallest string as (C) accepts smallest string as a(D) accepts smallest string as aa.Clearly (C) is the language accepted by the given FA.(C) is the answer.

75. The minimized DFA for the regular expression b*a (a + b)* is

ba

a, b

It has 2 states.(B) is the answer.

76. From the given probabilities, we can calculate the frequencies of a, b,c,d,e,f as 16,8,4,2,1,1respectively.The Huffman tree is as follows :

11

1

1

1f

0

0

00

0e

d

cb

a

Now, Huffman code for each of the letters is :a = 0b = 10c = 110d = 1110e = 11110(A) is the answer.

Page 30: CS-GATE 2007 1 VIJAY SHEKHAR ACADEMY

VIJAY SHEKHAR ACADEMY 30

77. Average length = n

i ii l

P F

where Pi – probability of each letter Fi – length of codeword of each letter

Average length = 1 1 1 1 1 11 2 3 4 5 52 4 8 16 32 32

= 6232

= 1.9375(D) is the answer.

78. The given grammar generates the language having equal number of a’s and b’s. From the givenoptions, aabbab is the only string generated by the given grammar. We can derive it using thefollowing sequence.

S aB aaBB

aabB aabbS aabbaB aabbab(C) is the answer.

79. Derivation trees for the string w = aabbab

a

bb

b

a

a B

B

S

B

B

S

b

a

b

b

a

a

B

BB

S

A

S

only 2 parse trees are possible.(B) is the answer.

80. For direct mapped data cache,

bits used to represent addresses = log2162

= 16 bitsFormat for direct mapped cache is

Page 31: CS-GATE 2007 1 VIJAY SHEKHAR ACADEMY

CS-GATE 2007 31

tag line offset word offset16

cache line size = block size = 64 B

word offset = 2log 64

= 6 bits #lines in cache = 32

lines offset = 2log 32

= 5 bits Tag bits = 16 – ( 6 + 5 )

= 5 bitsSize of the given 2D array = 50×50×1B

= 2500BSo, number of cache lines required for this 2 D array

= 2500 B64 B

= 39.0625 40

We require 40 cache lines to hold this array but we have only 32 cache lines availableStarting address of array = 1100 H

00100 000000tag Line offset Block offset

00010

Hence, array starts from cache line number 4 .

Page 32: CS-GATE 2007 1 VIJAY SHEKHAR ACADEMY

VIJAY SHEKHAR ACADEMY 32

Line number Array line01234567891011. .. .. .. .. .

3031

28A

29A

30A

31A

0A

1A

2A

3A

4A

5A

6A

7A

32A

3 3A34A

35A

36A

37A

38A

39A

26A

27A

During the first access, we will have (32 + 8 ) misses 40 misses in first access. When the array will be accessed for the second time majority ofthe elements will already be in cache.

A0 to A7 will be cache misses and A32 to A39 will also be cache misses 8 + 8 = 16 misses in second accessSo that number of cache misses = 40 + 16 = 56.(C) is the answer.

81. As it is given that starting address of array is 1100 H 00010 00100

Line offset 00100

So, we can see that it starts from cache line number 4 and since we need 40 lines for the entirearray but only 32 cache lines are available, so last 8 blocks of first access will be replaced byfirst 8 block of the second access For 8 blocks (lines), we need 8 linesi.e. from line number 4 to 11.(A) is the answer.

Page 33: CS-GATE 2007 1 VIJAY SHEKHAR ACADEMY

CS-GATE 2007 33

82. Using optimal page replacement policy, page – frames = 3

1

334466671555333

77222

411111

365473121

Hit Hit HitWe have 3 hits

#page faults =10 – 3 = 7(A) is the answer.

83. Using LRU page replacement policy,

13344

6667

7555333

7722241111

3654731211

Hit#page faults = 10 – 1 = 9Hence 2 page faults occur more in LRU than the optimal page replacement policy for the samereference string.(C) is the answer.

84. To move from (0,0) to (10,10) we need to traverse 20 steps ( 10 right and 10 up) Thus, numberof such possible arrangements

= 20!

10!10! = 1020C

(A) is the answer.

85. We are not allowed to traverse from (4,4) to (5,4). So to find paths passing through (4, 4) to(5, 4) we traverse from (0,0) to (4,4) and then (5,4) from (5,4) to (10,10)

#paths from (0,0) to (4,4) = 8!

4!4!

= 8C4

#paths from (5,4) to (10,10) = 11!5!4!

= 11C5

Now we subtract these paths from the total number of paths.Total number of paths = 20C10 – 8C4 × 11C5

(D) is the answer.