You are on page 1of 291

# SREENIVASA INSTITUTE OF TECHNOLOGY AND MANAGEMENT STUDIES

(AUTONOMOUS)

## GATE BITS SUBJECT-WISE

1. GATE Syllabus .. 3 2. Programming and Data Structures... 5 3. Design And Analysis Of Algorithms 57 4. Compiler Design . 69 5. Operating System 90 6. Databases ... 124 7. Software Engineering . 154 8. Computer Networks 160 9. Web technologies. 179 10. Computer Organization.. 185 11. Digital Logic . 237

GATE SYLLABUS
1. COMPUTER SCIENCE AND INFORMATION TECHNOLOGY CS & IT Engineering Mathematics

Mathematical Logic: Propositional Logic; First Order Logic. Probability: Conditional Probability; Mean, Median, Mode and Standard Deviation; Random Variables; Distributions; uniform, normal, exponential, Poisson, Binomial. Set Theory & Algebra: Sets; Relations; Functions; Groups; Partial Orders; Lattice; Boolean Algebra. Combinatorics: Permutations; Combinations; Counting; Summation; generating functions; recurrence relations; asymptotics. Graph Theory: Connectivity; spanning trees; Cut vertices & edges; covering; matching; independent sets; Colouring; Planarity; Isomorphism. Linear Algebra: Algebra of matrices, determinants, systems of linear equations, Eigen values and Eigen vectors. Numerical Methods: LU decomposition for systems of linear equations; numerical solutions of non-linear algebraic equations by Secant, Bisection and Newton-Raphson Methods; Numerical integration by trapezoidal and Simpson's rules. Calculus: Limit, Continuity & differentiability, Mean value Theorems, Theorems of integral calculus, evaluation of definite & improper integrals, Partial derivatives, Total derivatives, maxima & minima. GENERAL APTITUDE(GA): Verbal Ability: English grammar, sentence completion, verbal analogies, word groups, instructions, critical reasoning and verbal deduction. Computer Science and Information Technology Programming and Data Structures: Programming in C; Functions, Recursion, Parameter passing, Scope, Binding; Abstract data types, Arrays, Stacks, Queues, Linked Lists, Trees, Binary search trees, Binary heaps. Algorithms: Analysis, Asymptotic notation, Notions of space and time complexity, Worst and
3

average case analysis; Design: Greedy approach, Dynamic programming, Divide-and-conquer; Tree and graph traversals, Connected components, Spanning trees, Shortest paths; Hashing, Sorting, Searching. Asymptotic analysis (best, worst, average cases) of time and space, upper and lower bounds, Basic concepts of complexity classes P, NP, NP-hard, NP-complete. Compiler Design: Lexical analysis, Parsing, Syntax directed translation, Runtime environments, Intermediate and target code generation, Basics of code optimization. Operating System: Processes, Threads, Inter-process communication, Concurrency, Synchronization, Deadlock, CPU scheduling, Memory management and virtual memory, File systems, I/O systems, Protection and security. Databases: ER-model, Relational model (relational algebra, tuple calculus), Database design (integrity constraints, normal forms), Query languages (SQL), File structures (sequential files, indexing, B and B+ trees), Transactions and concurrency control. Information Systems and Software Engineering: information gathering, requirement and feasibility analysis, data flow diagrams, process specifications, input/output design, process life cycle, planning and managing the project, design, coding, testing, implementation, maintenance. Computer Networks: ISO/OSI stack, LAN technologies (Ethernet, Token ring), Flow and error control techniques, Routing algorithms, Congestion control, TCP/UDP and sockets, IP(v4), Application layer protocols (icmp, dns, smtp, pop, ftp, http); Basic concepts of hubs, switches, gateways, and routers. Network security basic concepts of public key and private key cryptography, digital signature, firewalls. Theory of Computation: Regular languages and finite automata, Context free languages and Push-down automata, Recursively enumerable sets and Turing machines, Undecidability. Digital Logic: Logic functions, Minimization, Design and synthesis of combinational and sequential circuits; Number representation and computer arithmetic (fixed and floating point). Computer Organization and Architecture: Machine instructions and addressing modes, ALU and data-path, CPU control design, Memory interface, I/O interface (Interrupt and DMA mode), Instruction pipelining, Cache and main memory, Secondary storage. Web technologies: HTML, XML, basic concepts of client-server computing.

## Programming and Data Structures

1. Which one of the following is the tightest upper bound that represents the time complexity of inserting an object into a binary search tree of n nodes? (A) O(1) Answer: (C) Explanation: For skewed binary search tree on n nodes, the tightest upper bound to insert a node is O(n). 2. Which one of the following is the tightest upper bound that represents the number of swaps required to sort n numbers using selection sort? (A)O(log n) Answer: (B) Explanation: The maximum number of swaps that takes place in selection sort on n numbers is n 3. Consider the following operation along with Enqueue and Dequeue operations on queues, where k is global parameters MultiDequeue(Q) { m=k while (Q is not empty) and (m >0) { Dequeue(Q) m=m-1 } } What is the worst case time complexity of a sequence of n queue operations on an initially empty queue? (A) (n) Answer: (C) 4. The preorder traversal sequence of a binary search tree is 30, 20, 10, 15, 25, 23, 39, 35, 42. Which one of the following is the postorder traversal sequence of the same tree? (A) 10,20,15,23,25,35,42,39,30 (C) 15,20,10,23,25,42,35,39,30 (B) 15,10,25,23,20,42,35,39,30 (D) 15,10,23,25,20,35,42,39,30
5

(B) O(log n)

(C) O(n)

(GATE 2013)

(B) O(n)

(D) O(n2)

(GATE 2013)

(B) (n+k)

(C) (nk)

(D) (n2)

(GATE 2013)

## Explanation: Preorder : 30,20,10,15,25,23,39,35,42 Inorder :10,15,20,23,25,30,35,39,42

5. What is the return value of f p,pif the value of p is initialized to 5 before the call? Note that the first parameter is passed by reference, whereas the second parameter is passed by value.

## int f(int&x,int c) { c=c-1; if (c==0) return 1; x=x+1; return f(x,c)*x; }

(A) 3024 Answer: (B) (B) 6561 (C) 55440 (D) 161051 (GATE 2013)

Explanation:

Common Data Questions 6 & 7: The procedure given below is required to find and replace certain characters inside an input character string supplied in array A. The characters to be replaced are supplied in array oldc, while their respective replacement characters are supplied in array newc. Array A has a fixed length of five characters, while arrays oldc and newc contain three characters each. However, the procedure is flawed

voidfind_and_replace( char *A, char *oldc, char *newc) { for (inti=0;i<5;i++) for (int j=0;j<3;j++) if (A[i]==oldc[j]) A[i]=newc[j]; }

## The procedure is tested with the following four test cases

7

(1) oldc= "abc ", newc= "dab" (2) oldc= " cde", newc= "bcd" (3) oldc= "bca", newc= "cda" (4) oldc= "abc ", newc= "bac "

6. The tester now tests the program on all input strings of length five consisting of characters a, b, c, d and e with duplicates allowed. If the tester carries out this testing with the four test cases given above, how many test cases will be able to capture the flaw? (A) Only one (B) Only two (C) Only three (D) All four Answer: (B) Explanation: Flaw in this given procedure is that one character of Array A can be replaced by more than one character of newc array, which should not be so.Test case (3) and (4) identifies this flaw as they are containing oldc and newc array characters arranged in specific manner. Following string can reflect flaw, if tested by test case (3). (GATE 2013)

Likewise single character b in A is replaced by c and then by d. Same way test case (4) can also catch the flaw. 7. If array A is made to hold the string abcde, which of the above four test cases will be successful in exposing the flaw in this procedure? (A) None Answer: (C) Explanation: Now for string abcde in array A, both test case (3) and (4) will be successful in finding the flaw, as explained in above question. 8. What will be output of the following program?
8

(B) 2 only

## (C) 3 and 4 only

(D) 4 only

(GATE 2013)

char inChar=A;
switch(inChar) { case A: print(Choice A\n); case B: case C: printf(Choice B); case D: case E: default: printf(No Choice); }

(A) No Choice (B) Choice A (C) Choice A Choice B No Choice (D) Program gives no output as it is erroneous Answer: (C) Explanation:-Since there is no break statement, the program executes all the subsequent case statements after printing choice A.
9. Supposeacircularqueueofcapacity(n1)elementsisimplementedwithan arrayofnelements.Assumethattheinsertionanddeletionoperationsarecarriedoutusi ngREARandFRONTasarrayindexvariables,respectively.Initially,REAR=FRONT=0.Thecond itionstodetectqueuefullandqueueemptyare (A)full:(REAR+1)modn==FRONT empty:REAR==FRONT (B)full:(REAR+1)mod n==FRONT empty:(FRONT+1)modn==REAR

(GATE 2012)

## (C)full:REAR==FRONT(D)full:(FRONT+1)mod n==REAR empty:(REAR+1)modn==FRONTempty:REAR==FRONT (GATE 2012)

Answer:(A) Explanation:Thecounterexamplefortheconditionfull:REAR=FRONTis InitiallywhentheQueueisemptyREAR=FRONT=0bywhichtheabovefullcondition issatisfiedwhichisfalse Thecounterexamplefortheconditionfull:(FRONT+1)modn=REARis InitiallywhentheQueueisemptyREAR=FRONT=0andletn=3,soafterinsertingone elementREAR=1andFRONT=0,atthispointtheconditionfullaboveissatisfied,buts tillthereisplacefor onemoreelementinQueue,sothisconditionisalsofalse Thecounterexamplefortheconditionempty:(REAR+1)modn=FRONTis InitiallywhentheQueueisemptyREAR=FRONT=0andletn=2,soafterinsertingone elementREAR=1andFRONT=0,atthispointtheconditionemptyaboveissatisfied,b utthequeueofcapacityn-1isfullhere 9

## Thecounterexamplefortheconditionempty:(FRONT+1)modn=REARis InitiallywhentheQueueisemptyREAR=FRONT=0andletn=2,soafterinsertingone elementREAR=1andFRONT=0,atthispointtheconditionemptyaboveissatisfied,b utthequeueofcapacityn-1isfullhere

COMMON DATA QUESTIONS 10 & 11 Consider the following C program int a, b, c = 0; voidprtFun (void); int main () { staticint a = 1; /* line 1 */ prtFun(); a += 1; prtFun(); printf ( "\n %d %d " , a, b) ; } voidprtFun (void) { staticint a = 2; /* line 2 */ int b = 1; a += ++b; printf (" \n %d %d " , a, b); }
10.What output will be generated by the given code segment? (A) 3 1 (B) 4 2 (c) 4 2 (D) 3 1 41 61 62 52 42 61 20 52 Answer (C)

(2012)

Explanation: a and b are global variable. prtFun() also has a and b as local variables. The local variables hide the globals (See Scope rules in C). When prtFun() is called first time, the local b becomes 2 and local a becomes 4. When prtFun() is called second time, same instance of local static a is used and a new instance of b is created because a is static and b is non -static. So b becomes 2 again and a becomes 6. main() also has its own local static variable named a that hides the global a in main. The printf() statement in main() accesses the local a and prints its value. The same printf() statement accesses the global b as there is no local variable named b in main. Also, the defaut value of static and global int variables is 0. That is why the printf statement in main() prints 0 as value of b.

10

11.What output will be generated by the given code d\segment if: (GATE 2012) Line 1 is replaced by auto int a = 1; Line 2 is replaced by register int a = 2; (A) 3 1 (B) 4 2 (C) 4 2 (D) 4 2 41 61 62 42 42 61 20 20 Answer (D) Explanation: If we replace line 1 by auto int a = 1; and line 2 by register int a = 2;, then a becomes non-static in prtFun(). The output of first prtFun() remains same. But, the output of second prtFun() call is changed as a new instance of a is created in second call. So 4 2 is printed again. Finally, the printf() in main will print 2 0. Making a a register variable wont change anything in output. 12. What does the following fragment of C-program print? char c[] = "GATE2011"; char *p =c; printf("%s", p + p[3] - p[1]) ; (A) GATE2011 (B) E2011 (C) 2011 (D) 011 Answer: (C) Explanation: See comments for explanation. char c[] = "GATE2011"; // p now has the base address string "GATE2011" char *p =c; // p[3] is 'E' and p[1] is 'A'. // p[3] - p[1] = ASCII value of 'E' - ASCII value of 'A' = 4 // So the expression p + p[3] - p[1] becomes p + 4 which is // base address of string "2011" printf("%s", p + p[3] - p[1]) ; 13. A max-heap is a heap where the value of each parent is greater than or equal to the value of its children. Which of the following is a max-heap? (GATE 2011) (GATE 2011)

11

## Answer: - (B) Explanation: - Heap is a complete binary tree

COMMON DATA QUESTIONS 14 & 15 Consider the following recursive C function that takes two arguments (2011) unsignedint foo(unsigned int n, unsigned int r) { if (n > 0) return (n%r + foo (n/r, r )); else return 0; } 14. What is the return value of the function foo when it is called as foo(513, 2)? (A) 9 (B) 8 (C) 5 (D) 2 (GATE 2011)

Explanation: foo(513, 2) will return 1 + foo(256, 2). All subsequent recursive calls (including foo(256, 2)) will return 0 + foo(n/2, 2) except the last call foo(1, 2) . The last call foo(1, 2) returns 1. So, the value returned by foo(513, 2) is 1 + 0 + 0. + 0 + 1. The function foo(n, 2) basically returns sum of bits (or count of set bits) in the number n.

12

15. What is the return value of the function foo when it is called as foo(345, 10) ? (GATE 2011) (A) 345 (B) 12 (C) 5 (D) 3 Answer: (B) Explanation: The call foo(345, 10) returns sum of decimal digits (because r is 10) in the number n. Sum of digits for 345 is 3 + 4 + 5 = 12.

## 16. WhatisthevalueprintedbythefollowingCprogram? #include<stdio.h> intf(int*a,intn)

(GATE 2010)

13

{ if(n<=0)return0; elseif(*a% 2==0)return*a+ f(a+1,n-1); elsereturn*a-f(a+1,n-1); } intmain() { inta[]={12,7,13,4,11,6}; printf("%d",f(a,6)); return0; } 1)-9 Answer (C) Explanation: f() is a recursive function which adds f(a+1, n-1) to *a if *a is even. If *a is odd then f() subtracts f(a+1, n-1) from *a. See below recursion tree for execution of f(a, 6). . f(add(12), 6) /*Since 12 is first element. a contains address of 12 */ | | 12 + f(add(7), 5) /* Since 7 is the next element, a+1 contains address of 7 */ | | 7 - f(add(13), 4) | | 13 - f(add(4), 3) | | 4 + f(add(11), 2) | | 11 - f(add(6), 1) | | 6+0 So, the final returned value is 12 + (7 (13 (4 + (11 (6 + 0))))) = 15 2)5 3)15 4)19

14

15

p->next should below head node. sop->next=head Now the head node is p. So head = p. Hence (D) is correct option. 18. ThecyclomaticcomplexityofeachofthemodulesAandBshownbelowis10.Whatisthe
cyclomaticcomplexityofthesequentialintegrationshownontherighthandside? (GATE 2010)

1)19

2)21

3)20

4)10

Answer: (1) Explanation: Cyclomatic complexity is defined as the no. of independent paths form begin to exit in a module. If some dependent sub modules are there in the module then the individual cyclomatic complexities are added & overall sum is reduced by 1. Here CC(complete) = CC(A) + CC(B) 1 So 10+10-1=19 Hence (1) is correct option. 19. What does the following program print? (GATE 2010) #include<stdio.h> void f(int *p, int *q) { p = q; *p = 2;} inti = 0, j = 1; int main() { f(&i, &j); printf("%d %d \n", i, j); getchar(); return 0; } (A) 2 2 (B) 2 1 (C) 0 1 (D) 0 2 Answer: (D)
16

Explanation: See below f() with comments for explanation. /* p points to i and q points to j */ void f(int *p, int *q) { p = q; /* p also points to j now */ *p = 2; /* Value of j is changed to 2 now */ } 20.The following program is to be tested for statement coverage : (GATE 2010) begin if(a==b){S1;exit} else if(c==d){S2;} else {S3;exit;} S4; end The test cases T1, T2, T3, and T4 given below are expressed in terms of the properties satisfied by the values of variables a_b_cand d. The exact values are not given. T1: a,b,c and d are equal T2: a,b,c and d are all distinct T3: a=b and c!=d T4: a!=b and c=d Which of the test suites given below ensures coverage of statements S1, S2, S3 and S4? A) T1, T2, T3 B) T2, T4 C) T3, T4 D) T1, T2, T4 Answer: (D) Explanation: The following test cases covers statements. T1: all are equal S1 executed and then so no other execution. T2: all are distinct Only S3 executed T3: a=b & c!=d Only S1 executed T4: a!=b & c=d Only S2,S4only So to have all statements the option should be either T1,T2,T4or T2,T3,T4 Option (D) is T1,T2,T4 Hence (D) is correct option. Statement for Linked Answer Questions 21 & 22 (GATE 2010)
17

A has table of length 10 uses open addressing with hash function h(k)=k mod 10, and linear probing. After inserting 6 values into an empty has table, the table is as shown below.
0 1 2 3 4 5 6 7 8 9 42 23 34 52 46 33

21. Which one oft he following choices gives a possible order in which the key values could have been inserted in the table ? (A) 46, 42, 34, 52, 23, 33 (B) 34, 42, 23, 52, 33, 46 (C) 46, 34, 42, 23, 52, 33 (D) 42, 46, 33, 23, 34, 52 Answer: (C) Explanation: Here for hashing Linear probing is used, i.e. it finds the hash key value through hash function and maps the key on particular position In Hash table. In case of key has same hash address then it will find the next address then it will find the next empty position in the Has Table. Here we check all options: (A) Here 42 will be inserted at the 2nd position in the array next 52, also has same hash address 2. But it already occupied so it will search for the next free place which is 3rd position. So here 52 is misplaced and it is not possible key values. (B) Here 46 is misplaced so it is not possible value. (C) This is same as given hash table. So correct order is 46, 34, 42, 23, 52, 33 Hence (C) is correct option. 22. How many different insertion sequences of the key values using the same hash function and linear probing will result in the hash table shown above ? (A) 10 (B) 20 (C) 30 (D) 40 Answer: (C) Explanation: Here the given order of insertion is 46, 34, 42, 23, 52, 33 Here 42, 23, 34, 46 are inserted direct using hash function" But to insert 52 we have 6 vacant places." After insertion of 52 at any of the 6 places, we have 5 places"remaining for 33. So total combination. 6 * 5 = 30 possible ways Hence (C) is correct option.
18

## 23.Whatisthenumberofswapsrequiredtosortnelements usingselectionsort,intheworst case?

(GATE 2009) A)(n) C) (n2 ) Answer: (C) B)(nlogn) D) (n2logn)

24. Consider the program below: #include<stdio.h> int fun(int n, int *f_p){ intt,f; if (n<=1){ *f_p=1 return 1; } t=fun(n-1,f_p); f=t+*f_p; *f_p=t; return f; } int main () { int x=15; printf(%d\n, fun(5,&x)); return 0; } The value printed is: A) 6 B) 8 C) 14 D) 15 Answer: B Explanation:

(GATE 2009)

Here the table column I, II, & III are during the forward calls of the recursive function fun &The part after arrow in column III is updated value during return calls & column IV & V are the returned values.
19

In the end 8 is returned so only this will be printed Hence (B) is correct option. 25. What is the maximum height of any AVL-tree with 7 nodes ? Assume that the height of a tree with a single node is 0. (GATE 2009) (A) 2 (B) 3 (C) 4 (D) 5 Answer: (B)

Explanation: AVL tree is a partially balanced tree with the weights assigned to thenodes can be only 1,0 or 1. This weight is assigned on the basis of difference of the no. of children in the left subtree& right subtree. If some other weight is there then we rotate the tree to balance it.

In this tree the height is 3 and it is Also AVL balanced so maximum height will be 3 Hence (B) is correct option. Statement for Linked Answer Question 26 & 27 (GATE 2009) Consider a binary max-heap implemented using an array 26.Which one of the follow9ng array represents a binary max-heap? (A) {25, 12, 16, 13, 10, 8, 14} (B) {25, 14, 13, 16, 10, 8, 12} (C) {25, 14, 16, 13, 10, 8, 12} (D) {25, 14, 12, 13, 10, 8, 16} Answer: (C) Explanation: If the value presented at any node is greater then all its children then the tree is called the max heap. Here we need to draw heap for all options

20

Hence (C) is correct option. 27. What is the content of the array after two delete operations on the correct answer to the previous question? (GATE 2009) (A) {14, 13, 12, 10, 8} (B) {14, 12, 13, 8, 10} (C) {14, 13, 8, 12, 10} (D) {14, 13, 12, 8, 10} Answer: (D) Explanation:

21

28. Which combination of the integer variables x,y, and z makes the variable a get the value 4 in the following expression? (GATE 2008) a = (x >y)?((x>z)?x:z): ((y >z)?y:z) (A) x= 3,y = 4,z = 2 (C) x= 6,y = 3,z = 5 (B) x = 6,y = 5,z = 3 (D) x = 5,y = 4,z = 5

Answer: (A) Explanation: a = (x >y)?((x>z)?x:z): ((y >z)?y:z) Expr 1?expr 2 : expr 3 ; Here Expr 1 is a comparison expression whose result may be true or false. If true returned the expr 2 is selected as choice otherwise expr3. Here we want 4 to be printed which is only in option (A) & (D) for y = 4 to be printed. x >y should be false since y is in true part so this expr should be true. So both the conditions are true in option (A) only so correct. We can check. x=3y=4z=2 a = (x >y)?((x >z)?x:z) ((y >z)?y:z) First we can check 3 >2 ?3 : 2 thus 3 is selected Then 4 >2 ?4 : 2 here 4 is selected Hence a = 3 > 4?3:4 = 4 Hence (A) is correct option. 30. What is printed by the following C program? int f(int x, int *py, int **ppz) { int y, z; **ppz += 1; z = **ppz; (GATE 2008)

22

*py += 2; y = *py; x += 3; return x + y + z; } void main() { int c, *b, **a; c = 4; b = &c; a = &b; printf( "%d", f(c,b,a)); getchar(); } (A) 18 (B) 19 (C) 21 (D) 22 Answer :(B) Explanation: /* Explanation for the answer */ /*below line changes value of c to 5. Note that x remains unaffected by this change as x is a copy of c and address of x is different from c*/ **ppz += 1 /* z is changed to 5*/ z = **ppz; /* changes c to 7, x is not changed */ *py += 2; /* y is changed to 7*/ y = *py; /* x is incremented by 3 */ x += 3; /* return 7 + 7 + 5*/ return x + y + z;

23

31. Choose the correct option to fill ?1 and ?2 so that the program below prints an input string in reverse order. Assume that the input string is terminated by a newline character. (GATE 2008) void reverse(void) { int c; if (?1) reverse() ; ?2 } main() { printf ("Enter Text ") ; printf ("\n") ; reverse(); printf ("\n") ; } (A) ?1 is (getchar() != \n) ?2 is getchar(c); (B) ?1 is (c = getchar() ) != \n) ?2 is getchar(c); (C) ?1 is (c != \n) ?2 is putchar(c); (D) ?1 is ((c = getchar()) != \n) ?2 is putchar(c); Answer: (D) Explanation: getchar() is used to get the input character from the user and putchar() to print the entered character, but before printing reverse is called again and again until \n is entered. When \n is entered the functions from the function stack run putchar() statements one by one. Therefore, last entered character is printed first. You can try running below program void reverse(void); /* function prototype */ void reverse(void) { int c; if (((c = getchar()) != '\n')) reverse(); putchar(c); } main() { printf ("Enter Text ") ; printf ("\n") ;
24

reverse(); printf ("\n") ; getchar(); } 32. The following postfix expression with single digit operands in evaluated using a stack 823^/23*+ 51* . Note that ^ is the exponentiation operator. The top two elements of the stack after the first* is evaluated are (GATE 2007) (A) 6, 1 (B) 5, 7 (C) 3, 2 (D) 1, 5 Answer: (B) Explanation: Given postfix expression is 823^/23*+ 51* Scanning the string from left to right we push all the digits,& we get any operator we evaluate the operation between top 2 elements poped from stack. Then the result is pushed again into stack.

Stack contain 5, 7 Hence (B) is correct option 33.Consider the following C-function in which a[n] and b[n] are two sorted integer arrays and c[n+m] be another integer array. void xyz (int a[],int b[],int c[]){ inti, j, k; i=j=k=0; while((i<n))&&(j<m) if (a[i]<b[j]) c[k++]=a[i++];
25

(GATE 2006)

else c[k++]=b[j++]; } Which of the following condition (s) hold (s) after the termination of the while loop ? I II j<m, k=n+j-1, and a [n-1]<b[j] if i=n i<n, k=m+j-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) Answer: (C) Explanation: While loop will terminate i>= n &j >= m program is to merge a &b arrays into C . While loop terminates after merging then either (I) or (II) should hold but not both at the same time. (I) says j <m & (II) say j = m vice versa Hence (C) is correct option. 34.Consider the C code to swap two integers and these five statements: the code 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 referreing to integers stored in memory locations accessible to the process S4: implements the swap procedure correctly for some but not all valid input pointers
26

(GATE 2006)

S5: may add or subtract integers and pointers (A) S1 (B) S2 and S3 (C) S2 and S4 (D) S2 and S5 Answer: (C) Explanation: Here pointers are used without initialization also the address pointed by then may be out of segment of program, so segmentation. Fault may be there so. S2 correct. Here no compiler error S1 false. Correctly done swap procedure but not all valid import pointers so S4 also true. S2 &S4 are correct. Hence (C) is correct option. Common Data Questions 35 & 36 (GATE 2006) A 3-ary max heap os 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 form 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. 35.Which one of the following is a valid sequence of elements in an array representing 2-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 Answer: (D) Explanation:

27

Here in option (A), (B) and (C), value present at node is not greater then all its children. Hence (D) is correct option. 36.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, Q. 38. Which on of the following is the sequence of items in the array representing the resultant heap ? (GATE 2006) (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 Answer: (A) Explanation: Given heap is as follows

## To add 7, 2, 10, 4 we add the node at the end of array

28

We keep if at right place in the heap tree. Compare elements with its parent node. Since 10 > 6 and 7 >5, we interchange

## Since 10 >9, we interchange and we get

n/2=10/2=5 3 is at right position 4 is at right position Hence (A) is correct option. 37. What does the following C-statement declare? Int (*f) (int*)

(GATE 2005)

(A) A function that takes an integer pointer as argument and returns an integer (B) A function that takes an integer pointer as argument and returns an integer pointer (C) A pointer to a function that takes an integer pointer as argument an returns (D) A function that takes an integer pointer as argument returns a function pointer
29

Answer: (C) Explanation: Given statement int (*f) (int*) This is not the declaration of any function since the f has *(pointer symbol) before it. So f is a pointer to a function also the argument type is int *& the return type is int. So overall we can say that f is a pointer to a function that takes an integer pointer as argument and returns an integer. Hence (C) is correct option. 38.An Abstract Data type (ADT) is (A) same as an abstract class (B) a data type that cannot be instantiated (C) a data type for which only the operations defined on it can be used, but none else (D) all of the above Answer: (C) Explanation: Abstract Data type :- It is defined as a user defined data type, specified by keyword abstract & defines the variables & functions, these operations can only use the variables of this data type. So option (C) which says that Abstract data type for which only operations defined on it can be used is correct. Eg.stack data type Here operations defined are push & pop. So we can apply only these 2 operations on it. Hence (C) is correct option. 39.A common property of logic programming languages and functional languages is (A) both are procedural language (B) both are based oncalculus (C) both are declarative (D) all of the above Answer: (D)
30

(GATE 2005)

(GATE 2005)

Explanation: -calculus" It provides the semantics for computation with functions so that properties of functional computation can be studied. Both the languages require declaration before use of any object. Both are procedural So option (D) is correct. Both the languages are based on calculus, procedural & declarative Hence (D) is correct option. 40.Which of the following are essential features of an object-oriented programming languages? 1. Abstraction and encapsulation 2. Strictly-typedness 3. Type-safe property coupled with sub-type rule 4. Polymorphism in the presence of inheritance (A) 1 and 2 only (C) 1, 2 and 4 only Answer: (B) Explanation: Object oriented programming languages necessarily have features like Abstraction Encapsulation, inheritance with polymorphism. but OOPL are also strongly-typed since there are restrictions on how operations involving values having different data types can be intermixed. Eg.two integers can be divided but one integer & one string cant. Hence (B) is correct option. 41.A program P reads in 500 integers in the range (0, 100) representing the scores of 500 students. It then prints the frequency of each score above 50. What be the best way for P to store the frequencies? (A) An array of 50 numbers (B) An array of 100 numbers (C) An array of 500 numbers
31

(GATE 2005)

## (B) 1 and 4 only (D) 1, 3 and 4 only

(GATE 2005)

(D) A dynamically allocated array of 550 numbers Answer: (A) Explanation: Here the no. readable are range 0 to 100 but the output of the program is interested in scores above 50 so there are 50 values (51 to 100) in this range. So only an array 50 integers required as we get any no. we increment the value stored at index. Array [x 50] by 1. Hence (A ) is correct option. 42.Consider the following C-program (GATE 2005) double foo (double); /* Line 1*/ int main(){ doubleda_db; // input da db _foo(da); } double foo(double a){ returna; } The above code complied without any error or warning. If Line 1 is deleted, the above code will show (A) no compile warning or error (B) some complier-warning not leading to unitended results (C) Some complier-warning due to type-mismatch eventually leading to unitended results (D) Complier errors Answer: (C) Explanation: Here if line 1 which is prototype declaration of the function foo, in C compilation process this would give an compile warning , due to type-mismatch. Since then compiler wont know what is the return type of foo. So unintended results may occur. Hence (C) is correct option. 43.Postorder traversal of a given binary search tree, T produces the following sequence of keys10, 9, 23, 22, 27, 25, 15, 50, 95, 60, 40, 29 Which one of the following sequences of keys can be the result of an inorder traversal of the tree T? (GATE 2005)
32

(A) 9, 10, 15, 22, 23, 25, 27, 29, 40, 50, 60, 95 (B) 9, 10, 15, 22, 40, 50, 60, 95, 23, 25, 27, 29 (C) 29, 15, 9, 10, 25, 22, 23, 27, 40, 60, 50, 95 (D) 95, 50, 60, 40, 27, 23, 22, 25, 10, 0, 15, 29 Answer: (A) Explanation: When we are given any no elements & even any order (preorder or post order) & we need to calculate inorder, then inorder is simply sorted sequence of the elements. Here 9, 10, 15, 22, 23, 25, 27, 29, 40, 50, 60, 95 Hence (A) is correct option. 44.Assume that the operators +, -,# are left associative and ^ is right associative .The order of precedence (from highest to lowest) is ^,#, +, -. The postfix expression corresponding to the infix expression a + b#c - d ^ e ^ f is (GATE 2004)

(A) abc#+def ^^

(B) abc#+de^f^

## (C) ab+c#de^f^ Answer: (A) Explanation:

(D) +a#bc^^def

Given expression a + b)c d/e/f parenthesizing the expression as per given rules. = ((a + (b)c)) (d/(e/f))) = ((a + (bc))) (d/(ef/))) = ((abc)+) (def//)) = (abc)+def//) So option (A) is correct You can also solve using stack. Hence (A) is correct option. 45.Consider the following C program main () (GATE 2004)
33

{ int x, y, m, n; scanf(%d%d, &x,&y); /*Assume x>0 and y>0*/ m=x; n=y; while (m!=n) { if (m>n) m=mn; else n=nm; } printf(%d,n); } The program computers (A) x'y, using repeated subtraction (B) x mod y using repeated subtraction (C) the greatest common divisor of x and y (D) the least common multiple of x only Answer: (A) Explanation: Here if m >n then m = m n m <n then n = n m Let take X = 24 Y = 9 Then m = 24 n = 9 iteration m n 1 24 9 = 15 9 2 15 9 = 6 9 3 6 96=3 4 63=3 3 Here m = n so n returned Which is GCD (Greatest common divisor) of X &Y Hence (C) is correct option. 46.What does the following algorithm approximate ? (Assume m>1, E> 0). (GATE 2004) x=m; y=1; while (xy>E) { x=(x+y)/2; y=m/x; } print (x);
34

## (B) m2 (D) m1/3

Here we take let x = 16 Loop will stop when x y = 0 or >0 Iteration 1 X (16+1)/2=8 Y 16/8=2

2 3 Here X = Y

(8+2)/2=5 (5+3)/2=4

16/5=3 16/4=4

## Then take X. which is 4. (m)1/2 = 4 = (16)1/2 Hence (C) is correct option.

47.Choose the best matching between the programming styles in Group 1 and their characteristics in Group 2. (GATE 2004)

## Group-1 P. Functional Q. Logic R. Object-oriented S. Imperative

Group-2 1. Command-based, procedural 2. Imperative, abstract data types 3. Side-effect free, declarative, expression evaluation 4. Declarative, clausal representation, theorem proving

35

(A) P-2, Q-3, R-4, S-1 (C) P-3, Q-4, R-1, S-2 Answer: (D) Explanation:

(B) P-4, Q-3, R-2, S-1 (D) P-3, Q-4, R-2, S-1

p. Functional Programming is declarative in nature, involves expression evaluation, & side effect free. q Logic is also declarative but involves theorem proving. r. Object oriented is imperative statement based & have abstract (general) data types. s Imperative :- The programs are made giving commands & follows definite procedure & sequence. Hence (D) is correct option. 48)What is printed by the print statements in the program P1 assuming call by reference parameter passing ? (2001) Program P1( ) { _ _ 1__ _ _ __ ____1(*)_ _r___ x; _r___ y; } func1(x,y,z) { y=y+4 z=x+y+z; } (A) 10, 3 (B) 31, 3 (C) 27, 7 (D) None of the above

36

SOLUTION Since the function fun 1 doesnt return the values of x & y and x & y are not passed by reference. So in program P1( ) would print x = 10 & y = 3. So 10, 3 Hence (A) is correct option. 49)Consider the following three functions. (2001) [P1] int *g(void) { Int x=10; return (& x); } [P2] int *g(void) { int *px; *px=10; return px; } [P3] int *g(void) { int *px px=(int*)malloc (size of (int)); *px=10; return px; } Which of the above three functions are likely to cause problems with pointers ? (A) Only P3 (B) Only P1 and P3 (C) Only P1 and P2 (D) P1, P2 and P3

SOLUTION
37

P1 : Here the function is returning address of the variable x (& x ) but the return type is pointer to integer not address. So incorrect. P2 : *px = 0 directly assigned a value but still px doesnt point to any memory location, so memory initialization or allocation should be done before. So incorrect. P3: Correction made in P2, memory pre allocated, So correct. Hence (C) is correct option. 50)Consider the following program (2001) Program P2 Var n:int: procedure W (var x:int) begin X=X+1 Print x; end Procedure D Begin var n:int; n=3; W(n); End Begin \\begin P2 n=10; D; end If the language has dynamic scooping and parameters are passed by reference, what will be printed by the program ? (A) 10 (B) 11 (C) 3 (D) None of the above

38

SOLUTION n = 10 given but not passed to D. In D, n = 3 & W(n) increments by 1. So n = n + 1 = 4. Hence (D) is correct option. 51)The results returned by function under value-result and reference parameter passing conventions. (2002) (A) Do not differ (B) Differ in the presence of loops (C) Differ in all cases (D) May differ in the presence of exception SOLUTION The results returned by function under value & reference parameter passing may differ in presence of loops. Hence (B) is correct option. 52)Consider the following declaration of a two-dimensional array in C. (2002) Char a[100][100] Assuming that the main memory is byte-addressable and that array is stored starting form memory address 0, the address of a [40] [50] is (A) 4040 (B) 4050 (C) 5040 (D) 5050 SOLUTION Char a[100] [100] 1 char require 1 byte Total required 10000 bytes. Memory format is byte addressable A[0] . . . A[50][0] .
39

a[0][50]

a[0][99] . . .

a[40][50]

. . A[99][0] a[99][99]

100 bytes per row. I.e 40#100 = 4000 1 byte per column I. e. 50#1 = 50 Total 4050 Hence (B) is correct option. 53) Consider the following C function.(2003) fl oat f(fl oat x, int y){ fl oat p, s; int i; for (s=1, p=1, i=1, i<y; i++) { p)=x/i; s+=p; } return s; } For large values of y, the return value of the function f best approximates (A) xy (B) ex (C) In(1 + x) (D) xx SOLUTION The function is rewritten as s = _;p = _; for _i = _;i _ y;i ++_ { p = p)x/i; s = s + p; } Here initial value of s increments every time with a factor of p)x/i Initially s = _ _ p = _
40

## Loop counter (i)

1+x

x)x/2 : 1 = x2/2 : 1

1 + x + x2/2

x2/2)x/3 = x3/3 : 2 : 1

1 + x + x2/2! + x3/3!

## 1 + x + x2/2! + x3/3! + x4/4!

Thus it can be checked for every value. Here the assumption is that the value of y is very large so y " 3 So the series 1 + x + x2/2! + x3/3!................3 will have infinite terms & from our previous knowledge we know that this 3 series is expansion of ex (exponential series) so. 1 + x + x2/2! + x3/3!...........3 = ex Hence (B) is correct option. 54)Assume the following C variable declaration (2003) int)A[10], B[10][10]; Of the following expressions (1) A[2] (2) A[2][3] (3) B[1]
41

(4) B[2][3] Which will not give compile-time errors if used as left hand sides of assignment statements in a C program ? (A) 1, 2, and 4, only (B) 2, 3, and 4, only (C) 2 and 4 only (D) 4 only

SOLUTION We have int )* which is an array of 10 integer value pointer whereas B[10] [10] is an array which stores 10#10 = 100 integers So let us try to solve it eliminating way. " Option 3 B[1] cant be at the left side since it is 2D array so cant use single index. We need not necessarily specify the size of first dimension for B[][3] " Option 4 B[2][3] is assignment to the array B value so possible. " Option 1 A [2] is also possible to assign some address os integer value " Option 2 this is some what tricky. Here A[2][3] becomes a 2D array if integer where A [2] means the 2nd integer in this array and A[2][3]o means 3rd integer in this row. eg. A[2] [3] = 5 means that at second row the third integer value is 5. Hence (*) Is correct option.

55)Let T(n) be the number of different binary search trees on n distinct elements. (2003) Then T[n] T(k 1)T(x) k1 n = =/ , where x is (A) n k + 1 (B) n k (C) n k 1 (D) n k 2

SOLUTION

42

Binary search tree has a root node & its 2 subtrees. So for every node other than the leaves, all the elements smaller than the node are its left subtree & all the nodes which have value equal to or greater than that node are at right subtree. Here the given expression. T(n) T(k 1)T(X) K n 1 = =/ Figure n(B) = no. of nodes in left subtree n(C) " no. of nodes in right subtree T(n) = n(B) + n(C) + 1 T(n) T(X)T(k 1) K n 1 = =/ Expanding forT (k 1) we get T(n) T(X) [T(0) T(1) T(2) .....T(n 1)] K n 1 =:++ = 144444444424444444443 / no. of nodes in left subtree denoted by K Total nodes = n So remaining node n (k 1) i.e nodes in the right subtree. So = n k + 1 So overall we can say that the no. of different BSTs on n different
43

## elements. T(n) T(n k 1)T(k 1) n k 1 = + =/ Hence ( ) is correct option.

56) A data structure is required for storing a set of integers such that each of the following operations can be done is (logn) time, where n is the number of elements in the set. (2003) 1. Delection of the smallest element. 2. Insertion of an element if it is not already present in the set. Which of the following data structures can be used for this purpose ? (A) A heap can be used but not a balanced binary search tree (B) A balanced binary search tree can be used but not a heap (C) Both balanced binary search tree and heap can be used (D) Neither balanced binary search tree nor heap can be used SOLUTION Both the tasks can be performed by both the data structures but heap is a data structure where to perform these function every element has to be checked so O(n) complexity. But the balance binary search tree is efficient data structure since at every decision it selects one of its subtree to no. of elements to be checked are reduced by a factor of 1/2 every time. n/2! = x x = logn Hence (B) is correct option. 57) Let S be a stack of size n $1. Starting with the empty stack, suppose we push the first n natural numbers in sequence, and then perform n pop operations. Assume that Push and Pop operation take X seconds each , and Y seconds elapse between the end of the one such stack operation and the start of the next operation. For m$ 1, define the stack-life of mcs the time
44

elapsed from the end or Push (m) to the start of the pop operation that removes m from S . The average stack-life of an element of this stack is (2003) (A) n(X + Y) (B) 3Y + 2X (C) n(X + Y) X (D) Y + 2X

SOLUTION Here each of PURSH & POP operation take X seconds & Y seconds are elapsed between two consecutive stack operations. m is the life time of element in stack. So m X is time for push. m X is time for pop. m Y is time for intermediate So total m(2X + Y) Average stack life ( ) m = m 2X + Y = 2X + Y = Y + 2X Hence (D) is correct option. 58) Consider the C program shown below. #include <stdio.h> #defi ne print(x)printf(%d,x) int x; void Q (int z){ z+=x; print(z); } void p (int)y){ int x=)y+2; Page 13 www.gatehelp.com CS Topicwise 2001-2010 Programming & Data
45

Structure Q(x);)y=x-1; print(x); } main (void){ x=5; p(&x); print(x); } The output of this program is (A) 12 7 6 (B) 22 12 11 (C) 14 6 6 (D) 7 6 6 SOLUTION Figure Here X is the global variable so still 5. Figure Here this is global X whose xy has been changed to 6 so 6 is printed 12 66 Hence (A) is correct option. First x=5 Then by function p(&x) X =5+2=7 Then by function Q(x) z =z+x =7+5=12 Here x is global variable so still it is 5. Return to function p(&x) Y =7-1=6 print x =7 return to main Print x =6 Here this is global x whose *y ahs been changed to 6 so 6 is printed. 59) Consider the function - defined below.(2003) struct item { int data; struct item)next; };
46

int f (struct item )p){ return ((p==NULL)||(p>next==NULL)|| ((p>data<=p>next>data)&& f(p>next))); } For a given linked list p, the function f return 1 if and only if (A) the list is empty or has exactly one element (B) the elements in the list are sorted in non-decreasing order of data value (C) the elements in the list are sorted in non-increasing order of data value (D) not all elements in the list have the same data value SOLUTION Here the return 1 any 1 of the following should be correct. (A) P == NULL i.e the list is empty (ends) (B) P " next = NULL i.e have one element. (C) P " data <= p " next " data i.e the element is smaller than its next element also. This is true for whole list. Since &&f(p "next) is also there. So overall it gives that the elements should be in sorted order. Hence (B) is correct option. 60) The goal of structured programming is to (2004) (A) have well indented programs (B) be able to infer the flow of control from the compiled code (C) be able to infer the flow of control form the program text (D) avoid the use of GOTO statements SOLUTION Structured programming :- It is way of programming using the sub structure method, i.e splitting the programs into sub sections. Structured programming prevents confusing transfer of control of avoiding the use of GOTO statements. Hence (D) is correct option. 61) Consider the following C function (2004) void swap (int a, int b) {int temp;
47

temp =a; a =b; b =temp; } In the order to exchange the values of two variables x and y . (A) call swap (x,y) (B) call swap (&x,&y) (C) swap (x,y) cannot be used as it does not return any value (D) swap (x,y) cannot be used as the parameters are passed by value SOLUTION Here the function takes the arguments by value. " Option (A) sends parameter by value but only the local variable a & b will be exchanged but not the actual variables x & y so incorrect. " Option (B) is incorrect sending address of x & y . " Option (C) swap (x,y) is usable there is no need to return. " Option (D) is the opposite statement of option (A), it says that the values are passed by value so wont swap so the option is correct. Hence (D) is correct option. 62) A single array A [1........MAXSIZE] is used to implement two stacks. The two stacks grow from opposite ends of the array. Variables top 1 and top 2 (top 1<top 2) point to the location of the topmost element in each of the stacks. If the space is to be used efficiently, the condition for stack full is (A) (top 1=MAXSIZE/2) and (top 2=MAXSIZE/.2+1) (B) top 1+top2=MAXSIZE (C) (top 1=MAXSIZE/2) or (top2=MAXSIZE) (D) top 1=top 21 SOLUTION Let take maxsize =10 1 2 3 4 5 6 7 8 9 10

48

Here the stack will be fuel if both top 1 & top 2 are at the adjacent index values i.e. their difference is 1. So top 1 = top 2 1 Here (D) is correct option. 63) The best data structure to check whether an arithmetic expression has balanced parenthesis is a (A) queue (B) stack (C) tree (D) list SOLUTION Balanced parenthesis in an equation are such that the no. of opening and closing parenthesis and in correct order should be there. We can check balancing using stack. When we get any opening parenthesis then we push that in the stack & if we get a closing one then we pop the stack. After the complete scanning of input string if stack is found empty then the arithmetic expression is balanced. Hence (B) is correct option. 63) Consider the following C function int f(int n) {static int i=1; if (n>=5) return n; n=n+i; i++; return f(n); } The value returned by f(1) is (A) 5 (B) 6 (C) 7
49

(D) 8 SOLUTION Here i is an static variable, so if it is once initialized it cant be initialized again during its scope n is incremented by 1 & f(n) is called then. The final return is when n>=5 i.e. n returned then Step (1) 1 (2) (3) 2 (4) (5) 3 (6) (7) 4 Call 1 1+1=2 2 2+2=4 4 4+3=7 7 n 1 2 2 3 3 4 4 true return n = 7 false n < 5 false n < 5 i condition false n < 5

So return value is 7. Hence (C) is correct option. 64) Consider the following program fragment for reversing the digits in a given integer to obtain a new integer. Let ....... n d d d. = 1 2 m int n, rev; rev=0; while(n>0){ rev=rev)10+n%10; n=n/10; } The loop invariant condition at the end of the ith iteration is (A) n = d1d2......dmi and rev = dmdm1......dmi+1 (B) n = dmi+1.....dm1dm or rev = dmi .....d2d1 (C) n =Y rev (D) n = d1d2....dm or rev = dm......d2d1

SOLUTION Here after every iteration one digit is reduced from n since n = n/10 so unit place is removed.

50

This unit place is then added into the previous reverse sum (rev) after multiplying rev by 10. So 1 digit is incremented every iteration. So at the ith iteration n should have m i digits d1d2.....dmi & rev have dmdm1..........dmi+1 i 1 2 So on. Hence (A) is correct option. 65)Consider the following C program segment. (2003) char p[20]; char)s= string; int length=strlen(s); for (i=0;i<length; i++) p[i]=s[length_i]; printf(% s, p); The output of the program is (A) gnirts (B) string (C) gnirt (D) no output is printed SOLUTION In line 8 p[i]=S[length-i]; Here p is a character pointer variable so we cant assign the value of a pointer variable into character variable so no output is printed. The block of code shown here is actually outputs the reversal of string given in S. Which is a char type pointer. But the mistake during the loop execution is done. The statement is accessing the s[length - i] & loop starts from 0 When i = 0, s[length - 0] & s[length]. So this value for string is always P will start with null pointer. So the string p will start with null pointers and nothing will be printed. Hence (D) is correct option. n rev d1d2....dm1 dm d1d2......dm2 dmdm1

51

66) A circularly linked list is used to represent a Queue. A single variable p is used to access the Queue. To which node should p point such that both the operations enQueue and deQueue can be performed in constant time ? (2003) (A) rear node (B) front node (C) not possible with a single pointer (D) node next to front SOLUTION: Here due to circular connection the rear & front are connected. Here if we point P to rear the P "next point to front node & P " data will point to rear value while inserting at rear following sequence of operations done. These operation done is 0(1) time So constant complexity. Hence (A) is correct option. 67) Suppose the numbers 7, 5, 1, 8, 3, 6, 0, 9, 4, 2 are inserted in that order into an initially empty binary search tree. The binary search tree uses the usual ordering on natural numbers. What is the inorder transversal sequence of the resultant tree ?(2003) (A) 7 5 1 0 3 2 4 6 8 9 (B) 0 2 4 3 1 6 5 9 8 7 (C) 0 1 2 3 4 5 6 7 8 9 (D) 9 8 6 4 2 3 0 1 5 7 SOLUTION We can solve it in shortcut that the first given element in 7, so we need to choose that particular option in which 7 is at the right place i.e. all the elements on its left should be smaller than it & all the elements on the right should be equal & greater than it. So this rule is followed in option C only. The method to make BST for given inputs is 7, 5, 1, 8, 3, 6, 0, 9, 4, 2.

52

To make in order of a binary search tree. (i) Start with the root node. (ii) Scan its left subtree, (iii) If the node in subtree has any left child then store the node in stack & repeat this step for its left child unit no. left child of any node. (iv) If leaf reached then print the node & pop the stack, print the poped value. (v) Check its right subtree & repeat step (III) for it. (vi) When stack empty then stop

53

So here inorder is 0 1 2 3 4 5 6 7 8 9. Actually a fact can be remembered that inorder traversal of a BST leads to a sorted sequence of elements. Hence (C) is correct option 67) Consider the following 2-3-4 tree (i.e., B-tree with a minimum degree of two in which each data item is a letter. The usual alphabetical ordering of letters is used in constructing the tree.(2003) What is the result of inserting G in the below tree ?

## (D) None of the above SOLUTION

54

2-3-4 B-tree means the min degree of a node is two & it can be max 4 So maximum of 3 elements can be there in a node.

Here in this node the no. of element >3. So we need a split or rotation. Since the adjacent child has no. of element n 2 2 # = 4 = 2 so we apply a right rotation. So here.

Hence (C) is correct option. 68) The following numbers are inserted into an empty binary search tree in the given order: 10, 1, 3, 5, 15, 12, 16. What is the height of the binary search tree (tree height is the maximum distance of a leaf node from the root) (2003) (A) 2 (B) 3 (C) 4 (D) 6 SOLUTION
55

## Given are 10, 1, 3, 5, 15, 12, 16

The height of the leaf node (5) is high 3. Hence (B) is correct option.

56

## DESIGN AND ANALYSIS OF ALGORITHMS

1.Consider a linked list of n elements. What is the time taken to insert an element after an element pointed by some pointer? A. O (1) Answer A 2.An algorithm is made up of two independent time complexities f (n) and g (n). Then the complexities of the algorithm is in the order of A. f(n) x g(n) B. Max ( f(n),g(n)) Answer B 3.Two main measures for the efficiency of an algorithm are A. Processor and memory B. Complexity and capacity C. Time and space D. Data and space Answer C 4.The total number of comparisons in a bubble sort is A. 0(log n) B. 0(n log n) C. 0(n) D. None of the above Answer B 5.Time complexities of three algorithms are given. Which should execute the slowest for large values of N? A. ( 1 2 ) O N B. O(N) Answer B 6.The upper bound of computing time of m coloring decision problem is A. O(nm) Answer C 7.The space factor when determining the efficiency of algorithm is measured by A. Counting the maximum memory needed by the algorithm B. Counting the minimum memory needed by the algorithm C. Counting the average memory needed by the algorithm D. Counting the maximum disk space needed by the algorithm 57 B .O(nm) C. O(nmn) D. O(nmmn) C. O(log N) D. None of these C. Min (f(n),g(n)) D. f(n) + g(n) B. O (n) C. O (log2 n) D .O (n log2 n)

Answer A 8.If the address of A[1][1] and A[2][1] are 1000 and 1010 respectively and each element occupies 2 bytes then the array has been stored in _________ order. A. row major Answer A 9.The time factor when determining the efficiency of algorithm is measured by A. Counting microseconds B. Counting the number of key operations C. Counting the number of statements D. Counting the kilobytes of algorithm Answer B 10.The Worst case occur in linear search algorithm when A. Item is somewhere in the middle of the array B. Item is not in the array at all C. Item is the last element in the array D. Item is the last element in the array or is not there at all Answer D 11.A list of n strings, each of length n, is sorted into lexicographic order using the merge-sort algorithm. The worst case running time of this computation is A. O (n log n) B. O (n2 log n) C. O (n2 + log n) Answer A 12.Which of the following case does not exist in complexity theory A. Best case Answer D 13.The minimum number of multiplications and additions required to evaluate the polynomial P = 4x3+3x2-15x+45 is A. 6 & 3 Answer C 58 B. 4 & 2 C. 3 & 3 D. 8 & 3 B. Worst case C. Average case D. Null case D. O (n2) B. column major C. matix major D. none of these

14.The concept of order Big O is important because A. It can be used to decide the best algorithm that solves a given problem B. It determines the maximum size of a problem that can be solved in a given given amount of time C. It is the lower bound of the growth rate of algorithm D. Both A and B Answer A 15.The worst case running time to search for an element in a balanced binary search tree with n2n elements is A. T(nlogn) Answer C 16.Which of the following sorting algorithm is of divide-and-conquer type? A. Bubble sort B. Insertion sort Answer C 17.The quick sort algorithm exploit _________ design technique A. Greedy Answer C 18.The number of distinct simple graphs with up to three nodes are A. 15 Answer C 19.The number of unused pointers in a complete binary tree of depth 5 is A. 4 Answer C 20.A given connected graph G is a Euler graph , if and only if all vertices of G are of A. Same degree Answer B 21.What is the maximum number of nodes in a B-tree of order 10 of depth 3 (root at depth 0) ? A. 111 B.999 C. 9999 D. None of the above 59 B .Even degree C .Odd degree D. Different degree B. 8 C. 16 D. 32 B. 10 C. 7 D. 9 B. Dynamic programming C. Divide and Conquer D. Backtracking C. Quick sort D. All of above B. T(n2n) C. T(n) D. T(logn)

26.Tree A. Is a bipartite graph B. With n node contains n-1 edges C. Is a connected graph D. All of these
Answer D 27.If every node u in G is adjacent to every other node v in G, A graph is said to be A. Isolated B. Complete C. Finite D. Strongly Connected Answer B 28.Consider the following pseudo-code : If (A > B) and (C > D) then A=A+1 B=B+1 Endif The cyclomatic complexity of the pseudo-code is A. 2 Answer D 29.Leaves of which of the following trees are at the same level ? 60 B. 3 C. 4 D. 5

## A. Binary tree B. B-tree Answer B

C. AVL-tree

D. Expression tree

30.The Inorder traversal of the tree will yield a sorted listing of elements of tree in A. Binary tree B. Binary search tree Answer B 31.One can make an exact replica of a Binary Search Tree by traversing it in A. Inorder Answer B 32.Let A be an adjacency matrix of a graph G. The th ij entry in the matrix K A , gives A. The number of paths of length K from vertex Vi to vertex Vj. B. Shortest path of K edges from vertex Vi to vertex Vj. C. Length of a Eulerian path from vertex Vi to vertex Vj. D. Length of a Hamiltonian cycle from vertex Vi to vertex Vj. Answer B 33. A graph in which all nodes are of equal degree is called A. Multi graph B. Non regular graph C. Regular graph D. Complete graph Answer C 34. The time complexity to build a heap of n elements is A. 0(1) Answer D 35. Given a binary tree whose inorder and preorder traversal are given by Inorder : EICFBGDJHK Preorder : BCEIFDGHJK The post order traversal of the above binary tree is A. IEFCGJKHDB Answer A 36. The running time of the following sorting algorithm depends on whether the partitioning is balanced or unbalanced 61 B. IEFCJGKHDB C. IEFCGKJHDB D. IEFCGJKDBH B. 0(lgn) C. 0(n) D. 0(nlgn) B. Preorder C. Postorder D. Any order C. Heaps D. None of the above

A. Insertion sort B. Selection sort C. Quick sort D. Merge sort Answer C 37. In worst case Quick Sort has order A. O (n log n) B. O (n2/2) Answer B 38. The sorting technique where array to be sorted is partitioned again and again in such a way that all elements less than or equal to partitioning element appear before it and those which are greater appear after it, is called A. Merge sort B. Quick sort Answer B 39. The best average behaviour is shown by A. Quick Sort B. Merge Sort C. Insertion Sort D. Heap Sort Answer A 40. Quick sort is also known as A. Merge sort B. Heap sort C. Bubble sort D. None of these Answer D 41. Assuming P ? NP, which of the following is TRUE? A. NP-complete = NP B. NP-completenP=theta C. NP-hard = NP D. P = NP-complete Answer B 42. If there is an NP complete language L whose complement is in NP ,then complement of any language in NP is in A. P Answer B 43. Both P and NP are closed under the operation of A. Union Answer D 44. If every node u in G is adjacent to every other node v in G, A graph is said to be B. Intersection C. Concatenation D. Kleene B. NP C. Both A and B D. None of these C. Selection sort D. None of these C. O (log n) D. O (n2/4)

A.

Isolated
62

## Complete Finite Strongly Connected

45. Which of the following sorting algorithms has the lowest worst case complexity?

A. B. C. D.

Merge sort Bubble sort Quick sort Selection sort of quicksort where the pivot is case complexity of sorting n (c) O(n2) (d) O(n!)

46. Randomized quicksort is an extension chosen randomly. What is the worst numbers using randomized quicksort?

(a) O(n)

## (b) O(n log n)

47. Level of any node of a tree is A. B. C. D. Height of its left subtree minus height of its right subtree Height of its right subtree minus height of its left subtree Its distance from the root None of these

48. The total number of comparisons in a bubble sort is A. 0(log n) B. 0(n log n) C. 0(n) D. None of the above 49. Time complexities of three algorithms are given. Which should execute the slowest for large values of N? A. ( 1 2 ) O N B. O(N) C. O(log N) D. None of these 50. The quick sort algorithm exploit _________ design technique
63

A. B. C. D.

## Greedy Dynamic programming Divide and Conquer Backtracking

51. A sort which relatively passes through a list to exchange the first element with any element less than it and then repeats with a new first element is called A. Insertion sort B. Selection sort C. Heap sort Quick sort

52. The pre order and post order traversal of a Binary Tree generates the same output. The tree can have maximum A. Three nodes B. Two nodes C. One node D. Any number of nodes 53. A search technique where we keep expanding nodes with least accumulated cost so far is called A. B. C. D. Hill climbing Branch and bound Best first Divide and conquer

54. The spanning tree of connected graph with 10 vertices contains A. 9 edges B. 11 edges C. 10 edges D.10 vertices 55. The post order traversal of a binary tree is DEBFCA. Find out the preorder traversal. A. ABFCDE B. ADBFEC C. ABDECF D. ABDCEF 56. Which of the following statements are TRUE? (1) The problem of determining whether there exists a cycle in an undirected graph is in P. (2) The problem of determining whether there exists a cycle in an undirected graph is in NP.
64

(3) If a problem A is NP-Complete, there exists a non-deterministic polynomial time algorithm to solve A. A. 1,2 and 3 B. 1 and 2 only C. 2 and 3 only D. 1 and 3 only 57. A binary tree can easily be converted into q 2-tree A. by replacing each empty sub tree by a new internal node B. by inserting an internal nodes for non-empty node C. by inserting an external nodes for non-empty node D. by replacing each empty sub tree by a new external node 58. Which of the following sorting procedures is the slowest? A. Quick sort B. Heap sort C. Shell sort D. Bubble sort 59. The pre-order and post order traversal of a Binary Tree generates the same output. The tree can have maximum A. B. C. D. 60. Three nodes Two nodes One node Any number of nodes

A. A B. B C. C D. D

## 61. Two isomorphic graphs must have

A. B. C. D.

Equal number of vertices Same number of edges Same number of vertices All of the above

62. If each node in a tree has value greater than every value in its left subtree and has value less than every in the its right subtree ,the tree is called
65

A. Complete tree B.Full binary tree C. Binary search tree D. Threaded tree 63. A simple graph in which there exists an edge between pair of vertices is called A. Regular graph B. Planner graph C.Euler graph D. Complete graph

64. The best average behaviour is shown by A. Quick sort B. Merge sort C.Insertion sort D. Heap sort 65. Which of the following sorting algorithm is of divide-and-conquer type? A. Bubble sort B. Insertion sort C. Quick sort D. All of above 66. The recurrence relation capturing the optimal execution time of the Towers of Hanoi problem with n discs is A. B. C. D. 67. T(n) = 2T(n - 2) + 2 T(n) = 2T(n - 1) + n T(n) = 2T(n/2) + 1 T(n) = 2T(n - 1) + 1

## A. A B. B C. C D. D 68. The goal of hashing is to produce a search that takes

O(1) time O(n2 ) time O(log n ) time O(n log n ) time 69. One can make an exact replica of a Binary Search Tree by traversing it in
66

A. B. C. D.

A. Inorder B. Preorder C. Postorder D. Any order 70. When converting binary tree into extended binary tree, all the original nodes in binary

tree are A. internal nodes on extended tree B. external nodes on extended tree C. vanished on extended tree D. None of above 71. The postfix form of A*B+C/D is A. *AB/CD+ C. A*BC+/D B. AB*CD/+ D. ABCD+/*

72. For the bubble sort algorithm, what is the time complexity of the best/worst case?

(assume that the computation stops as soon as no more swaps in one pass) (a) (b) (c) (d) best case: O(n) worst case: O(n*n) best case: O(n) worst case: O(n*log(n)) best case: O(n*log(n)) worst case: O(n*log(n)) best case: O(n*log(n)) worst case: O(n*n)

73. For the

quick sort algorithm, what is the time complexity of the best/worst case?

(a) best case: O(n) worst case: O(n*n) (b) best case: O(n) worst case: O(n*log(n)) (c) best case: O(n*log(n)) worst case: O(n*log(n)) (d) best case: O(n*log(n)) worst case: O(n*n) Answer : D
74. In

an arbitrary tree ( not a search tree) of order M. Its size is N, and its height is K. The computation time needed to find a data item on T is (a) O(K*K) (b) O(M*M) (c) O(N) (d) O(K) Answer : C

67

## 75. When we organize our data

as an ordered list, what is the time complexity of inserting/deleting a data item to/from the list? (a) O(length_of_list*length_of_list) (b) O(length_of_list) (c) O(log(length_of_list * length_of_list)) (d) O(1) Answer : B
76. Five statements

about B-trees are below. Four of them are correct. Which one is

INCORRECT? (a) All B-trees are also search trees (b) The word B-tree stands for balanced tree (c) The word B-tree also stands for binary tree (d) All leaves of a B-tree must be on the same level Answer : C
77. For any

B-tree of height H (H>1), after inserting a new key, is it possible for a key, K, which was located in a leaf-node to move up to the root in this regard which of the following is correct? (a) Cant be defined without data (b) Never (c) Yes, only if H=2 (d) Yes Answer : D
78. When we say

## the order of a tree is M, we mean

(a) Every non-leaf node must have M subtrees (b) Every non-leaf node must have M keys (c) Every non-leaf node can have at most M subtrees (d) Every non-leaf node can have at most M keys Answer : C
79. T

is a search tree of order M, its size is N, and its height is K. The computation time needed to INSERT/DELETE a data item on T is (a) O( 1 ) (b) O( M ) (c) O( Log K ) (d) O( K ) Answer : D

68

## 80. Suppose that

we have a data file containing records of famous people, and we need to build a hash table to find a record from the person's birthday. The size of the hash table is 4096. The following are hash functions which convert a birthday to an integer. Which of the following function is the best? (a) h1( day/month/year ) = day + month + year (b) h2( day/month/year ) = day + month*31 + year (c) h3( day/month/year ) = (day + month*31 + year*365) mod 4096 (d) h4( day/month/year ) = (day + month*31 + year*365) mod 4093 Answer : D

COMPILER DESIGN
1.Which of the following statements is false ? (A) An unambiguous grammar has same left most and right most derivation (B) An LL(1) parser is a top-down parser (C) LALR is more powerful than SLR (D) An ambiguous grammar can never be LR (K) for any k SOLUTION So (A) & (C) are, true. An ambiguous grammar cant be LR (K) So option (A) is false since an unambiguous grammar has unique right most derivation & left most derivations but both are not same. Hence (A) is correct option 2. Dynamic linking can cause security concerns because (A) Security is dynamic (B) The path for searching dynamic libraries is not known till run time. (C) Linking is insecure (D) Cryptographic procedures are not available for dynamic linking SOLUTION Dynamic linking is type of linking in which libraries required by the program are linked during run time. But at this time cryptographic procedures are not available, so make this process insecure. Hence (D) is correct option. 3. Which of the following suffices to convert an arbitrary CFG to an LL(1) grammar? (A) Removing left recursion alone
69

(B) Factoring the grammar alone (C) Removing left recursion and factoring the grammar (D) None of this SOLUTION If a grammar has left recursion & left factoring then it is ambiguous. So to convert a CFG to LL(1) grammar both removal of left recursion & left factoring need to be done. Hence (C) is correct option. 4. Assume that the SLR parser for a grammar G has n1 states and the LALR parser for G has n2 states. The relationship between n1 and n2 is (A) n1 is necessarily less than n2 (B) n1 is necessarily equal to n2 (C) n1 is necessarily greater than n2 (D) None of the above SOLUTION SLR parsue is less range of context free languages than LALR but still both n1 & n2 are same for SLR & LALR respectively. Hence (B) is correct option. 5. In a bottom-up evaluation of a syntax directed definition, inherited attributes can (A) always be evaluated (B) be evaluated if the definition is L-attributed (C) be evaluated only if the definition has synthesized attributes (D) never be evaluated SOLUTION Every S (synthesized) -attributed definitions is L- attributed. So in a bottom-up evaluation of SDD inherited attributes can be evaluated only if the definition has synthesized attributes. Hence (C) is correct option. 6. Which of the following statements is FALSE? (A) In statically typed language, each variable in a program has a fixed type (B) In up-typed languages, values do not have any types (C) In dynamically typed languages, variables have no types (D) In all statically typed languages, each variable in a program is associated with values of only a single type during the execution of the program
70

SOLUTION (1) True for statically typed languages where each variable has fixed type. Similarly (4) is also correct. (2) True, in un-typed languages types of values are not defined. But option (C) is false, since in dynamically typed language variables have dynamically changing types but not that they have no type. Hence (C) is correct option. 7.Consider the grammar shown below S " | EtSS' | S' " eS |! E"b In the predictive parse table M of this grammar the entities M(S) and M[S1,$] respectively are (A) {s' " eS }and{S' " } (B) {s' " eS}and{} (C) {s' " }and{S' " } (D){s' " eS , S ' " }and{ S' " } SOLUTION:D 8. Consider the grammar shown below. S"CC C " eC | d The grammar is (A) LL (1) (B) SLR (1) but not LL (1) (C) LALR (1) but not SLR (1) (D) LR (1) but not LALR (1) SOLUTION Given grammar S " CC C "cC d it cant be LL since C " cC is recursive. LR(1) also known as CLR parser, and every CF 71 grammar is CLR grammar. So (A) is false but (C) & (D) can be correct. This grammar is CLR and also reducible to LALR without any conflicts. So (D) is false. Only need to check for SLR(1) or LR(0) This grammar is not SLR. Hence (C) is correct option 9. Consider the translation scheme shown below S " TR R "+ T {print (+);}R | T " num {print (num.val);} Here num is a token that represents an integer and num. val represents the corresponding integer value. For an input string 9 + 5+ 2, this translation scheme will print (A) 9 + 5 + 2 (C) 9 5 2 ++ SOLUTION S " TR R "+ T {pr int(' + ');}R T " num{print(num.val);} Given string 9 + 5 + 2 S " TR (B) 9 5 + 2 + (D) ++ 9 5 2 ## T + TR T+T+T 9+T+T 9+5 +T 9+5 +2 ## {print(+);} {print(+);} {print(9);} {print(5);} {print(2);} So ++ 952 is printed Hence (D) is correct option. 10. Consider the syntax directed definition shown below S " id: = E " newtemp (); gen(t . place .place t} . place;); 72 " .place .place;} Here, gen is a function that generates the output code, and newtemp is a function that returns the name of a new temporary variable on every call. Assume that t1s are the temporary variable names generated by newtemp. For the statement X: = Y + Z , the 3-address code sequence generated by this definition is (A) X = Y + Z (B) t1 = Y + Z; X t1 (C) t1 = Y; t2 = t1 + Z; X = t2 (D) t1 = Y; t2 = Z; t3 + t2; X = t3 SOLUTION In 3-address code we use temporary variables to reduce complex instructions so here t1 = Y t2 = Z t 3 = t 1 + t2 x = t3 Hence (D) is correct option. Solve the problems and choose the correct answers. The following program fragment is written in a programming language that allows variables and does not allow nested declarations of functions. global inti void int i print i print } main () { (i ) } 11. If the programming language uses static scoping and call by need parameter passing mechanism, the values printed by the above program are (A) 115, 220 (B) 25, 220 (C) 25, 15 SOLUTION In static scoping the variables are initialized at compile time only 73 ## (D) 115, 105 So i = 100 & j = 5 P (i + j) = P (100 + 5) = P(105) So x = 105 x + 10 = 105 + 10 = 115 So 115 & 105 will be printed. Hence (D) is correct option. 12. If the programming language uses dynamic scoping and call by name parameter passing mechanism, the values printed by the above program are (A) 115, 220 (B) 25, 220 (C) 25, 15 (D) 115, 105 SOLUTION In dynamic scoping, the local values are considered & variables are initialized at run time. Since x = i + j & in P (x) i = 200 & j = 20 x = 200 + 20 = 220 & printing (x + 10) x = i + j + 10 = 10 + 5 + 10 = 25 Hence (B) is correct option 13. Consider the following class definitions in a hypothetical object oriented language that supports inheritance and uses dynamic binding. The language should not be assumed to be either Java or C++, thought the syntax is similar Now consider the following program fragment: P x =new Q(); Q y =new Q(); 74 P z =new Q(); x. f (1);((P) y). f (1);z.f(1); Here ((P) y) denotes a typecast of y to P. The output produced by executing the above program fragment will be (A) 1 2 1 (B) 2 1 1 (C) 2 1 2 SOLUTION 1. 2. 3. 4. 5. 6. Px = newQ(); Qy = newQ(); Pz = newQ(); x : f(1); print 2 # i = 2 ((P) y) : f(1); z : f(1) print 2 # i = 2 (D) 2 2 2 but line 5. will print 2 because typecast to parent class cant prevent over ridding. So function f(1) of class Q will be called not f(1) of class P . Hence (D) is correct option. 14. Which of the following is NOT an advantage of using shared, dynamically linked libraries as opposed to using statically linked libraries? (A) Smaller sizes of executable (B) Lesser overall page fault rate in the system (C) Faster program startup (D) Existing programs need not be re-linked to take advantage of newer versions of libraries SOLUTION The advantages of shared dynamically linked libraries include. (A) smaller size of executable since less data (B) lesser overall page fault rate. (C) No need for re-linking if newer versions of libraries are there. But since compilation time doesnt include linking so a long linking time required during runtime in DLL ' s so slow startup. Hence (C) is correct option. 15. Which of the following grammar rules violate the requirements of an operator grammar? P, Q, R are non-terminals, and r, s, t are terminals 75 . (i) P " QR (iii) P " (A) (i) only (ii) P " Q s R (iv) P " Q t R r (B) (i) and (iii) only (C) (ii) and (iii) only (D) (iii) and (iv) only SOLUTION (I) P " QR is not possible since two NT should include one operator as Terminal. (II) Correct (III) Again incorrect. (IV) Correct. Hence (B) is correct option. 16. Consider a program P that consists of two source modules M1 and M2 a reference to a function contained in two different files. If M1 contains defined in M2, the reference will be resolved at (A) Edit-time (B) Compile-time (C) Link-time SOLUTION The two modules needed to be linked since definition exist & M2 & M1 refers it. So during linking phase M1 links to M2. Hence (C) is correct option. 17. Consider the grammar rule E " E1 E2 for arithmetic expressions. The code generated is targeted to a CPU having a single user register. The subtraction operation requires the first operand to be in the register. If E1 and E2 do not have any common sub expression, in order to get the shortest possible code (A) E1 should be evaluated first (B) E2 should be evaluated first (C) Evaluation of E1 and E2 should necessarily be interleaved (D) Order of evaluation of E1 and E2 is of no consequence (D) Load-time SOLUTION E1 is to be kept in accumulator & accumulator is required for operations to evaluate E2 also. So E2 should be evaluated first & then E1, so finally E1 will be in accumulator, otherwise need to use move & load instructions. 76 Hence (B) is correct option. 18. Consider the grammar with the following translation rules and E as the start symbol. E " E 1 #T " value = .value * .value} .value = .value} .value = .value + .value} .value = .value} "num .value =num.value} Compute E . value for the root of the parse tree for the expression: 2 # 3 # & 5 # 6 & 4. (A) 200 (B) 180 (C) 160 SOLUTION The parse tree would be. (D) 40 ## Now we evaluate bottom up 77 LL " left to right left most derivation no ambignity should be there SLR or LR(0) L to R reverse right sentential form create LR(0) items. CLR or LR(1) create LR(1) items no bound LALR reduced CLR if while reducing any conflict found then not LALR Hence (C) is correct option. 19. The grammar A " AA |( A)| is not suitable for predictive-parsing 78 because the grammar is (A) ambiguous (C) right-recurisve SOLUTION The grammar is definitely left & right recursive but it is not suitable for predictive parsing because it is ambiguous. Hence (A) is correct option. 20. Consider the grammar E " E + n | E # n | n For a sentence n + n, the handles in the right-sentential form of the reduction are (A) n, E + n and E + n # (C) n , n + n and n + n # n SOLUTION Given grammar E "E+n E "E#n E "n String = n + n # n Right sentential so right most non terminal will be used. E"E#n {E " E # n} E+n#n {E " E + n} n+n#n {E " n} So during reduction the order is reverse. So {E " n , E " E + n, E " E # n} Hence (D) is correct option. 21. Consider the grammar S " (S)| a Let the number of states in SLR(1), LR(1) and LALR(1) parsers for the grammar n1 n2 and n3 respectively. The following relationship holds good (A) n1 < n2 < n3 (C) n1 = n2 = n3 SOLUTION The no. of states for SLR(1) & LALR(1) are equal so n 1 = n3, but CLR(1) or LR(1) will have no. of states greater than LALR & LR(0) both. 79 ## (B) Left-recursive (D) an operator-grammar ## B) n , E + n and E + E # n (D) n , E + n and E # n ## (B) n1 = n3 < n2 (D) n1$ n3 $n2 Hence (B) is correct option. 22. Consider line number 3 of the following C-program. Identify the compilers response about this line while creating the object-module (A) No compilation error (B) Only a lexical error (C) Only syntactic errors (D) Both lexical and syntactic errors SOLUTION There are no lexical errors for C because all the wrong spelled keywords would be considered as identifiers until the syntax is checked. So the compiler would give syntax errors. Hence (C) is correct option. Data for Q. 23 & 24 are given below. Solve the problems and choose the correct answers. Consider the following expression grammar. The semantic rules for expression calculation are stared next to each grammar production. E " number E E # E ; 23. The above grammar and the semantic rules are fed to a yacc tool (which is an LALR(1) parser generator) for parsing and evaluating arithmetic expressions. Which one of the following is true about the action of yacc for the given grammar? (A) It detects recursion and eliminates recursion (B) It detects reduce-reduce conflict, and resolves (C) It detects shift-reduce conflict, and resolves the conflict in favor of a shift over a reduce 80 ## Eval E .val E .val ## number val E .VAL E .VAL E .val E .val action (D) It detects shift-reduce conflict, and resolves the conflict in favor of a reduce over a shift action SOLUTION Yace tool is used to create a LALR(1) parser. This parser can detect the conflicts but to resolve the conflicts it actually prefers shift over reduce action. Hence (C) is correct option. 24. Assume the conflicts part (a) of this question are resolved and an LALR(1) parser is generated for parsing arithmetic expressions as per the given grammar. Consider an expression 3 # 2 + 1. What precedence and associativity properties does the generated parser realize? (A) Equal precedence and left associativity; expression is evaluated to 7 (B) Equal precedence and right associativity, expression is evaluated to 9 (C) Precedence of 'x' is higher than that of +, and both operators are left associative; expression is evaluated to 7 (D) Precedence of ' # ' is higher than that of #, and both operators are left associative; expression is evaluated to 9 SOLUTION The grammar has equal precedence and it is also ambiguous. Since LALR(1) parser prefer shift over reduce so + operation will be executed here before ). 2 + 1 = 3 & 3 # 3 = 9 also the operators are right associative. Hence (B) is correct option. 25. Consider the following grammar. S "S*E S "E E"F+EE"F F " id Consider the following LR(0) items corresponding to the grammar above. (i) (ii) (iii) S " S * .E E"F.+E E " F + .E Given the items above, which two of them will appear in the same set in the canonical sets-ofitems for the grammar? 81 ## (A) (i) and (ii) (C) (i) and (iii) SOLUTION ## (B) (ii) and (iii) (D) None of these If S " S ): E is in LR(0) then E " F +: E will also be there because both of them has ' : ' before E . Hence (C) is correct option. 26. 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 " } (C) {S " FR} and {R " * S} SOLUTION The predictive parser table is given as. Non Terminal S F R So at R ") S R "! M [ S, id] = S { " FR} "!} ) id S " FR F " id R "! $(B) {S " FR} and {} (D) {F " id} and {R " } ## M [ R,$] = {R Hence (A) is correct option.

27. Consider the following translation scheme. S " ER R " * E{print{ * );R | f E " F + E{print( + ); | F F " (S) | id{print(id.value);} Here id is a taken 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 + *
82

SOLUTION Input string 2 ) 3 + 4 S " ER FR idR {print(2)} id)ER {print())} id) F+ER {print(+)}id) id + ER {print(3)} id) id ) id +id So 2 )+ 3 4 are printed Hence (B) is correct option. 28. Consider the following C code segment. for for if i #i } } } Which one to the following false? (A) The code contains loop-in variant computation (B) There is scope of common sub-expression elimination in this code (C) There is scope strength reduction in this code (D) There is scope of dead code elimination in this code

SOLUTION All the statements are true except option (D) since there is no dead code to get eliminated. Hence (D) is correct option. 29. Which one of the following grammars generates the language L = (a i b i | i ! j}?

(A)

## S " AC | CB C " aCb | a | b A " aA | B " Bb | S " ACCB

(B) S " aS | Sb | a | b

(C)

(D)

S " AC | CB
83

## C " aCb |! A " aA | a B " bB | b

SOLUTION The grammar S " AC CB C "aCb ! A "aA a B " bB b Consider string aaabb S " AC AaCb AaaCbb Aaabb aaabb But string aabb S " AC And this string is not derivable. Hence (D) is correct option. 30.In the correct grammar above, what is the length of the derivation (number of steps starting from S to generate the string al bm with l ! m? (A) max (l, m) + 2 (B) l+m+2 (C) l + m + 3 SOLUTION It is very clear from the previous solution that the no. of steps required depend upon the no. of a' s & b ' s which ever is higher & exceeds by 2 due to S " AC CB & C "! So max(l , m) + 2 Hence (A) is correct option. 31. Which one of the following is a top-down parser? (A) Recursive descent parser (B) Operator precedence parser (C) An LR(k) parser SOLUTION Clearly LR & LALR are not top down they are bottom up passers. Also not operator precedence parser. ut yes recursive descent parser is top down parser. Starts from start symbol & derives the terminal string. Hence (A) is correct option.
84

## (D) An LALR(k) parser

32.Consider the grammar with non-terminals N = {S , C , S}, terminals T = {a, b , i , t, e}, with S as the start symbol, and the following of rules S " iCtSS1 | a S1 " eS | C"b The grammar is NOTLL(1) because: (A) It is left recursive (B) It is right recursive (C) It is ambiguous SOLUTION The grammar has production S " iCtSS1 here the right hand side of grammar has the same symbol as left side. So the grammar is left recursive. The grammar is not ambiguous. Hence (A) is correct option. 33.Consider the following two statements: P: Every regular grammar is LL(1) Q: Every regular set has LR(1) grammar Which of the following is TRUE? (A) Both P and Q are true (C) P is false and Q is true SOLUTION LL(1) parsers can recognize the regular grammars also LL(1) is subset of LR(1) or CLR grammar so it also recognizes regular sets. So both accept regular grammar. 34. In a simplified computer the instructions are: OP R j , Ri Performs Rj OP Ri and stores the result in register Ri OP m, Ri Performs val OP Ri abd stores the result in Ri. value denotes the content of memory location m. MCVm, Ri Moves the content off memory loction m to register Ri . MCVm, Ri , m Moves the content of register Ri to memory location m. (B) P is true and Q is false (D) Both P and Q are false (D) It is not context-free

The computer has only two registers, and OP is either ADD or SUB. Consider the following basic block:
85

t1 = a + b t2 = c + d t 3 = e t2 t 4 = t 1 t2 Assume that all operands are initially in memory. The final value of the computation should be in memory. What is the minimum number of MOV instructions in the code generated for this basic block? (A) 2 (C) 5 SOLUTION The operation sequence would be MOV a, R1 ADD b , R1 {R 1 = t1 MOV c , R2 ADD d, R2 { R 2 = t2 SUB e , R2 {t 3 = e R 2 = R2 SUB R 1, R2 {R 2 = t4 MOV R 2, t4 {finally in memory Totally no. of move operation are 3 Hence (B) is correct option Data for Q. 35 & 36 are given below. Solve the problems and choose the correct answers. Consider the CFG with {S, A, B} as the non-terminal alphabet, {a, b} as the terminal alphabet, S as the start symbol and the following set of production rules (B) 3 (D) 6

35.Which of the following strings is generated by the grammar? (A) aaaabb (C) aabbab (B) aabbbb (D) abbbba

SOLUTION aabbab
86

S " aB " aaBB " aabSB " aabbAB " aabbab Hence (C) is correct option. 36.For the correct answer string to Q. 9 how many derivation trees are there? (A) 1 (C) 3 SOLUTION For the derivation two trees are possible (B) 2 (D) 4

## So due to ambiguity 2 trees are possible Hence (B) is correct option.

37. Which of the following describes a handle (as applicable to LR-parsing) appropriately? (A) It is the position in a sentential form where the next shift or reduce operation will occur (B) It is a non-terminal whose production will be used for reduction in the next step (C) It is a production that may be used for reduction in a future step along with a position in the sentential form where the next shift or reduce operation will occur. (D) It is the production p that will be used for reduction in the next step along with a position in the sentential form where the right hand side of the production may be found SOLUTION Handles are the part of sentential form, & they are identified as the right side of any given production which will be used for reduction in the net step.
87

Hence (D) is correct option. 38.Some code optimizations are carried out on the intermediate code because (A) They enhance the portability of the complier to other target processors (B) Program analysis is name accurate on intermediate code than on machine code (C) The information from data flow analysis cannot otherwise be used for optimization (D) The information from the front end cannot otherwise be used for optimization SOLUTION Code optimizations are carried out on the intermediate code because program analysis is more accurte on intermediate code than on machine code. Hence (B) is correct option. 39. Which of the following are true? (i) A programming language option does not permit global variables of any king and has no nesting of procedures/functions, but permits recursion can be implemented with static storage allocation (ii) Multi-level access link (or display) arrangement is needed to arrange activation recordsonly if the programming language being implemented has nesting of procedures/function (iii) Recursion in programming languages cannot be implemented with dynamic storage allocation (iv) Nesting of procedures/functions and recursion require a dynamic heap allocation scheme and cannot be implemented with a stack-based allocation scheme for activation records (v) Languages which permit a function to return a function as its result cannot be implemented with a stack-based storage allocation scheme for activation records (A) (ii) and (v) only (C) (i), (ii) and (v) SOLUTION I. Statement is false since global variables are required for recursions with static storage. This is due to unavailability of stack in static storage. II. This is true III. In dynamic allocation heap structure is used, so it is false. IV. False since recursion can be implemented. V. Statement is completely true. So only II & V are true. Hence (A) is correct option.
88

(B) (i), (iii) and (iv) only (D) (ii), (iii) and (v) only

40. An LALR(1) parser for a grammar can have shift-reduce (S-R) conflicts if and only if (A) The SLR(1) parser for G has S-R conflicts (B) The LR(1) parser for G has S-R conflicts (C) The LR(0) parser for G has S-R conflicts (D) The LALR(1) parser for G has reduce-reduce conflicts SOLUTION LALR parser is reduced form of CLR or LR(1) parser, LALR parser uses the LR(1) items of CLR parser & of any shift reduce conflicts are there then it is due to LR(1) parser. Hence (B) is correct option. 41. Which of the following statements are TRUE ? There exist parsing algorithms 3for some programming languages hose complex are less than (n ) II A programming language which allows recursion can be implemented with static storage allocation III No L-attributed definition can be evaluated in the framework of bottom-up parsing IV Code improving transformations can be performed at both source language and intermediate code level (A) I and II (C) III and IV (B) I and IV (D) I, III and IV

SOLUTION I. Statement is true since there are some parsers which take 0(n log2n) time for parsing. II. Completely false, since there is no use of stack which is required for recursion. III. False IV. True since both types of optimizations are applied Hence (B) is correct option. 42.What data structure in a complier is used for managing information about variables and their attributes? (A) Abstract syntax tree (B) Symbol table (C) Semantic stack SOLUTION Symbol table is used for storing the information about variables and their attributes by
89

## (D) Parse table

compiler. Hence (B) is correct option. 43. Which languages necessarily need heap allocation in the runtime environment ? (A) Those that support recursion (B) Those that use dynamic scoping (C) Those that allow dynamic data structure (D) Those that use global variables

SOLUTION Dynamic memory allocation is maintained by heap data structure. So to allow dynamic data structure heap is required. Hence (C) is correct option.

OPERATING SYSTEMS
YEAR 2001 Question. 1 Which of the following statements is false ?
(A)Virtual memory implements the translation of a programs address space into physical memory address space. (B)Virtual memory allows each program to exceed the size of the primary memory. (C)Virtual memory increases the degree of multi-programming (D)Virtual memory reduces the context switching overhead.

SOLUTION Virtual memory enables a program to exceed the size of primary memory so it increases degree of multi-programming. Since data required by executing program is available here so context switching is reduced. But virtual memory doesnt translate programs address space into physical memory. Hence (A) is correct option. Question. 2

90

Consider a set of n tasks with known runtimes r1,r2,........rn to be run on a uniprocessor machine. Which of the following processor scheduling algorithms will result in the maximum throughput ?
(A) Round-Robin (C) Highest-Response-Ratio-Next SOLUTION (B) Shortest-Job-First (D) First-come-First-Served

Here the running times r1....rn are already known, single processor system. In this scenario, throughput i.e. CPU is maximum utilized in shortest job first scheduling. Hence (B) is correct option. Question. 3 Where does the swap space reside ? (A) RAM (C) ROM SOLUTION Swap space is the memory space where the part of the program not currently in main memory for execution is stored, this program part can be swapped into memory when required. This space is generally in disk. Hence (B) is correct option. Question. 4 Consider a virtual memory system with FIFO page replacement policy. For an arbitrary page access pattern, increasing the number of page frames in main memory will.
(A)Always decrease the number of page faults (B)Always increase the number of page faults (C)Sometimes increase the number of page faults (D)Never affect the number of page faults

## (B) Disk (D) On-chip cache

SOLUTION During F1F0 page replacement policy, due to increase in the no. of page frames in memory should decrease the no. of page faults since more frames can be kept there. But due to Beladys Anomaly after certain limit or in some page access instances no. of page faults are high.
91

Hence (C) is correct option. Question. 5 Consider a machine with 64 MB physical memory and a 32-bit virtual address space. If the page size is 4 KB, what is the approximate size of the page table ? (A) 16 MB (C) 2 MB SOLUTION
Size of main memory = 64 MB Size of virtual memory = 232 B No. of pages = 232/212 = 220 pages Required 1 M enteries. But each entry has both a virtual address & corresponding physical address. Total bits in each entry = 32 +26 (Physical) = 58

(B) 8 MB (D) 24 MB

= 58/8 = 8 Bytes. So total memory = 8*1 MB= 8 MB Hence (B) is correct option. Question. 6 Consider Petersons algorithm for mutual exclusion between two concurrent processes i and j. The program executed by process is shown below.
repeat ag[i]=true; turn=j; while(p)do no-op; Enter critical section, perform actions, then exit critical section Flag[i]=false; Perform other non-critical section actions. Until false;

For the program to guarantee mutual exclusion, the predicate P in the while loop should be
(A) flag [j]= true and turn =j (C) flag [i]=true and turn=j (B) flag [j]=true and turn =j (D) flag [i]=true and turn=i

SOLUTION
92

While loop if true predicate then the program enters into critical region. This program enters into critical region of flag [i]=true act as semaphore, & true =j, the requirement of resource is by some other process. Hence (B) is correct option. YEAR 2002 Question. 7
Which of the following scheduling algorithms is non-preemptive ? (A) Round Robin (B) First-In First-Out (C)Multilevel Queue Scheduling (D)Multilevel Queue Scheduling with Feedback

SOLUTION Round robin is preemptive since processes are cycled for CPU time, & run for a particular time stamp in one cycle. Multilevel queue scheduling maintains various quenes, each having different priorities. But in FIFO scheme, only the process which enters once, would be completed first, so no. preemption. Hence (B) is correct option.Question. 8 The optimal page replacement algorithm will select the page that
(A)Has not been used for the longest time in the past. (B)Will not be used for the longest time in the future. (C)Has been used least number of times. (D)Has been used most number of times

SOLUTION Optimal page replacement algorithm assumes that the pages that will come in future are already known, so replacement of the page which will not be used in future occurs. Hence (B) is correct option. Question. 9 Which combination of the following features will suffice to characterize an OS as a multiprogrammed OS ? More than one program may be loaded into main memory at the same time for execution. (B) If a program waits for certain events such as I/O, another program is immediately scheduled for execution. (C) If the execution of a program terminates, another program is immediately scheduled for execution.
93

## (B) A and B (D) A, B and C

Multi-programmed:- More than one program can run on single CPU, when one is blocked. (A)Is true and a characteristic of multi-programmed (B)Is true & also characterize a multi-programmed OS (C)Is true but no necessary for this type this happens in all OS, even in batch processor. Hence (B) is correct option.

Question. 10
In the index allocation scheme of blocks to a file, the maximum possible size of the file depends on (A)The size of the blocks, and the size of the address of the blocks (B)The number of blocks used for the index, and the size of the blocks. (C)The size of the blocks, the number of blocks used for the index, and the size of the address of the blocks. (D)None of the above.

SOLUTION When indexes are created, the maximum no. of blocks given to a file are totally dependent upon size of the index which tells how many blocks can be there, & size of each block. Hence (B) is correct option. YEAR 2003 Question. 11 Using a larger block size in a fixed block size file system leads to (A)better disk throughput but poorer disk space utilization (B)better disk throughput and better disk space utilization (C)poorer disk throughput but better disk space utilization (D)poorer disk throughput and poorer disk space utilization SOLUTION Using larger block size in a fixed block size system lead to poor disk space utilization due to data items which are very small comparable to block size cause fragmentation. But it leads to better disk through put since no. of blocks needs to fetch & replace become less.
94

## Hence (A) is correct option. Question. 12

In a system with 32 bit virtual addresses and 1 KB page size, use of one-level page tables for virtual to physical address translation is not practical because of (A)the large amount of internal fragmentation (B)the large amount of external fragmentation (C)the large memory overhead in maintaining page tables (D)the large computation overhead in the translation process

SOLUTION 32 bit virtual address, i.e. 232 kB of virtual memory & 1 kB page size. So total pages = 232. So. we need to maintain a page table of 232 rows, this require 4 GB main memory which is quite impractical due to large memory overhead. Hence (C) is correct option. Question. 13 A uni-processor computer system only has two processes, both of which alternate 10 ms CPU bursts with 90 ms I/O bursts. Both the processes were created at nearly the same time. The I/O of both processes can proceed in parallel. Which of the following scheduling strategies will result in the least CPU utilizations (over a long period of time) for this system ?
(A)First come first served scheduling (B)Shortest remaining time first scheduling (C)Static priority scheduling with different priorities for the two processes (D)Round robin scheduling with a time quantum of 5 ms.

SOLUTION There should be no doubt that round robin scheduling would lead to maximum CPU utilization, but since in FCFS one task would starve for a long time so min CPU utilization would be in this case. Hence (A) is correct option. Data for Q. 14 & 15 are given below. A processor uses 2-level page table fro virtual to physical address translation. Page table for both levels are stored in the main memory. Virtual and physical addresses are both 32 bits wide. The memory is byte addressable. For virtual to physical address translation, the 10 most
95

significant bits of the virtual address are used as index into the first level page table while the next 10 bits are used as index into the second level page table. The 12 least significant bits of the virtual address are used as offset within the page. Assume that the page table entries in both levels of page tables are 4 a bytes wide. Further, the processor has a translation look aside buffer(TLB), with a hit rate of 96%. The TLB caches recently used virtual page numbers and the corresponding physical page numbers. The processor also has a physically addressed cache with a bit ratio of 90%. Main memory access time is 10 ns, cache access time is 1 ns, and {LB access time is also 1ns. Question. 14 Assuming that no page faults occur, the average time taken to access a virtual address is approximately (to the nearest 0.5 ns) (A) 1.5 ns (C) 3 ns SOLUTION
TLB is successfully 96% of total request & for remaining 4%. RAM is accessed twice. So average time taken. =0.96(1 +(0.9*1) +0.1*(1 +10))+0.04(21 +(0.9*0.1)) +0.1*(1 +10) =.96(1 +.9 +1.1) +0.4(21 +.09 +1.1) =.96*3 +0.4*23 =2.88 +0.92 =3.804 ns (Nearest .5) Hence (D) is correct option.

(B) 2 ns (D) 4 ns

Question. 15 Suppose a process has only the following pages in its virtual address space; two contiguous code pages starting at virtual address 0x0000000, two contiguous data pages starting at virtual address 0x00400000, and a stack page starting at virtual address 0xFFFFF000. The amount of memory required for storing the page tables of this process is (A)8 KB SOLUTION Total no. of pages required = 5 But due to 2 level page table = 2*4 Kb*2 =16 kB Hence (D) is correct option. Data for Q. 16 & 17 are given below. (B) 12KB (C) 16 KB (D) 20KB

96

Suppose we want to synchronize two concurrent processes P and Q using binary semaphores S and T. The code for the processes P and Q is shown below. Process P while(1) { W: print 0; print 0; X: } Process Q: while(1) { Y: print 1 print 1 Z: }

## Synchronization statements can be inserted only at points W, X, Y and Z. Question. 16

Which of the following will always lead to an output staring with 001100110011? (A) P(S) at W, V(S) at X, P(T) at Y, V(T) at Z, S and T initially 1 (B) P(S) at W, V(T) at X, P(T) at Y, V(S) at Z, S initially 1, and T initially 0 (C)P(S) at W, V(T) at X, P(T) at Y, V(S) at Z, S and T initially 1 (D)P(S) at W, V(T) at X, P(T) at Y, V(S) at Z, S initially 1, and T initially 0

SOLUTION
For output string 001100110011 alternatingly we require process P & Q to execute. For this to happen P(s) with S = 1 should be placed at W. At the same time P(T) with T = 0 will be at Y. At X we have V(T) which will have T = 1 so process Q starts. At the same time at Z we have V(s) which make S = 0 to stop process P. Hence (B) is correct option.

Question. 17 Which of the following will ensure that the output string never contains a substring of the form 0.1 or 101 where n is odd?
(A)P(S) at W, V(S) at X, P(T) at Y, V(T) at Z, S and T initially 1 (B)P(S) at W, V(T) at X, P(T) at Y, V(S) at Z, S and T initially 1 (C)P(S) at W, V(S) at X, P(T) at Y, V(S) at Z, S initially 1 (D)(S) at W, V(T) at X, P(T) at Y, P(S) at Z, S and T initially 1

SOLUTION To ensure this condition that substring of form 01n0 or 10n1, where n is odd S should be initially 1, we will case only 1 semaphore S. So at W P(s), at X V(s) whereas at Y P(s), at Z V(s)
97

## Hence (C) is correct option. YEAR 2004 Question. 18

Consider the following statements with respect to user-level threads and kernel-supported threads (i)Context which is faster with kernel-supported threads (ii)For user-level threads. a system call can block the entire process (iii)Kernel-supported threads can be scheduled independently (iv)User-level threads are transparent to the kernel Which of the above statements are true?

(A) (ii),(iii) and (iv) only (C) (i) and (iii) only SOLUTION

(B) (ii) and (iii) only (D) (i) and (ii) only

(I)It is false, context switch is not faster in support of kernel threads. (II)A system call can truly block the user level threads, since they dont have permission to do that. (III)True since kernel supported threads have their independent memory & resources. (IV) False since user level threads might need support of kernel threads. Hence (B) is correct option.

Question. 19 Consider an operating system capable of loading and executing a single sequential user process at a time. The disk head scheduling algorithm used is First Come First Served (FCFS). If FCFS is replaced by shortest seek Time Fist (SSTF), claimed by the vendor to given 50% better beachmark results, what is the expected improvement in the I/O performance of user programs? (A) 50% (C) 25% SOLUTION I/O performance is not entirely dependent upon disk access, it has effect of various other devices, so using SSTF in place of FCFS may reduce disk access time but no improvement in the I/O is done. Hence (D) is correct option. Question. 20 The minimum number of page frames that must be allocated to a running process in a virtual memory environment is determined by
(A)the instruction set architecture 98

## (B)page size (C)physical memory size (D)number of processes in memory

SOLUTION Page frames are allocated in main memory, for virtual memory pages. This no. of page frames depends upon the instruction set architecture. Hence (A) is correct option. Question. 21 Consider the following set of processes, with the arrival times and the CPU-burst times given in milliseconds

Process P1 P2 P3 P4

Arrival Time 0 1 2 4

Burst Time 5 3 3 1

What is the average turnaround time for these processes with the preemptive shortest remaining processing time first (SRPT) algorithm? (A) 5.50 (C) 6.00 SOLUTION Then around time = (Submit time finish time) Gantt chart for the scheduler. (B) 5.75 (D) 6.25

## T.A time for P1 = 12 0 = 12 P2 = 4 1 = 3 P3 = 8 2 = 6

99

P4 = 5 4 = 1 Total = 22 Average turnaround time = 22/4 = 5.5 Hence (A) is correct option.

Question. 22 Consider a system with a two-level paging scheme in which a regular memory access takes 150 nanoseconds, and servicing a page fault takes 8 milliseconds. An average instruction takes 100 nanoseconds of CPU time, and two memory accesses. The TLB hit ratio is 99%, and the page fault rate is one in every 10,000 instructions. What is the effective average instruction execution time? (A) 645 nanoseconds (C) 1215 nanoseconds
SOLUTION Memory access time =0.90*150 +0.10*(150 +150) =135 +30 =165 ns The error rate = 1/10000 = 104 CPU burst time = 100 ns Total execution time =[100 +2[165] +104*8*106] =100 +330 +800 =100 +1130 =1230 ns Hence (D) is correct option.

## (B) 1050 nanoseconds (D) 1230 nanoseconds

Question. 23 Consider two processes P1 and P2 accessing the shared variables X and Y protected by two binary semaphores Sx and Sy respectively, both initialized to 1. P and V denote the usual semaphore operators, where P decrements the semaphore value, and V increments the semaphore value. The pseudo-code of P1 and P2 is as follows: P1: { while true do L1: L2: X = X+1; Y = Y-1; V(Sx); V(Sy); } P 2: { while true do L3: L4: Y = Y+1; X = Y-1; V(Sy); V(Sx); }
100

In order to avoid deadlock, the correct operators at L1, L2, L3 and L4 are respectively (A) P(Sy),P(Sx);P(Sx),P(Sy) (C) P(Sx),P(Sx);P(Sy),P(Sy) SOLUTION Here semaphores are required to obtain mutual exclusion since both access X & Y . So at L1 P(Sx) which means now Sx = wait at L2P(Sy) Sy wait, this prevents process P2 to start access X &Y . V(Sx) & V(Sy) in the end of P1 makes Sx & Sy signal so that at L3 & L4 P(Sx) & P(Sy) can start. Hence (D) is correct option. Question. 24 A Unix-style I-node has 10 direct pointers and one single, one double and one triple indirect pointers. Disk block size is 1 Kbyte, disk block address is 32 bits, and 48-bit integers are used. What is the maximum possible file size? (A) 224 bytes SOLUTION
Size of 1 block = 1 kB Block addresses size 1 pointer size = 32 bit = 4 bytes. So, no. of pointers in= 210B/ 22B 1 block = 256 So direct pointer will have = 10*1kB = 10kB Double will have = 256*256*1 kB Triple will have = 256*256*256*1 kB = 28*28*28*210 B = 234 B Hence (C) is correct option. YEAR 2005

## (D) 248 bytes

Question. 25 Suppose n processes, P1Pn share m identical resource units, which can be reserved and released one at a time. The maximum resource requirement of process Pi is sp where si<0. Which one of the following is a sufficient condition for ensuring that deadlock does not occur? (A) i, s < m n (C) si < (m +n) i=1 (B) i,s,< n n (D) si < (m * n) i=1
101

SOLUTION For every Pi Si is maximum resource requirement where Si > 0. To allot resources to all processes without any deadlock situation is n si < (m +n) i=1 i.e. sum of all maximum resource requirement should be less than m +n. Hence (C) is correct option.

Question. 26 Consider the following code fragment: if (fork()==0) {a = a +5; printf("%d,%/n"a, and a);} else {a 5; printf("%d,%d/n",a,&a);} let u, v be the values printed by the parent process, and x,y be the values printed by the child process. Which one of the following is TRUE? (A) u = x+10 and v = y (B) u = x+10 and vy (C) u+10 = x and v = y (D) u+10 = x and v y SOLUTION Initial value of a is let 10 and its address &a would be different for both parent & child process so. (A) & (B) are incorrect also parent process executes a = a 5 = 5 = u & child executes a = a +5 = 15 = x so u +10 = x Hence (D) is correct option. YEAR 2006 Question. 27 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
102

implements a shortes remaining time first scheduling algorithm? Do not count the context switches at time zero and at the end (A) 1 SOLUTION When CPU burst are given to another process, called context switching. The Gantt chart for shortest remaining time first is. (B) 2 (C) 3 (D) 4

So there are two context & witches at T = 10 & T = 30 Hence (B) is correct option. Question. 28 The atomic feth-and-set x,y instruction unconditionally sets the memory location x to 1 and fetches the old value of x in 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_semphore*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
103

SOLUTION If there are more than two processes and context & switching processes is disabled in P then this implementation doesnt work properly and cant synchronize the processes. Hence (A) is correct option. Question. 29 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 4way set associative. The minimum size of the TLB tag is (A)11bits SOLUTION TLB has 128 page table enteries, each page table would have. 64 bits i.e. 32 +32 virtual addresses. So total memory required. 27*26 But 4 way set associative. 27*26/22 = 211 So 11 bits are required. Hence (A) is correct option. Question. 30 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 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
104

(B) 13bits

(C) 15bits

(D) 20bits

SOLUTION Since both virtual and physical memory has 32 bit addresses, so there is no need for address translation hardware is required. Hence (C) is correct option. Question. 31 Consider three processes (process id 0,1,2, respectively) with compute time bursts 2,4, and 8 time units. All processes arrive at time zero. Consider the longest remaining time first (LRTF) scheduling algorithm. In LRTF ties are broken by giving priority to the process with the lowest process id. The average turn around time is (A) 13 units (B) 14 units (C) 15 units (D) 16 units

## So we draw Gantt chart for scheduler

At t = 0 longest remaining time for P2 At t = 4 remaining times for both P1 & P2 is 4 so P1 is given priority. At t = 8 remaining time for P0P1 & P2 is 2. P0 is given priority & cyclically done till t = 14. Process P0 P1 P2 TAT 12 0 = 12 13 0 = 13 14 0 = 14 39/3=13 units

## Hence (A) is correct option. Question. 32

105

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 get blocked on I/O or when the running process finishes its compute burst. Assume that all I/O operations can be overlapped as much as possible. For what percentage of time does the CPU remain idle? (A) 0% SOLUTION Process 2 3 First I/O 2 4 6 Computation 7 14 21 Second I/O 1 2 3 Total 10 20 30 (B) 10.6% (C) 30.0% (D) 89.4%

## Since I/0 can be done parallely. Gantt chart

Total time taken = 51 units CPU has to wait = 6 units =(6/51)*100 =10.6% Hence (B) is correct option.

Question. 33
106

Consider the following snapshot of a system running n processes. Process i is holding xi instances of a resource R, for 1in. Currently, all instances of R are occupied. Further, for all i, process i has placed a request for an additional y, 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) < maxkp,q yk (B) xp+xq maxkp,q yk (C) min(xp,xq) < 1 (D) min(xp,xq)>1 SOLUTION Here option (B) is that min (xp,xq) < maxk p,q yk Means the min no. of resources allocated should be less than the maximum number of resources required by any process other than p & q It prevent from deadlock. Hence (B) is correct option. Data for Q. 34 & 35 are given below. 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 the 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 variable 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. Question. 34
107

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 invocations are used in immediate succession (C)Lines 6 to 10 need not be inside a critical section (D)The barrier implementation is correct if there are only two processes instead of three

SOLUTION This barrier implementation is to keep track of arrival & completion of processes in system, by incrementing no. of process arrived & left. This implementation may lead to deadlock if two barrier functions invocations are used is immediate sessions. SinceV(s) in first invocation at line 3 removes 1-3 from critical section bring 5-11 in critical section at line 7. Hence (B) is correct option. Question. 35 Which one of the following rectifies the problem in the implementation? (A)lines 6 to 10 are simply replaced by process_arrived (B)At the beginning of the barrier the first process to enter the barrier waits until process_arrived becomes zero before proceeding to execute P(S) (C)Context switch is disabled at the beginning of the barrier and re-enabled at the end. (D)The variable process_left is made private instead of shared SOLUTION To rectify the barrier function at the beginning of the functions the first process which inters the function waits until process arrived becomes zero before executing P(s). This removes any deadlock situation. Hence (B) is correct option. YEAR 2007 Question. 36 Group-1 contains some CPU scheduling algorithms and group-2 contains some applications.
108

Match entries in Group-1 entries in Group-2 Group-1 P. Gang Scheduling Q. Rate Monotonic Scheduling R. Fair Share Scheduling (A)P-3 Q-2 R-1 SOLUTION Rate monotonic scheduling is for real time processes, Gang scheduling is used to schedule group of program threads and fair share scheduling is a scheduling which guarantees a fair share of CPU burst to every competing process. Hence (A) is correct option. Question. 37 Consider the following statements about user level threads and kernel level threads. Which one of the following statements is FALSE?
(A)Context switch time is longer for kernel level threads than for user level threads (B)User level threads do not need any hardware support (C)Related kernal level thread can be scheduled on different processors in a multiprocessor system (D) Blocking one kernel level thread blocks all related threads

Group-2 1.Guaranteed Scheduling 2. Real-time scheduling 3.Thread Scheduling (D) P-1 Q-3 R-2

## (C) P-2 Q-3 R-1

SOLUTION Threading a method of executing small sub processes instead of single big process. This prevents thread from blocking. So blocking of one kernel level thread doesnt block other related threads, they are unaffected. So (D) is false. Hence (D) is correct option. Question. 38 An operating system uses Shortest Remaining Time first (SRT) process scheduling algorithm. Consider the arrival times and execution times for the following processes Process P1 P2 P3 P4 Execution Time 20 25 10 15 Arrival Time 0 15 30 45
109

What is the total waiting time for process P2? (A) 5 SOLUTION Gantt chart for the processes. (B) 15 (C) 40 (D) 55

P2 came at t = 15 Scheduled first time at t = 20 wait = 5. Wait between t = 30 & t = 40 due to short remaining time of new process P3. Wait now = 5 +10 = 15 Then complete at t = 55 Hence (B) is correct option.

Question. 39 A virtual memory system uses first In First Out (FIFO) page replacement policy and allocates a fixed number of frames to a process. Consider the following statements: P:Increasing the number of page frames allocated to a process sometimes increases the page fault rate. Q:Some program do not exhibit locality of reference.
Which one of the following is TRUE? (A)Both P and Q are ture, and Q is the reason for P (B)Both P and Q are true, but Q is not the reason for P (C)P is false, but Q is true (D)Both P and Q are false

SOLUTION Due to Beladys Anomaly, increasing the number of page frames allocated to a process sometimes increase the page fault rate so P is true. Also some program do not exhibit locality of reference, so both are true but Q is not reason for P. Hence (B) is correct option.
110

Question. 40 A single processor system has three resource types X,Y, and Z, which are shared by three processes. There are 5 units of each resource type. Consider the following scenario, where the column alloc denotes the number of units of each resource type allocated to each process, and the column request denotes the number of units of each resource type requested by a process in order to complete execution. Which of these processes will finish LAST? alloc XYZ P0 121 P1 201 P2 221 (A)P0 (B)P1 request XYZ 103 012 120 (C)P2 (D)None of the above,

since the system is in a deadlock SOLUTION Initially. Process P0 P1 P2 Allow XYZ 121 121 221 Request/need XYZ 103 012 120 Available XYZ 012

Here looking at available resources, only need of P1 can be completed. So P1 will execute & free 2 0 1 so now available XYZ = 203. This is need for P0 so at second no. P0 will execute & free XYZ = 121 so available 3 2 4 & in the end need of P2 is fulfilled. Hence (C) is correct option. Question. 41 Two processes, P1 and P2, need to access a critical section of code. Consider the following synchronization construct used by the processes: /* P1 */ /*P2*/ while (true) { while (true) { wants1=true; wants2 = true; while(wants2==true); while (wants1 == true); /* Critical /* Critical
111

Section

Section

*/ */ wants 1 = false; wants 2 = false; } } /* Remainder section*/ /*Remainder section*/ Here, wants 1 and wants 2 are shared variables, Which are initialized to false. Which one of the following statements is TRUE about the above construct?
(A)It does not ensure mutual exclusion. (B)It does not ensure bounded waiting. (C)It requires that processes enter the critical section in strict alternation. (D)It does not prevent deadlocks, but ensures mutual exclusion

SOLUTION If P1 make wants 1 = true then P2 goes in critical section & vice versa so both together are implementing mutual exclusion but. Since both are accessing wants 1 & wants 2 concurrently 4 wants 1 is first captured by P1 so P2 will wait & P2 captures want 2 so P1 will have to wait. So a definite deadlock. Hence (D) is correct option. Data for Q. 42 & 43 are given below. A process has been allocated 3 page frames. Assume that none of the pages of the process are available in the memory initially. The process makes the following sequence of page references (reference string): 1,2,1,3,7,4,5,6,3,1. Question. 42 If optimal page replacement policy is used, how many page faults occur for the above reference string? (A) 7 SOLUTION Reference string 1, 2, 1, 3, 7, 4, 5, 6, 3, 1 Using optimal replacement policy, we will replace that page in memory which either will not be used or latest used in future. (B)8 (C) 9 (D)10

112

*denotes page fault So no. of page faults are 7. Hence (A) is correct option. Question. 43 Least Recently Used (LRU) page replacement policy is a practical approximation to optimal page replacement. For the above reference string, how many more page faults occur with LRU than with the optimal page replacement policy? (A) 0 SOLUTION Instead of optimal policy if we use LRU then we dont have future knowledge but we replace that page in memory which has been recently used in past. Order 1, 2,1, 3, 7, 4, 5, 6, 3,1 (B)1 (C) 2 (D)3

*denotes page faults. In this case no. of page fault = 9 In optimal strategy = 7 Difference = 9 7 = 2 Hence (C) is correct option. 113

YEAR 2008 Question. 44 Which of the following system calls results in the sending of SYN packets? (A) socket SOLUTION SYN packets are used for synchronization between sender & receiver, these packets are sent by sender during connect system call for synchronous connection. Hence (D) is correct option. Question. 45
The data block of a very large file in the Unix file system are allocated using (A) Contiguous allocation (B) Linked allocation (C) indexed allocation (D) an extension of indexed allocation

(B)bind

(C) listen

(D)connect

SOLUTION Generally a large file system for UNIX OS use indexed allocation, but for very large systems an extension of indexed allocation i.e. ext 2, ext 3 are used. Hence (D) is correct option. Question. 46 The P and V operations on counting semaphores, where s is a counting ewmaphore, are defined as follows: P(s);s = s 1; If s < 0 then wait; V(s): s = s +1; If s <= 0 then wakeup a process waiting on s; Assume that Pb and Vb the wait and signal operations on binary semaphores are provided. Two binary semaphores Xb and Yb are used to implement the semaphore operations P(s) and V(s) as follows: P( s ): Pb( Xb ); s = s-1; if( s <0 ) {
114

Vb( Xb ); Pb( Yb ); } else Vb ( Xb ); V( s ): Pb( Xb ); s = s+1; if( s <= 0 ) Vb( Yb ); Vb( Xb ); The initial values of Xb and Yb are respectively (A) 0 and 0 SOLUTION Xb & Yb are binary semaphores used to implement mutual exclusion here. So when Xb is 1 Yb should be zero so only 1 code between the two could run. Since Pb(Xb) module implementing wait process so Xb should be 1. Pb(Yb) implementing signal s = s +1 So Yb should be 0 initially. Hence (C) is correct option. Question. 47 Which of the following statements about synchronous and asynchronous I/O is NOT true?
(A) An ISR is invoked on completion of I/O in synchronous I/O but not in asynchronous I/O (B)In both synchronous and asynchronous I/O an ISR (Interrupt Serive Routine) is invoked after completion of the I/O (C) A process making a synchronous I/O cal waits until I/O is complete, but a process making an asynchronous I/O call does not wait for completion of the I/O (D) In the case of synchronous I/O, the process waiting for the completion of I/O is woken up by the ISR that is invoked afterr the completion of I/O

(B)0 and 1

(C) 1 and 0

(D)1 and 1

SOLUTION For the completion of I/0 an interrupt should be generated for CPU in case of both synchronous & asynchronous I/0 and this ISR call is before them. So CPU can switch to I/0. Hence (B) is correct option. Question. 48 Which of the following is NOT true of deadlock prevention and deadlock avoidance schemes?
115

(A) In deadlock prevention, the request for resources is always granted if the resulting state is safe (B) In deadlock avoidance, the request for resources is always granted if the resulting state is safe (C) Deadlock avoidance is less restrictive than deadlock prevention (D) Deadlock avoidance requires knowledge of resource requirements a priori

SOLUTION Both deadlock prevention, & avoidance allocate resources if the resulting state is safe state so option (A) & (B) are tree. The difference in both schemes is that in avoidance we know the requirement a prior. But Deadlock avoidance is less restrictive than prevention is false. Hence (C) is correct option. Question. 49 A process executes the following code for(i = 0;i < n;i ++) fork(); The total number of child processes created is (A) n SOLUTION The loop is called for n times. The first process is parent process so this should not be counted in child process. But after that every child process has its own child created so after every loop. 20,2',........2n total threads. But subtracting the parent. Hence (B) is correct option. (B)2n-1 (C) 2n (D)2n+1-1

Question. 50 A processor uses 36 bit physical addresses and 32 bit virtual addresses, with a page frame size of 4 Kbytes. Each page table entry is of size 4 bytes. A three level page table is used for virtualto-physical address translation, where the virtual address is used as follows bits 30-31 are used to index into the first level page table, bits 21-29 are used to index into second level page table bits 12-20 are used to index into third level page table bits 0-11 are used as offset within the page

The number of bits required for addressing the next level page table(or page frame) in the page table entry of the first, second and third level page table are respectively
116

(B)24,24 and 24

## (D) 25,25 and 24

SOLUTION
Total address single = 36 bit First level no. of bits = 2*12 = 24 bits Second level = 4*6 = 24 bits Third level = 8*3 = 24 bits Hence (B) is correct option.

YEAR 2009 Question. 51 Consider a system with 4 type of resources R1 (3 units), R2 (2 units), R3 (3 units), R4 (4units). A non-preemptive resource allocation policy is used. At any give instance, a request is not entertained if it cannot be completely satisfied. Three processes P1, P2, P3 request the resources as follows if executed independently.

Which one of the following statements is TRUE if all three processes run concurrently starting at time t = 0 ? (A)All processes will finish without any deadlock (B)Only P1 and P2 will be in deadlock (C)Only P1 and P3 will be in deadlock (D)All three processes will be in deadlock SOLUTION Total resources = 3 2 3 2
117

Time 0 1 2 3 4 5 6 7 8 9 10

Process 1Process 2Process 3Available 1234 1234 1234 1234 0200 0020 0001 3011 0210 0020 0001 3001 0210 0021 2001 1000 0210 0021 2001 1000 0210 1021 2001 0000 1110 1021 0001 1100 1110 1011 0001 1110 1100 1011 0101 1020 1100 0000 0111 2021 1102 0000 0000 2130 0000 0000 0000 3232

All process computed without deadlock Hence (A) is correct option. Question. 52 In which of the following page replacement policies, Beladys anomaly may occur ? (A) FIFO SOLUTION Beladys anomaly is a properly of FIFO page replacement policy in which the no. of page faults increases even if the no. of page frames are increased in some cases. Hence (A) is correct option. Question. 53 The essential content(S) in each entry of a page table is/are
(A)virtual page number (B)page frame number (C)Both virtual page number and page frame number (D)access right information

(B)Optimal

(C) LRU

(D)MRU

SOLUTION
A page table is in main memory which mop a page frame to a virtual memory page. So essential content is page frame number Hence (B) is correct option.

118

Question. 54 Consider a disk system with 100 cylinders. The requests to access the cylinders occur in following sequence : 4, 34, 10, 7, 19, 73, 2, 15, 6, 20 Assuming that the head is currently at cylinder 50, what is the time taken to satisfy all requests if it takes 1 ms to move from one cylinder to adjacent one and shortest seek time first policy is used? (A) 95ms SOLUTION Arranging in order. (B) 119ms (C) 233ms (D) 276ms

Total = 16 +14 +1 +4 +5 +3 +1 +2 +2 +71 = 119 ms Hence (B) is correct option. Question. 55 In the following process state transition diagram for a uniprocessor system, assume that there are always some processes in the steady state : Now consider the following statements : I. If a process makes a transition D, it would result in another process making transition A immediately
119

## II. III. IV.

A process P2 in blocked state can make transition E while another process P1 is in running state The OS uses non-preemptive scheduling The OS uses non-preemptive scheduling

## Which of the above statement are TRUE ? (A) I and II SOLUTION

IIs not necessary that a new process enters immediately. IIIs true different process can be in different states one is ready and another in running state. IIIIs also correct since if one blocked it stop running so other can run. IV Is not correct. Hence (C) is correct option.

## (C) II and III

(D) II and IV

Question. 56 The enter_CS( ) and leave_CS( ) functions to implement critical section of a process are realized using test and set instruction as follows : Void enter_cs(X) { while (test-and-set)(X)) : } Void leave_CS(X) { X=0; } In the above solution, X is a memory location associated with the CS and is initialized to 0. Now consider the following statements I. II. III. IV. The above solution to CS problem is deadlock-free II The solution is starvation free The processes enter CS in FIFO order More than one process can enter CS at the same time

Which of the above statements are TRUE (A) I only SOLUTION I Is true since X is initialized to zero, this cause only 1 process to enter into critical so no deadlock.
120

(B) I and II

## (C) II and III

(D) IV only

II & III

Are false, other process which doesnt capture X will wait so ultimately starve.

IV

## Since I true so it is false.

Hence (A) is correct option. Question. 57 A multilevel page table is preferred in comparison to a single level page table for translating virtual address to physical address because (A) It reduces the memory access time to read or write and memory location (B) It helps to reduce the size of page table needed to implement the virtual address space of a process (C) If is required by the translation look aside buffer (D) If helps to reduce the number of page faults in page replacement algorithms. SOLUTION Single level page table is not preferred since it requires the number of page table entries equal to the number of virtual memory addresses, but a multilevel page table has smaller number of entries so reduce the size of page table needed. Hence (B) is correct option. YEAR 2010 Question. 58 Consider the methods used by processes P1 and P2 for accessing their critical sections whenever needed, as given below. The initial values of shared boolean variables S1 and S2 are randomly assigned. Method used by P1 Method used by P2
While(S1= = S2) Critical Section S1= S2; While(S1!= S2) Critical Section S2= not(S1);

## While one of the following statements describes properties achieved?

(A)Mutual exclusion nut nor progress (B)Progress but not mutual exclusion (C)Neither mutual exclusion nor progress 121

## (D)Both mutual exclusion and progress

SOLUTION Method used by P1 & P2 enters into critical section when S1 = S2 & S1! = S2 respectively, since both are opposite conditions so mutual exclusion is there, but if P1's while loop true then it will always be true & in P2 if while loop true it would run infinitely so no progress. Hence (A) is correct option. Question. 59 A system uses FIFO policy for page replacement. It has 4 page frames with no pages loaded to begin with. The system first accesses 100 distinct pages in some order and then accesses the same 100 pages but now in the reverse order. How many page faults will occur ? (A) 196 SOLUTION In FIFO page replacement policy, the pages which entered first are replaced first so for first 100 accesses, 100 page faults will occur. Now in memory there are last 4 pages 97, 98, 99 & 100th page. So during reverse access there 4 pages would not create any page fault & other 97 page faults. (B) 192 (C) 197 (D) 195

So total 100 +96 = 196 page faults. Hence (A) is correct option. Question. 60 Which of the following statements are true ? I. II. III. (A) I only Shortest remaining time first scheduling may cause starvation Preemptive scheduling may cause starvation Round robin in better than FCFS in terms of response time (B) I and III only (C) II and III only (D) I, II and III

SOLUTION
I. SRIF scheduling may cause starvation since the processes which require large CPU burst periods would have to wait. 122

II.

Generally preemptive scheduling doesnt cause starvation but in some cases, it may cause

starvation when one process doesnt block due to I/O so others have to wait. III. It is quite obvious that due to preemption involvement round orbit is better than FCFS, in

## case of response time.

All are true Hence (D) is correct option. Question. 61 The following program consists of 3 concurrent processes and 3 binary semaphores. The semaphores are initialized as S0 = 1, S1 = 0, S2 = 0 Process P0
while( true ){ wait ( S0 ); print 0 release ( S1 ); release ( S2 ); }

Process P1
wait ( S1 ); release ( S0 );

Process P2
wait ( S2 ); release ( S0 );

How many times will process P0 print 0? (A) At least twice once SOLUTION
Let us see what will happen initially S0 = 1, S1 = 0 S2 = 0 so P1 & P2 will wait & P0 runs & make S0 = 0 wait decrements semaphore by 1 & release increments if by 1. So after P0's 1st run S1 = 1 & S2 = 1 0 is printed Now P1 & P2 can run & make S1 = 0, S2 = 0 but both increments S0 = 1 again. So P0 again starts and print '0' so this would continue again & again. So '0' will be printed at least twice. Hence (A) is correct option.

## (C) Exactly thrice

(D) Exactly

Question. 62 A system has n resources R0..Rn-1, and k processes P0..Pk-1.The implementation of the resource request logic of each process Pi, is as follows:
if (i%2==0){ 123

if(i<n)request Ri; if(i+2<n) request Ri+2; } else { if (i<n) request Rn-i ; if (i+2<n) request Rn-i-2; }

In which one of the following situations is a deadlock possible ? (A) n=40, k=26 SOLUTION
Allotment of resources would be successful to all cases but in option (B) where n = 21 & k = 12. Let use take i = 10 So for P10 only R10 can be allotted whereas for P11 odd case (else). R2111 i.e R10 can only be allotted. This is an conflict. Hence (B) is correct option.

## DATABASE MANAGEMENT SYSTEMS

1) Which of the following statements are TRUE about an SQL query? (GATE 2012) P: An SQL query can contain a HAVING clause even if it does not a GROUP BY clause Q: An SQL query can contain a HAVING clause only if it has a GROUP BY clause R: All attributes used in the GROUP BY clause must appear in the SELECT clause S: Not all attributes used in the GROUP BY clause need to apper in the SELECT clause (A) P and R (B) P and S (C) Q and R (D) Q and S Answer (B) P is correct. HAVING clause can also be used with aggregate function. If we use a HAVING clause without a GROUP BY clause, the HAVING condition applies to all rows that satisfy the search condition. In other words, all rows that satisfy the search condition make up a single group. S is correct. To verify S, try following queries in SQL.
CREATE TABLE temp ( id INT, name VARCHAR(100) ); INSERT INSERT INSERT INSERT INTO INTO INTO INTO temp temp temp temp VALUES VALUES VALUES VALUES (1, (2, (3, (4, "abc"); "abc"); "bcd"); "cde");

124

## SELECT Count(*) FROM temp GROUP BY name;

Output:
count(*) -------2 1 1

2) Given the basic ER and relational models, which of the following is INCORRECT? (GATE 2012) (A) An attributes of an entity can have more that one value (B) An attribute of an entity can be composite (C) In a row of a relational table, an attribute can have more than one value (D) In a row of a relational table, an attribute can have exactly one value or a NULL value Answer (C) The term entity belongs to ER model and the term relational table belongs to relational model. A and B both are true. ER model supports both multivalued and composite attributes (C) is false and (D) is true. In Relation model, an entry in relational table can can have exactly one value or a NULL.

3) Suppose (A, B) and (C,D) are two relation schemas. Let r1 and r2 be the corresponding relation instances. B is a foreign key that refers to C in r2. If data in r1 and r2 satisfy referential integrity constraints, which of the following is ALWAYS TRUE? (GATE 2012)

Answer (A) B is a foreign key in r1 that refers to C in r2. r1 and r2 satisfy referential integrity constraints. So every value that exists in column B of r1 must also exist in column C of r2.

125

4) Which of the following is TRUE? (GATE 2012) (A) Every relation in 2NF is also in BCNF (B) A relation R is in 3NF if every non-prime attribute of R is fully functionally dependent on every key of R (C) Every relation in BCNF is also in 3NF (D) No relation can be in both BCNF and 3NF Answer (C) BCNF is a stronger version 3NF. So every relation in BCNF will also be in 3NF. 5) Consider the following transactions with data items P and Q initialized to zero:
T1: read (P) ; read (Q) ; if P = 0 then Q : = Q + 1 ; write (Q) ; T2: read (Q) ; read (P) ; if Q = 0 then P : = P + 1 ; write (P) ;

Any non-serial interleaving of T1 and T2 for concurrent execution leads to 2012) (A) A serializable schedule (B) A schedule that is not conflict serializable (C) A conflict serializable schedule (D) A schedule for which a precedence graph cannot be drawn Answer (B) Two or more actions are said to be in conflict if: 1) The actions belong to different transactions. 2) At least one of the actions is a write operation. 3) The actions access the same object (read or write).

(GATE

The schedules S1 and S2 are said to be conflict-equivalent if the following conditions are satisfied: 1) Both schedules S1 and S2 involve the same set of transactions (including ordering of actions within each transaction). 2) The order of each pair of conflicting actions in S1 and S2 are the same. A schedule is said to be conflict-serializable when the schedule is conflict-equivalent to one or more serial schedules. In the given scenario, there are two possible serial schedules: 1) T1 followed by T2 2) T2 followed by T1. In both of the serial schedules, one of the transactions reads the value written by other
126

transaction as a first step. Therefore, any non-serial interleaving of T1 and T2 will not be conflict serializable.

6) Consider the following relations A, B, C. How many tuples does the result of the following relational algebra expression contain? Assume that the schema of A U B is the same as that of A. (GATE 2012)

Table A Id Name Age ---------------12 Arun 60 15 Shreya 24 99 Rohit 11 Table B Id Name Age ---------------15 Shreya 24 25 Hari 40 98 Rohit 20 99 Rohit 11 Table C Id Phone Area ----------------10 2200 02 99 2100 01

## (A) 7 (B) 4 (C) 5 (D) 9 Answer (A)

Result of AUB will be following table Id Name Age ---------------12 Arun 60 15 Shreya 24 99 Rohit 11 25 Hari 40 98 Rohit 20 The result of given relational algebra expression will be

127

Id Name Age Id Phone Area --------------------------------12 Arun 60 10 2200 02 15 Shreya 24 10 2200 02 99 Rohit 11 10 2200 02 25 Hari 40 10 2200 02 98 Rohit 20 10 2200 02 99 Rohit 11 99 2100 01 98 Rohit 20 99 2100 01

7) Consider the above tables A, B and C. How many tuples does the result of the following SQL query contains? (GATE 2012)
SELECT A.id FROM A WHERE A.age > ALL (SELECT B.age FROM B WHERE B. name = "arun")

(A) 4 (B) 3 (C) 0 (D) 1 Answer (B) The meaning of ALL is the A.Age should be greater than all the values returned by the subquery. There is no entry with name arun in table B. So the subquery will return NULL. If a subquery returns NULL, then the condition becomes true for all rows of A So all rows of table A are selected. 8. Consider a relational table with a single record for each registered student with the following attributes. 1. Registration_Number:< Unique registration number for each registered student 2. UID: Unique Identity number, unique at the national level for each citizen 3. BankAccount_Number: Unique account number at the bank. A student can have multiple accounts or joint accounts. This attributes stores the primary account number 4. Name: Name of the Student 5. Hostel_Room: Room number of the hostel Which of the following options is INCORRECT? (GATE 2011) (A) BankAccount_Number is a candidate key (B) Registration_Number can be a primary key (C) UID is a candidate key if all students are from the same country (D) If S is a superkey such that S UID is NULL then S UID is also a superkey

128

Answer (A) A Candidate Key value must uniquely identify the corresponding row in table. BankAccount_Number is not a candidate key. As per the question A student can have multiple accounts or joint accounts. This attributes stores the primary account number. If two students have a joint account and if the joint account is their primary account, then BankAccount_Number value cannot uniquely identify a row.

9) Consider a relational table r with sufficient number of records, having attributes A1, A2,, An and let 1 <= p <= n. Two queries Q1 and Q2 are given below.

The database can be configured to do ordered indexing on Ap or hashing on Ap. Which of the following statements is TRUE? (GATE 2011) (A) Ordered indexing will always outperform hashing for both queries (B) Hashing will always outperform ordered indexing for both queries (C) Hashing will outperform ordered indexing on Q1, but not on Q2 (D) Hashing will outperform ordered indexing on Q2, but not on Q1. Answer (C) If record are accessed for a particular value from table, hashing will do better. If records are accessed in a range of values, ordered indexing will perform better. See this for more details.

## 10) Database table by name Loan_Records is given below.

Borrower Ramesh Suresh Mahesh Bank_Manager Sunderajan Ramgopal Sunderajan Loan_Amount 10000.00 5000.00 7000.00

## What is the output of the following SQL query?

SELECT Count(*) FROM ( (SELECT Borrower, Bank_Manager FROM Loan_Records) AS S NATURAL JOIN (SELECT Bank_Manager, Loan_Amount FROM Loan_Records) AS T );

(GATE 2011)

129

## Answer (C) Following will be contents of temporary table S

Borrower Bank_Manager -------------------------Ramesh Sunderajan Suresh Ramgqpal Mahesh Sunderjan

## Following will be contents of temporary table T

Bank_Manager Loan_Amount --------------------------Sunderajan 10000.00 Ramgopal 5000.00 Sunderjan 7000.00

Following will be the result of natural join of above two tables. The key thing to note is that the natural join happens on column name with same name which is Bank_Manager in the above example. Sunderjan appears two times in Bank_Manager column, so their will be four entries with Bank_Manager as Sunderjan.
Borrower Bank_Manager Load_Amount -----------------------------------Ramesh Sunderajan 10000.00 Ramesh Sunderajan 7000.00 Suresh Ramgopal 5000.00 Mahesh Sunderajan 10000.00 Mahesh Sunderajan 7000.00

11) the table at any point in time. Using MX and MY, new records are inserted in the table 128 times with X and Y values being MX+1, 2*MY+1 respectively. It may be noted that each time after the insertion, values of MX and MY change. What will be the output of the following SQL query after the steps mentioned above are carried out? (GATE 2011)
SELECT Y FROM T WHERE X=7;

(A) 127 (B) 255 (C) 129 (D) 257 Answer (A)
X Y ------1 1

130

## 2 3 3 7 4 15 5 31 6 63 7 127 ...... ......

12) A relational schema for a train reservation database is given below. Passenger (pid, pname, age) Reservation (pid, class, tid)
Table: Passenger pid pname age ----------------0 Sachin 65 1 Rahul 66 2 Sourav 67 3 Anil 69 Table : Reservation pid class tid --------------0 AC 8200 1 AC 8201 2 SC 8201 5 AC 8203 1 SC 8204 3 AC 8202

What pids are returned by the following SQL query for the above instance of the tables? (GATE 2010)
SLECT pid FROM Reservation , WHERE class AC AND EXISTS (SELECT * FROM Passenger WHERE age > 65 AND Passenger. pid = Reservation.pid)

(A) 1, 0 (B) 1, 2 (C) 1, 3 (S) 1, 5 Answer (C) When a subquery uses values from outer query, the subquery is called correlated subquery. The correlated subquery is evaluated once for each row processed by the outer query.

131

The outer query selects 4 entries (with pids as 0, 1, 5, 3) from Reservation table. Out of these selected entries, the subquery returns Non-Null values only for 1 and 3.

13) Which of the following concurrency control protocols ensure both conflict serialzability and freedom from deadlock? I. 2-phase locking II. Time-stamp ordering (GATE 2010) (A) I only (B) II only (C) Both I and II (D) Neither I nor II Answer (B) 2 Phase Locking (2PL) is a concurrency control method that guarantees serializability. The protocol utilizes locks, applied by a transaction to data, which may block (interpreted as signals to stop) other transactions from accessing the same data during the transactions life. 2PL may be lead to deadlocks that result from the mutual blocking of two or more transactions. See the following situation, neither T3 nor T4 can make progress.

Timestamp-based concurrency control algorithm is a non-lock concurrency control method. In Timestamp based method, deadlock cannot occur as no transaction ever waits.

14) Consider the following schedule for transactions T1, T2 and T3:

Which one of the schedules below is the correct serialization of the above? 2010) (A)T1 T3 T2

(GATE

132

## (B)T2 (C)T2 (D)T3

T1 T3 T1

T3 T1 T2

Answer (A) T1 can complete before T2 and T3 as there is no conflict between Write(X) of T1 and the operations in T2 and T3 which occur before Write(X) of T1 in the above diagram. T3 should can complete before T2 as the Read(Y) of T3 doesnt conflict with Read(Y) of T2. Similarly, Write(X) of T3 doesnt conflict with Read(Y) and Write(Y) operations of T2. Another way to solve this question is to create a dependency graph and topologically sort the dependency graph. After topologically sorting, we can see the sequence T1, T3, T2.

15) The following functional dependencies hold for relations R(A, B, C) and S(B, D, E): B A, A C The relation R contains 200 tuples and the rel ation S contains 100 tuples. What is the maximum number of tuples possible in the natural join R S (R natural join S) (GATE 2010) (A) 100 (B) 200 (D) 300 (D) 2000 Answer (A) From the given set of functional dependencies, it can be observed that B is a candidate key of R. So all 200 values of B must be unique in R. There is no functional dependency given for S. To get the maximum number of tuples in output, there can be two possibilities for S. 1) All 100 values of B in S are same and there is an entry in R that matches with this value. In this case, we get 100 tuples in output. 2) All 100 values of B in S are different and these values are present in R also. In this case also, we get 100 tuples. 16) Consider two transactions T1 and T2, and four schedules S1, S2, S3, S4 of T1 and T2 as given below: T1 = R1[X] W1[X] W1[Y] T2 = R2[X] R2[Y] W2[Y] S1 = R1[X] R2[X] R2[Y] W1[X] W1[Y] W2[Y] S2 = R1[X] R2[X] R2[Y] W1[X] W2[Y] W1[Y] S3 = R1[X] W1[X] R2[X] W1[Y] R2[Y] W2[Y] S1 = R1[X] R2[Y]R2[X]W1[X] W1[Y] W2[Y] Which of the above schedules are conflict-serializable? (GATE: 2009) (A) S1 and S2 (B) S2 and S3
133

(C) S3 only (D) S4 only Answer (B) There can be two possible serial schedules T1 T2 and T2 T1. The serial schedule T1 T2 has the following sequence of operations R1[X] W1[X] W1[Y] R2[X] R2[Y] W2[Y] And the schedule T2 T1 has the following sequence of operations. R2[X] R2[Y] W2[Y] R1[X] W1[X] W1[Y] The Schedule S2 is conflict-equivalent to T2 T1 and S3 is conflict-equivalent to T1 T2.

17) Let R and S be relational schemes such that R={a,b,c} and S={c}. Now consider the following queries on the database:

## IV) SELECT R.a, R.b FROM R,S WHERE R.c=S.c

Which of the above queries are equivalent? (A) I and II (B) I and III (C) II and IV (D) III and IV

(GATE: 2009)

Answer (A) I and II describe the division operator in Relational Algebra and Tuple Relational Calculus respectively. See Page 3 of this and slide numbers 9,10 of this for more details.

## 18) Consider the following relational schema:

Suppliers(sid:integer, sname:string, city:string, street:string) Parts(pid:integer, pname:string, color:string) Catalog(sid:integer, pid:integer, cost:real)

## Consider the following relational query on the above database:

SELECT S.sname FROM Suppliers S WHERE S.sid NOT IN (SELECT C.sid FROM Catalog C WHERE C.pid NOT IN (SELECT P.pid

134

## FROM Parts P WHERE P.color<> 'blue'))

Assume that relations corresponding to the above schema are not empty. Which one of the following is the correct interpretation of the above query? (GATE: 2009) (A) Find the names of all suppliers who have supplied a non-blue part. (B) Find the names of all suppliers who have not supplied a non-blue part. (C) Find the names of all suppliers who have supplied only blue parts. (D) Find the names of all suppliers who have not supplied only blue parts. Answer (B) The subquery SELECT P.pid FROM Parts P WHERE P.color<> blue gives pids of parts which are not blue. The bigger subquery SELECT C.sid FROM Catalog C WHERE C.pid NOT IN (SELECT P.pid FROM Parts P WHERE P.color<> blue) gives sids of all those suppliers who have supplied blue parts. The complete query gives the names of all suppliers who have not supplied a non-blue part

19) Assume that, in the suppliers relation above, each supplier and each street within a city has a unique name, and (sname, city) forms a candidate key. No other functional dependencies are implied other than those implied by primary and candidate keys. Which one of the following is TRUE about the above schema? (GATE: 2009) (A) The schema is in BCNF (B) The schema is in 3NF but not in BCNF (C) The schema is in 2NF but not in 3NF (D) The schema is not in 2NF Answer (A) The schema is in BCNF as all attributes depend only on a superkey (Note that primary and candidate keys are also superkeys). 20) Let R and S be two relations with the following schema R (P,Q,R1,R2,R3) S (P,Q,S1,S2) Where {P, Q} is the key for both schemas. Which of the following queries are equivalent? (GATE: 2008)

(A) Only I and II (B) Only I and III (C) Only I, II and III (D) Only I, III and IV
135

Answer (D) In I, Ps from natural join of R and S are selected. In III, all Ps from intersection of (P, Q) pairs present in R and S. IV is also equivalent to III because (R (R S)) = R S. II is not equivalent as it may also include Ps where Qs are not same in R and S.

## 21) Consider the following ER diagram.

(GATE: 2008)

The minimum number of tables needed to represent M, N, P, R1, R2 is (A) 2 (B) 3 (C) 4 (D) 5 Answer (A) Many-to-one and one-to-many relationship sets that are total on the many-side can be represented by adding an extra attribute to the many side, containing the primary key of the one side. Since R1 is many to one and participation of M is total, M and R1 can be combined to form the table {M1, M2, M3, P1}. N is a week entity set, so it can be combined with P.

22) Which of the following is a correct attribute set for one of the tables for the correct answer to the above question? (GATE: 2008) (A) {M1, M2, M3, P1} (B) {M1, P1, N1, N2} (C) {M1, P1, N1} (D) {M1, P1} Answer (A)

23) Consider the following relational schemes for a library database: Book (Title, Author, Catalog_no, Publisher, Year, Price) Collection (Title, Author, Catalog_no) with in the following functional dependencies:
136

I. Title Author --> Catalog_no II. Catalog_no --> Title Author Publisher Year III. Publisher Title Year --> Price

Assume {Author, Title} is the key for both schemes. Which of the following statements is true? (GATE: 2008) (A) Both Book and Collection are in BCNF (B) Both Book and Collection are in 3NF only (C) Book is in 2NF and Collection is in 3NF (D) Both Book and Collection are in 2NF only Answer (C) Table Collection is in BCNF as there is only one functional dependency Title Author > Catalog_no and {Author, Title} is key for collection. Book is not in BCNF because Catalog_no is not a key and there is a functional dependency Catalog_no > Title Author Publisher Year. Book is not in 3NF because non-prime attributes (Publisher Year) are transitively dependent on key [Title, Author]. Book is in 2NF because every non-prime attribute of the table is either dependent on the key [Title, Author], or on another non prime attribute. 24) Information about a collection of students is given by the relation studinfo(studId, name, sex). The relation enroll(studId, courseId) gives which student has enrolled for (or taken) that course(s). Assume that every course is taken by at least one male and at least one female student. What does the following relational algebra expression represent? (GATE: 2007)

(A) Courses in which all the female students are enrolled. (B) Courses in which a proper subset of female students are enrolled. (C) Courses in which only male students are enrolled. (D) None of the above Answer (B) The expression given in question does following steps in sequence. a) Select studids of all female students and selects all courseids of all courses. b) Then the query does a Cartesian Product of the above select two columns from different tables. c) Finally it subtracts enroll table from the result of above step (b). This will remove all the (studid, courseid) pairs which are present in enroll table. If all female students have registered in a courses, then this course will not be there in the subtracted result. So the complete expression returns courses in which a proper subset of female students are enrolled.
studinfo table studid name sex

137

-----------------------1 a Male 2 c Female 3 d Female enroll table studid courseid -----------------1 1 2 1 3 1 2 2 3 3 3 2 Result of step b studid courseid --------------------2 1 2 2 2 3 3 1 3 2 3 3 Result of step c studid courseid ------------------2 3

25) Consider the relation employee(name, sex, supervisorName) with name as the key. supervisorName gives the name of the supervisor of the employee under consideration. What does the following Tuple Relational Calculus query produce? (GATE: 2007)

(A) Names of employees with a male supervisor. (B) Names of employees with no immediate male subordinates. (C) Names of employees with no immediate female subordinates. (D) Names of employees with a female supervisor. Answer (C) The query selects all those employees whose immediate subordinate is male. In other words, it selects names of employees with no immediate female subordinates

26) Consider the table employee(empId, name, department, salary) and the two queries
138

Q1 ,Q2 below. Assuming that department 5 has more than one employee, and we want to find the employees who get higher salary than anyone in the department 5, which one of the statements is TRUE for any arbitrary employee table? (GATE: 2007)
Q1 : Select e.empId From employee e Where not exists (Select * From employee s where s.department = 5 and s.salary >=e.salary) Q2 : Select e.empId From employee e Where e.salary > Any (Select distinct salary From employee s Where s.department = 5)

(A) Q1 is the correct query (B) Q2 is the correct query (C) Both Q1 and Q2 produce the same answer. (D) Neither Q1 nor Q2 is the correct query Answer (D) Consider the following example table.
empid 1 2 3 4 name department salary a 4 90k b 5 30k c 5 50k d 5 80k

Q1 will give empid 1 Q2 will give empid 1, 3, 4 But the correct answer is 4

27) Which one of the following statements if FALSE? (GATE: 2007) (A) Any relation with two attributes is in BCNF (B) A relation in which every key has only one attribute is in 2NF (C) A prime attribute can be transitively dependent on a key in a 3 NF relation. (D) A prime attribute can be transitively dependent on a key in a BCNF relation. Answer (D)

28) Consider the following schedules involving two transactions. Which one of the following statements is TRUE? (GATE: 2007)

139

(A) Both S1 and S2 are conflict serializable. (B) S1 is conflict serializable and S2 is not conflict serializable. (C) S1 is not conflict serializable and S2 is conflict serializable. (D) Both S1 and S2 are not conflict serializable. Answer (C) S1 is not conflict serializable, but S2 is conflict serializable
Schedule S1 T1 T2 --------------------r1(X) r1(Y) r2(X) r2(Y) w2(Y) w1(X) The schedule is neither conflict equivalent to T1T2, nor T2T1. Schedule S2 T1 T2 --------------------r1(X) r2(X) r2(Y) w2(Y) r1(Y) w1(X) The schedule is conflict equivalent to T2T1.

29) 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. 2. 3. 4. 5. 6. 7. T1 T1 T1 T1 T2 T2 T2 start B old=12000 new=10000 M old=0 new=2000 commit start B old=10000 new=10500 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? (GATE: 2006)

(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. Answer (C) Once a transaction is committed, no need to redo or undo operations.
140

30) 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?

(GATE : 2006)

(A) All queries return identical row sets for any database (B) Query2 and Query4 return identical row sets for all databases but there exist databases for which Query1 and Query2 return different row sets. (C) There exist databases for which Query3 returns strictly fewer rows than Query2. (D) There exist databases for which Query4 will encounter an integrity violation at runtime. Answer (A) 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 xyz c1 abc c2 pqr c1 Table paid student amount ----------------abc 20000 xyz 10000 rst 10000 Output of Query 1 abc abc xyz Output of Query 2 abc xyz Output of Query 3

141

## abc xyz Output of Query 4 abc xyz

31) 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? (GATE: 2006) (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. Answer (C) 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.

142

## 32) The following functional dependencies are given:

AB CD, AF D, DE F, C G , F E, G A

Which one of the following options is false? (A)CF+ = {ACDEFG} (B)BG+ = {ABCDG} (C)AF+ = {ACDEFG} (D)AB+ = {ABCDFG}

(GATE: 2006)

Answer (C) Closure of AF or AF+ = {ADEF}, closure of AF doesnt contain C and G. Option (D) also looks correct. AB+ = {ABCDG}, closure of AB doesnt contain F. 33) Which one of the following statements about normal forms is FALSE? (GATE 2005) (a) BCNF is stricter than 3NF (b) Lossless, dependency-preserving decomposition into 3NF is always possible (c) Lossless, dependency-preserving decomposition into BCNF is always possible (d) Any relation with two attributes is in BCNF Answer (c) It is not always possible to decompose a table in BCNF and preserve dependencies. For example, a set of functional dependencies {AB > C, C > B} cannot be decomposed in BCNF. 34) The following table has two attributes A and C where A is the primary key and C is the foreign key referencing A with on-delete cascade.
A C ----2 4 3 4 4 3 5 2 7 2 9 5 6 4

The set of all tuples that must be additionally deleted to preserve referential integrity when the tuple (2,4) is deleted is: (GATE 2005) (a) (3,4) and (6,4) (b) (5,2) and (7,2) (c) (5,2), (7,2) and (9,5) (d) (3,4), (4,3) and (6,4) Answer (C) When (2,4) is deleted. Since C is a foreign key referring A with delete on cascade, all entries
143

with value 2 in C must be deleted. So (5, 2) and (7, 2) are deleted. As a result of this 5 and 7 are deleted from A which causes (9, 5) to be deleted.

35) The relation book (title, price) contains the titles and prices of different books. Assuming that no two books have the same price, what does the following SQL query list? (GATE 2005)
select title from book as B where (select count(*) from book as T where T.price > B.price) < 5

(a) Titles of the four most expensive books (b) Title of the fifth most inexpensive book (c) Title of the fifth most expensive book (d) Titles of the five most expensive books Answer (d) When a subquery uses values from outer query, the subquery is called correlated subquery. The correlated subquery is evaluated once for each row processed by the outer query. The outer query selects all titles from book table. For every selected book, the subquery returns count of those books which are more expensive than the selected book. The where clause of outer query will be true for 5 most expensive book. For example count (*) will be 0 for the most expensive book and count(*) will be 1 for second most expensive book. 36) Let r be a relation instance with schema R = (A, B, C, D). We define r1 = select A,B,C from r and r2 = select A, D from r. Let s = r1 * r2 where * denotes natural join. Given that the decomposition of r into r1 and r2 is lossy, which one of the following is TRUE? (GATE 2005) (a) s is subset of r (b) r U s = r (c) r is a subset of s (d) r * s = s Answer (c) Consider the following example with lossy decomposition of r into r1 and r2. We can see that r is a subset of s.
Table r A B C D --------------------------1 10 100 1000 1 20 200 1000 1 20 200 1001 Table r1

144

A B C -----------------1 10 100 1 20 200 Table r2 A D ----------1 1000 1 1001 Table s (natural join of r1 and r2) A B C D --------------------------1 10 100 1000 1 20 200 1000 1 20 100 1001 1 20 200 1001

37) Let E1 and E2 be two entities in an E/R diagram with simple single-valued attributes. R1 and R2 are two relationships between E1 and E2, where R1 is one-to-many and R2 is many-to-many. R1 and R2 do not have any attributes of their own. What is the minimum number of tables required to represent this situation in the relational model? (GATE 2005) (a) 2 (b) 3 (c) 4 (d) 5 Answer (c) The situation given can be expressed with following sample data.
E1 a b c E2 x y z R1 E1 a a b R2 E1 E2 x y z

E2

145

a a b

x y y

38) Consider a relation scheme R = (A, B, C, D, E, H) on which the following functional dependencies hold: {A>B, BC> D, E>C, D>A}. What are the candidate keys of R? (GATE 2005) (a) AE, BE (b) AE, BE, DE (c) AEH, BEH, BCH (d) AEH, BEH, DEH Answer (d) A set of attributes S is candidate key of relation R if the closure of S is all attributes of R and there is no subset of S whose closure is all attributes of R. Closure of AEH, i.e. AEH+ = {ABCDEH} Closure of BEH, i.e. BEH+ = {ABCDEH} Closure of DEH, i.e. DEH+ = {ABCDEH}

39) Let R1 (A, B, C) and R2 (D, E) be two relation schema, where the primary keys are shown underlined, and let C be a foreign key in R1 referring to R2. Suppose there is no violation of the above referential integrity constraint in the corresponding relation instances r1 and r2 . Which one of the following relational algebra expressions would necessarily produce an empty relation ? (GATE:2004) 1) D (r2 ) - C (r1 ) 2) C (r1 ) - D (r2 ) 3) D (r1 4) C (r1

C 1 D r2 ) C = Dr2)

Explanation: C is an attribute in R1 but D is a key in K 2 . So consider C (r1) D (r2) So the result of this query would be all those tuples which are in C (r1) but not in D (r2).Since D is a key so it has all the possible values of C . So difference would always be
146

empty.Hence( 2 ) is correct.

40) Consider the following relation schema pertaining to a students database: Student (rollno, name, address) Enroll (rollno, courseno, coursename) where the primary keys are shown underlined. The number of tuples in the Student and Enroll tables are 120 and 8 respectively. What are the maximum and minimum number of tuples that can be present in (Student * Enroll), where '*' denotes natural join ? (GATE: 2004) 1) 8, 8 2) 120, 8 3) 960, 8 4) 960, 120 Answer (1) Explanation: The boundary cases are when either all the tuples of Enroll table belong to one roll no. , so there can be at most 8 roll no & courses no. combinations or the other case is when all the tuples belong to different roll no. this also has 8 tuples. So (8,8) = (max, min) Hence (A) is correct option

41) Which of the following scenarios may lead to an irrecoverable error in a database system ? (GATE: 2003) 1) A transaction writes a data item after it is read by an uncommitted transaction 2) A transaction reads a data item after it is read by an uncommitted transaction 3) A transaction reads a data item after it is written by a committed transaction 4) A transaction reads a data item after it is written by an uncommitted transaction

147

42) The following SQL query select distinct al, a2,........., an from r1 , r2,........, rm where P For an arbitrary predicate P, this query is equivalent to which of the following relational algebra expressions GATE 2003 1. 2. 3. 4.

43) Relation R with an associated set of functional dependencies, F, is decomposed into BCNF. The redundancy (arising out of functional dependencies) in the resulting set of relations is (GATE: 2002) (a) Zero (b) More than zero but less than that of an equivalent 3NF decomposition (c) Proportional to the size of F+ (d) Indetermine Ans: solution (b) Explanation: Redundancy in BCNF is low when compared to 3NF. 44) With regard to the expressive power of the formal relational query languages, which of the following statements is true? (GATE: 2002) (a) Relational algebra is more powerful than relational calculus (b) Relational algebra has the same power as relational calculus.
148

(c) Relational algebra has the same power as safe relational calculus. (d) None of the above
SOLUTION

Expressive power is the capacity of formal query languages to express various query statements, so relational algebra is as powerful as relational calculus only if calculus is safe relational calculus.Hence (C) is correct option.

45) Consider a relation geq which represents greater than or equal to, that is, (x,y) geq only if yx. create table geq ( Ib integer not null ub integer not null primary key 1b foreign key (ub) references geq on delete cascade) Which of the following is possible if a tuple (x,y) is deleted? (GATE:2001) (a) A tuple (z,w) with z > y is deleted (b) A tuple (z,w) with z > x is deleted (c) A tuple (z,w) with w < x is deleted (d) The deletion of (x,y) is prohibited
SOLUTION

238

SOLUTION Consider the following circuit with initial state Q 0 = Q1 = 0. The D flipflops are positive edged triggered and have set up times 20 nanosecond and hold times 0. Consider the following timing diagrams of X and C ; the clock period of C $40 nanosecond. Which one is the correct plot of Y ? Figure Question. 3 The 2s complement representation of ( 539)10 is hexadecimal is (A) ABE (C) DE5 SOLUTION Binary of 539 = 1000011011 239 ## (B) DBC (D) 9E7 Binary :0010 0001 1011 2's comp :1101 1110 0101 Hexadecimal D E 5 (DES)16 Hence (C) is correct option. Question. 4 Consider the circuit shown below. The output of a 2:1 Mux is given by the function (ac ' + bc). Which of the following is true ? (A) f = x1' + x2 (C) f = x1x2 + x1' x2' SOLUTION Output of any 2:1 MUX = ac' + bc Here output of MUX 1. g = ax 1' + bx1 Output of MVX 2 (I) = gx 2' + x 1 x2 (J) = (ax 1' + bx 1) x 2' + x 1 x2 (K) = ax 1' x 2' + bx 1 x 2' + x 1 x2 Given a = 1, b = 0 (L) = x 1' x 2' + x 1 x2 Hence (C) is correct option. Question. 5 Consider the circuit given below the initial state Q 0 = 1,Q 1 = Q2 = 0. The state of the circuit is given by the value 4Q 2 + 2Q 1 + Q0 (B) f = x1' x2 + x1x2' (D) f = x1 + x2 240 Which one of the following is the correct state sequence of the circuit ? (A) 1, 3, 4, 6, 7, 5, 2 (C) 1, 2, 7, 3, 5, 6, 4 (B) 1, 2, 5, 3, 7, 6, 4 (D) 1, 6, 5, 7, 2, 3, 5 SOLUTION Initially Clk 1 2 3 4 5 6 Q0 1 0 1 1 1 0 0 Q1 0 1 0 1 1 1 0 Q2 0 0 1 0 1 1 1 Value 4Q 2 + 2Q 1 + Q0 1 2 5 3 7 6 4 ## Hence (B) is correct option. YEAR 2002 Question. 6 Minimum sum of product expression for f (w, x, y, z) shown in Karnaughmap below is 241 ## (A) xz + y' z (C) x' y + zx' SOLUTION ## (B) xz' + zx' (D) None of the above There are 2 quads possible xz' + x' z Hence (B) is correct option. Question. 7 The decimal value of 0.25 (E) is equivalent to the binary value 0.1 (F) is equivalent to the binary value 0.01 (G) is equivalent to the binary value 0.00111..... (H) cannot be represented precisely in binary. 242 SOLUTION Given decimal no. 0.25 Binary = ? .25 # 2 = .5 .5 # 2 = 1 (.01)2 Hence (B) is correct option. Question. 8 The 2s complement represent representation of the decimal value 15 is (A) 1111 (C) 111111 SOLUTION Given ( 15)10 Binary of 15 = (01111)2 2s complement of 15 would represent ( 15). 01111 (10001)2 Hence (D) is correct option. Question. 9 Sign extension is a step in (I) floating point multiplication (J) signed 16 bit integer addition (K) arithmetic left shift (L) converting a signed integer from one size to another. SOLUTION Sign extension is the operation in computer arithmetic of increasing no. of bits of a binary no., while preserving sign and value done by appending MSBs. In the floating point multiplication to bring the no. in desired no. of significant digits sign extension is done. Hence (A) is correct option. 243 ## (B) 11111 (D) 10001 Question. 10 In 2s complement addition, overflow (H) Relational algebra is more powerful than relational calculus (I) Relational algebra has the same power as relational calculus. (J) Relational algebra has the same power as safe relational calculus. (K) None of the above. SOLUTION In 2s complement addition, overflow occurs when the carries from sign bit & previous bit doesnt match. So overflow cant occur when a positive value is added to some negative value. Hence (B) is correct option. Question. 11 Consider the following logic circuit whose inputs are functions f1, f2, f3 and output is f Given that f1(x, y, z) = (0,1,3,5) f2(x, y, z) = (6,7), and f (x, y, z) = (1,4,5) f3 is (A) (1,4,5) (C) (0,1,3,5) SOLUTION f1 (x, y, z) = (0,1,3,5) (B) (6,7) (D) None of the above 244 ## = x' y' + y' z + x' z f2 (x, y, z) = (6,7) = xy f (x, y, z) = (1,4,5) = xy' + y' z f (x, y, z) = f1 f2 : f3 (I) f1 : f2 + f3 (J)xy (x' y' + y' z + x' z) + (xy' + y' z) f3 = xy' z + xy' z' + xy' z + x' y' z f3 = (1,4,5) Hence (A) is correct option. Question. 12 Consider the following multiplexor where 10, 11, 12, 13 are four data input lines selected by two address line combinations A1A0 = 00,01,10,11 respectively and f is the output of the multiplexor. EN is the Enable input. 245 The function f (x, y, z) implemented by the above circuit is (A) xyz' (C) x + y SOLUTION A1 A0 0 0 1 0 1 0 EN (MUX) work 1 0 1 do not (MUX) Work do not (B) xy + z (D) None of the above 1 1 0 So MUX is ENABLED only if A0 = 0 So output should have Z'. Consider xyz' option (A) A, A0 = 1 0 gives correct answer. Hence (A) is correct option. Question. 13 Let f (A, B) = A' + B. Simplified expression for function f (f (x + y, y), z) is (A) x' + z (B) xyz (C) xy' + z SOLUTION f (x + y, y) = (x + y)' + y & x + y + y f (f (x + y, y), z) = x + y + y + z & (x + y : y ) + z [(x + y) : y ] + z (D) None of the above 246 [xy + yy ] + z xy + z Hence (C) is correct option. Question. 14 What are the states of the Auxiliary Carry (AC) and Carry Flag (CY) after executing the following 8085 program ? MIV MIV H, L, 5DH 6BH H MOV A, ADD L ## (A) AC = 0 and CY = 0 (C) AC = 1 and CY = 0 SOLUTION ## (B) AC = 1 and CY = 1 (D) AC = 0 and CY = 1 Program is to add 2 nos kept in H & L, result of addition is stored in A. (5D) 16 + (6B)16 & is the carry so CY = 0 (I) is auxillary carry AC = 1 Hence (C) is correct option. Question. 15 The finite state machine described by the following state diagram x y and x stands for with A as starting state, where an arc label is 1-bit input and y stands for 2-bit output. 247 (A) Outputs the sum of the present and the previous bits of the input. (B) Outputs 01 whenever the input sequence contains 11 (C) Outputs 00 whenever the input sequence contains 10 (D) None of the above. SOLUTION Previous input 0(A) 0(A) 1(B) 1(B) 1(C) 1(C) Present i/p 0(A) 1(B) 0(A) 1(C) 1(C) 0(A) Output 00 01 01 10 10 01 So output is always sum of the present and previous bits of input. Hence (A) is correct option. YEAR 2003 Question. 16 Assuming all numbers are in 2s complement representation, which of the following number is divisible by 11111011? (A) 11100111 (C) 11010111 SOLUTION (B) 11100100 (D) 11011011 248 We cant judge the nos in 2s complement first we need to convert them in decimal Given no. 11111011"00000101=5 11100111 " 00011001 = 25 (A) 11100100 " 00011100 = 28 (B) 11010111 " 00101001 = 41 (C) 11011011 " 00100101 = 37 From all only option (A) is divisible by 5. Shortcut : To convert 2s complement no. directly into original binary, we should complement all the digits from MSB till the last one (1). Keep the last 1 from the LSB as it is. Observe in the example. Question. 17 The following is a scheme for floating point number representation using 16 bits. Let s, c and m be the number represented in binary in the sign, exponent, and mantissa fields respectively. Then the flouting point number represented id 2 9 e31 , if the exponent 111111 0 otherwise )( 1) (1 + m # 2 )2 What is the maximum difference between two successive real numbers representable in this system? (A) 240 (C) 222 SOLUTION e has 6 bits so max value can be 26 1 = 63 when e = 111111 But given e =Y 111111 So max e = 62 = 111110 Two consecutive number will have same exponent but difference in mantissa by 1. Difference would be ( 1)2 (1 + (m + 1)2 9)262 31 ( 1)2 (1 + m # 2 9)262 31 231 # 29 = 222 Hence (C) is correct option. Question. 18 A 1-input, 2-output synchronous sequential circuit behaves as follows. 249 ## (B) 29 (D) 231 Let zk , nk denote the number of 0s and 1s respectively in initial k bits of the input (zk + nk = k). The circuit outputs 00 until one of the following conditions holds. 1. nk nk = 2. In this case, the output at the k -th and all subsequency clock ticks is 10. 2. nk zk = 2. In this case, the output at the k -th and all subsequent clock ticks is 01. What in the minimum number of states required in the state transition graph of the above circuit? (A) 5 (B) 6 (C) 7 SOLUTION The sequential circuit has 3 variables to decide the state in which input & 2 inputs are present. Output for particular inputs decide states. i/p 0 0 0 0 1 1 1 1 op 1 0 0 1 1 0 0 1 1 op 2 0 1 0 1 0 1 0 1 State Intial nKzK=2 zKnK=2 Not applicable Initial nKzK=2 zKnK=2 is correct (D) 8 Using 3 bits we require 23 1 = 7 states here. Hence (C) is correct option. Question. 19 The literal count of a boolean expression is the sum of the number of times each literal appears in the expression. For example, the literal count of (xy + xz) is 4. What are the minimum possible literal counts of the product-of-sum and sum-of-product representations respectively of the function given by the following karnaugh map? Here, denotes dont care 250 ## (A) (11,9) (C) (9,10) SOLUTION ## (B) (9,13) (D) (11,11) ## Considering product of sum & sum of product separately. Sum of product = wy + w' y' + z' wx' + xyz' 12 34 567 8910 Literal count =10 Hence (C) is correct option. ## Product of sum = (y' + z')(z' + y)(w' + z') (x + z + w) Lateral count =9 In SOP the K-map is solved for 1 & POS K-map solved for 0 Question. 20 Consider the following circuit composed of XOR gates and non-inverting buffers. The non-inverting buffers have delays 1 = 2ns and 2 = 4ns as shown in the figure. both XOR gates and al wires have zero delay. Assume that all gate inputs, outputs and 251 wires are stable at logic level 0. If the following waveform is applied at input. A, how many transition (s) (change of logic levels) occur (s) at B during the interval from 0 to 10 ns? ## (A) 1 (C) 3 SOLUTION (B) 2 (D) 4 Due to delays S1 = 2 & S2 = 4 the transitions would occur at time 1, 2 & 4. Time Input (A) 0 I II III 1 2 4 1 1 1 0 Output (B) 0 0 0 1 Transition Transition Transition So total 3 transitions Hence (C) is correct option. YEAR 2004 Question. 21 The Boolean function x' y' + xy + x' y is equivalent to 252 ## (A) x' + y' (C) x + y' SOLUTION ## (B) x + y (D) x' + y x' y' + xy + xy' x'(y + y') + xy (A + A') = 1 x' + xy (A + AB) = (A + A) : (A + B) (x' + x) : (x' + y) 1 : (x' + y) x' + y Hence (D) is correct option. Question. 22 In an SR latch made by cross-coupling two NAND gates, if both S and R inputs are set to 0, then it will result in (A) Q = 0,Q' = 1 (B) Q = 1,Q' = 0 (C) Q = 1,Q' = 1 SOLUTION SR latch both S and R when 0 leads to invalid state. (D) Indeterminate states Transition table for SR flip flop. S R Q(Next state) ii 0 Invalid so Q=Q=1 change 0 1 1 1 0 0 1 1 previous state For S=R=0 Q=Q=1 253 ## Hence (C) is correct option. 254 Question. 23 If 73x (in base-x number system) is equal to 54, (in base-y number system), the possible values of x and y are (A) 8, 16 (C) 9, 13 SOLUTION (73)x = (54)y 7x + 3 = 5y + 4 (x', y) 7x + 3 8, 16 59 10, 12 73 9, 13 64 8, 11 59 Hence (D) is correct option. Question. 24 What is the result of evaluating the following two expressions using three-digit floating point arithmetic with rounding? (113.+111.)+7.51 113.+(111.+7.51) (A) 9.51 and 10.0 respectively (C) 9.51 and 9.51 respectively SOLUTION Expression 1 (113.0 + ( 111.) + 7.51 (113.0 111.0) + 7.51 2.0 + 7.51 9.51 10 rounded off Expression 2 113.0 + ( 111.0 + 7.51) 113.0 + ( 103.49) 113.0 103.00 10.0 rounded off Hence (D) is correct option 255 ## (B) 10, 12 (D) 8, 11 5y + 4 84 64 69 59 (B) 10.0 and 9.51 respectively (D) 10.0 and 10.0 respectively Question. 25 A circuit outputs a digit in the form of 4 bits. 0 is represented by 0000, 1 by 0001,...9 by 1001. A combinational circuit is to be diesigned which takes these 4 bits as input and outputs 1 if the digit$ 5, and 0 otherwise. If only AND, OR and NOT gates may be used, what is the minimum number of gates required? (A) 2 (B) 3 (C) 4 SOLUTION CKT takes 4 bits as the input so K-Map will have 4 variable so 16 options are available. (D) 5

1 digit = 5 0 otherwise Here for 0 to 4 we have 0 output, from 5 to 9 1 output & for 10 to 15 dont care. 1 octed & 2 pounds. a + bd + bc a + b (d + c) Two OR gates One AND gate Total 3 Hence (B) is correct option. Question. 26 Which are the essential prime implicates of the following Boolean function? f (a, b , c ) = a' c + ac ' + b ' c
256

257

## (D) ac' and bc'

f (a, b , c) = a' c + ac ' + b ' c Making min terms a' bc + a' b' c + abc ' + ab' c ' + a' b' c + ab' c Since b ' c gives no new term. So a' c & ac' are only essential prime implicants. Solution detailed method Tabulation method Since b ' c gives no new term. So a' c & ac' are only essential prime implicants. Solution detailed method Tabulation method f (a, b , c ) = /m(1,3,5,6,4) Figure Figure 3 & 6 have only 1 cross they are in a' c & ac' Question. 27 Consider the partial implementation fo a 2-bit counter using T flip flops following the sequence 0-2-31-0, as shown below

To complete the circuit, the input X should be (A) Q2' (C) (Q1 5 Q2)' SOLUTION Counter counts the no. of signal inversion change of states. Sequence input is 0 2 3 1 0 (B) Q2 + Q1 (D) Q1 5 Q2

258

Binary 00 10 11 01 00 to generate signals if we XOR gate then it outputs 1 if both are different. So output sequence would be. 0 1 0 1 0 & the sequence would be counted. So. X = Q 1 5 Q2 Hence (D) is correct option. Question. 28 A 4-bit carry look ahead adder, which adds two 4-bit numbers, is designed using AND, OR, NOT, NAND, NOR gates only. Assuming that all the inputs are available in both complemented and uncompensated forms and the delay of each gate is one time unit, what is the overall propagation delay of the adder? Assume that the carry network has been implemented using two-level AND-OR logic. (A) 4 time units (C) 10 time units SOLUTION Carry of any higher order bit is dependent upon previous order bit addition generated carry. C out = g 0 + p0 C in P3 P2 P1 P0 g 3 g 2 g 1 g0 c 3 c 2 c 1 c0 c3 g 3 + P3 g 2 + P3 P2 g 1 + | P3 P2 P1 g 0 + P3 P2 P2 P0 C in This is 4 bit look ahead adder equation total gate delay = 1+1+2+2 = 6 Hence (B) is correct option. Question. 29 Let A = 11111010 and B 0000 1010 be two 8-bit 2s complement numbers. Their product in 2s complement is (A) 1100 0100 (C) 1010 0101 SOLUTION A and B are in 2s complement form.
259

## (B) 1001 1100 (D) 1101 0101

A = 11111010 Binary = 00000110 = 6 2s complement represent ve number So A = 6 B = 00001010 MSB is 0 so +ve no. decimal 10. B = 10 A # B = 6 # 10 = 60 Binary of 60 = 00111100 2s complement 11000100 Hence (A) is correct option.

YEAR 2005

## Question. 30 Consider the following circuit.

Which one of the following is TRUE? (A) f is independent of X (C) f is independent of Z (B) f is independent of Y (D) None of X, Y, Z is redundant

260

SOLUTION

f =X:Y:Y:Z = X:Y+Y:Z = X:Y+Y:Z For redundant check we need to draw K map to min terms. XY (Z + Z ) + (X + X ) : YZ XYZ + XY Z + XYZ + X YZ

XY + YZ + XZ Hence (D) is correct option. Question. 31 The range of integers that can be represented by an a bit 2s complement number system is (A) 2 n 1 to (2n1 1) (C) 2n 1 to 2n1 SOLUTION n bit 2s complement system must have corresponding bit binary system. But to implement +ve & ve nos. Both we require MSB to be sign bit. So maximum magnitude can be 2n1 1 suppose we take n = 4.
261

## (B) (2 n 1 1) to (2n1 1) (D) (2 n 1 + 1) to (2n1 1)

Using 4 bits. 1 1 1 1,. . . . . .0 0 0 0, . . . . .01 1 1 7 +7 This would be the range. So (2 n1 1) to + (2 n1 1) Hence (B) is correct option. Question. 32 The hexadecimal representation of 6578 is (A) 1AF (B) D78 (C) D71 SOLUTION (657)8 = (?)16 Making binary S S= 0 0 010101111 (IAF) 16 A BBC Hence (A) is correct option. Question. 33 The switching expression corresponding to f (A, B, C , D) = /(1,4,5,9,11,12) is (A) BC' D' + A' C ' D + AB' D (C) ACD ' + A' BC' + AC' D' SOLUTION f (A, B, C , D) = /(1,4,5,9,11,12) Drawing K map for min terms. (B) ABC' + ACF + B' C ' D (D) A' BD + ACD ' + BCD' (D) 32F

262

BC D + A C D + AB D So min terms are BC D + A CD + AB D Hence (A) is correct option. Question. 34 Consider the following circuit involving a positive edge triggered D -FF.

Consider the following timing diagram. Let Ai represent the logic level on the line A in the i th clock period.

Let A represent the complement of A. The correct output sequence on Y over the clock perids 1 through 5 is (A) A0 A1 A1 ' A3 A4 (B) A0 A1 A2 ' A3 A4 (C) A1 A2 A2 ' A3 A4 (D) A1 A2 ' A3 A4 A5 SOLUTION We need to calculate equation for D input. (D) = (A i X')' (X' Q')' =Ai+X+X+Q (E) =Ai'+X+Q Drawing truth table for ckt Clock X Q0 = 0 Q1 = 1 Ai Y

263

0 1 2 3 4 5

1 1 0 1 1 0

0 0 0 0 0 0

1 1 1 1 1 1

## A0' A0' A1' A1' A3' A4 '

Hence (A) is correct option. Question. 35 The following diagram represents a finite state machine which takes as input a binary number from the least significant bit

Which one of the following is TRUE? (J) It computes 1s complement of the input number (K) It computes 2s complement of the input number (L) It increments the input number (M) It decrements the input number SOLUTION The transition table for the diagram Present state Q0 Q0 Q1 Q1 Input 0 1 0 1 Next state Q0 Q1 Q1 Q1 Output 0 1 1 0
264

So the FSM takes input from LSB side it doesnt change state till the first 1 comes from LSB side, after that it complement all the bits. This is logic for 2s complement. Hence (B) is correct option. Question. 36 Consider the following circuit

The flip-flops are positive edge triggered DFFs. Each state is designated as a two bit string Q0, Q1. Let the initial state be 00. The state transition sequence is (A) 00 " 11 " 01 (B) 00 " 11 A BBBBBBBC A BBBC (C) 00 " 10 " 01 " 11 (D) 00 " 11 " 01 " 10 A BBBBBBBBBBC A BBBBBBBBBBC SOLUTION Truth table for DFF CP 0 1 1 D X 0 1 Qn+1 Qn 0 1 Action No change Reset Set

## D here AX + X' Q' Truth table for ckt

and so on.
265

Hence (D) is correct option. Data for Q. 37 & 38 are given below. Solve the problems and choose the correct answers. Consider the following floating point format

Mantissa is a pure fraction is sign-magnitude form. Question. 37 The decimal number 0.239 # 213 has the following hexadecimal representation without normalization and rounding off (A) 0D 24 (C) 4D 0D SOLUTION Sign bit 0 Exponent = 13 Excess 64 = 13 + 64 = 77 = 1001101 Binary of 239 (B) 0D 4D (D) 4D 3D

266

We have 8 bits for Mantissa 0 0 1 1 1 1 0 1 So the floating point format. 0 0100 4 1001101 1101 D 00111101 0011 3 1101 D

Hence (D) is correct option. Question. 38 The normalized representation for the above format is specified as follows. The mantissa has an implicit 1 preceding the binary (radix) point. Assume that only 0s are padded in while shifting a field. The normalized representation of the above number (0.239 # 213) is (A) 0A 20 (B) 11 34 (C) 4D D0 SOLUTION Given no. .239 # 213 Normalized form of binary. Binary " .239 = (00111101)2 Normalized = 1.11101 # 210 Proceeding implicit 1 So 8 bit mantissa 11101000S padding (D) 4A E8

267

Excess 64 exponent 1 0 0 1 0 1 0 = 74 Sign bit = 0 Floating 0 0100 4 Point 1001010 1010 A Format 11101000 1110 E 1000 8

## GAE8 Hence (D) is correct option.

268

YEAR 2006 Question. 39 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 180c ?

SOLUTION We require phase shift of 180 in f In ckt (B) the negation of signal f & clock delays signal f by 180.
269

So phase shift occurs. Hence (B) is correct option. Question. 40 Consider the circuit below. Which one of the following options correctly represents f (x, y, z)?

## (A) xz + xy + yz (C) xz + xy + yz SOLUTION

(B) xz + xy + yz (D) xz + xy + yz

MVXI Selects X when Z = 0 Y' when Z = 0 MVX II Selects (XZ' + Y' Z) when y = 0 X when y = 0 so (XZ' + YZ) Y' + XY Simplifying = xz' y' + zy' y' + xy = xz' y' + xy (z + z') + zy' = xz' y' + xyz + xyz' + zy'(x + x') = xz' y' + xyz + xyz' + xy' z + x' y' z = y' z + xy' z + xyz' + xyz + xyz'[a + a = a] = y' z + xz'(y + y') + xy (z + z') = y' z + xz' + xy
270

Hence (A) is correct option. Question. 41 Given two three bit numbers a2 a1 a0 and b2 b1 b0 and c, the carry in, the function that represents the carry generate function when these two numbers are added is (E) a2 b2 + a1 a1 b1 + a2 a1 a0 b0 + a2 a0 b1 b0 + a1 b2 b1 + a1 a0 b2 b0 + a0 b2 b1 b0 (F) a2 b2 + a2 b1 b0 + a2 a1 b1 b0 + a1 a0 b21 b1 + a1 a0 b2 + a1 a0 b2 b0 + a2 a0 b1 b0 (G) a2 + b2 + (a2 5 b2)[a1 + b1 + (a1 5 b1)(a0 + b0)] (H) a2 b2 + a2 a1 b1 + a2 a1 a0 b0 + a2 a0 b1 b0 + a1 b2 b1 a1 a0 b2 b0 + a0 b2 b1 b0 SOLUTION a2 a1 a0 b2 b1 b0 C 0 0 0 0 1 1 1 0 0 1 1 0 0 1 0 1 0 0 1 0 1 0 0 0 0 1 1 1 0 0 1 1 0 0 1 0 1 0 1 0 1 0 0 1

1 1 0 1 1 1 Case I These are the possible value of a 2 a 1 a0 & b 2 b 1 b0 when a2 = 1 c=1 Case II b2 = 1 c = 1 so a 2 + b2 Case III If any 1 of a2 or b2 is 1 a 2 5 b2 then if a1 = 1 c = 1 b1 = 1 c = 1 so a 2 5 b 2 [ a 1 + b1] Case IV If any of a2 or b2 is 1 & any of a2 or b1 is 1 then if a0 = 1 c = 1 or if b0 = 1 then c = 1 so overall. a 2 + b 2 + [(a 2 5 b 2){a 1 + b 1 + (a 1 5 b 1)(a 0 + b0)}] Hence (C) is correct option. Question. 42 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, x1 > and i2 +< w2, x2, y2, z2 >

271

, 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,, 711,12,13,15). Which of the following cube covers of f will ensure that the required property is satisfied? (A) wxz, wxy, xyz, xyz, wyz (C) wxyz , xz, wxyz SOLUTION Given function f (w, x, y, z) = (5,7,11,12,13,15) draw K-map of the above function. (B) wxy, wxz, wyz (D) wzy, wyz, wxz, wwxz , xyz, xyz

1 quad = xz = xz (y + y') = xzy + xy' z 2 pairs = wxy' + wyz xyz + xy' z + wxy' + wyz Hence (A) is correct option. Question. 43 We consider addition of two 2s complement numbers bn 1 bn 2 .....b0 and an 1 an 2 ....a0. A binary adder for adding unsigned binary numbers is used to add the two numbers. The sum is denoted by cn 1 cn 2 ....c0 and the carryout by cout . Which one of the following options correctly identifies the overflow condition?

272

## Binary adder generates C out only if 1 C in 0a 1b 1 1 0 0 1 1 1 1 1

1 C out 1 1 1 C out in this case is Cn1 generated carry. C in is Cn2 So b ' n 1 a' n 1 c n 2 + b n 1 a n 1 c'n2 f = Cout 5 Cn1 Hence (C) is correct option. Question. 44 Consider number represented in 4-bit gray code. Let h3 h2 h1 h0 be the gray code representation of a number n and let g3 g2 g1 g0 be the gray code of (n + 1) (modulo 16) value of the number. Which one of the following functions is correct? E g0 (h1 h2 h1 h0) = /(1,2,3,6,10,13,14,15) E g1 (h1 h2 h1 h0) = /(4,9,10,11,12,,13,14,15) E g2 (h1 h2 h1 h0) = /(2,4, 5,6,7,12,,13,15) E g3 (h1 h2 h1 h0) = /(0,1,6,7, 10,11,12,,13,) SOLUTION Binary h 0000 0001 0010 0011 0100 0101 0110 0111 1000 0 1 2 3 4 5 6 7 8 h 3 h 2 h 1 h0 (n + 1) mod 16 0000 0001 0011 0010 0110 0111 0101 0100 1100 1 2 3 4 5 6 7 8 9 g3g2g1 g0 0001 0011 0010 0110 0111 0101 0100 1100 1101

273

9 10 11 12 13 14

## 1101 1111 1110 1010 1011 1001

10 11 12 13 14 15

## 1111 1110 1010 1011 1001 1000

1111 15 1000 0 0000 This gives the solution option (B) g 1 (h 3, h 2, h 1, h0) = /(4,9,10,11,12,13,14,15) YEAR 2007 Question. 45 What is the maximum functions involving n Boolean variables? (A) n2 (C) 22n SOLUTION Each boolean variable can have values 0 or 1, so for expression involving n boolean variables will have terms 2n . These 2n terms need to be arranged in different manner and nos., suppose 2n = M. So this arrangement would take 2M ways or 22n ways. Hence (C) is correct option. Question. 46 How many 3-to-8 line decoders with an enable input are needed to construct a 6-to-64 line decoder without using any other logic gates? (A) 7 (B) 8 (C) 9 SOLUTION (D) 10 number of different Boolean (B) 2n (D) 2n2

274

Total output lines required = 64 We need to use 3 to 8 decoders. So decoders required 648 = 8 decoders for output. But we need one more decoder i.e for combining result. 8 + 1 = 9 decoders. Hence (C) is correct option. Question. 47 Consider the following Boolean function of four variables f (w, x,, y, z) = /(1,3,4,6,9,11,12,14) The function is (I) independent of one variable (J) independent of two variables (K) independent of three variables (L) dependent on all the variables SOLUTION f (w, x, y, z) = /m(1,3,4,6,9,11,12,14)

2 qlead 1st qlead xz' x' z 2nd qlead xz' + x' z xz' + x' z So independent of 2 variables. Hence (B) is correct option. Question. 48 Let f (w, x, y, z) = /(0,4,5,7,8,9,13,15). Which of the following expressions are NOT equivalent to f ?
275

(A) x' y' z + w' xy' + wy' z + xz (C) w' y' z' + wx' y' + xyz + xy' z

(B) w' y' x' + wx' y' + xz (D) x' y' z + wx' y' + w' y

276

## SOLUTION f (w, x, y, z) = /m(0,4,5,7,8,9,13,15) Drawing K-map.

xz + w' y' z' + wx' y' Hence (B) is correct option. Question. 49 Define the connective* for the boolean variable X and Y as: X * Y = XY + X' Y' Let Z = X * Z Consider the following expression P, Q and R. P: X = Y * ZQ: Y = X * Z R: X * Y * Z = 1 Which of the following is TRUE? (A) only P and Qare valid (C) Only P and Rare valid SOLUTION Given Z = X ) Z & XZ + X' Z' P: X = Y ) Z (I) YZ + Y' Z' (J)Y (XZ + X' Z') + Y' Z' (K) XYZ + X' YZ' + Y' Z' (L) XYZ + X' YZ' + XY' Z' + X' Y' Z' valid. Q: Y = X ) Z (M) XZ + X' Z' (N) X (XZ + X' Z') + X' Z'
277

## (B) Only Qand Rare valid (D) AllP, Q,Rare valid

(G) XZ + X' Z' (H) X (Y + Y') Z + X'(Y + Y') Z' (I)XYZ + XY' Z + X' YZ' + X' Y' Z' valid R : X ) Y ) Z = 1 (XY + X' Y') ) Z & (XZ + X' Y') Z + (XY + X' Y') Z' (E)XYZ + X' Y' Z + [(XY : X' Y') Z'] (F) XYZ + X' Y' Z + [(X + Y ) : (X + Y)] Z' (G) XYZ + X' Y' Z + X' YZ' + XY' Z' =Y 1 So invalid Hence (A) is correct option. Question. 50 Suppose only one multiplexer and one inverter are allowed to be used to implement any Boolean function of nvariables. What is the minimum size of the multiplexer needed? (A) 2n line to 1 (C) 2n1 line to SOLUTION To select 2n lines we need a select function with n bits. Here with n variables we have (n 1) select bits thus 2n1 data lines. So MUX has 2n1 lines to 1. Hence (C) is correct option. Question. 51 In a look-ahead carry generator, the carry generate function Gi and the carry propagate function Pi for inputs, Ai and Bi are given by Pi = Ai 5 Bi and Gi = Ai Bi The expressions for the sum bit S and carry bit Ci+1 of the look ahead carry adder are given by Si + Pi 5 Ci and Ci + 1Gi + Pi Ci , Where C0 is the input carry. Consider a two-level logic implementation of the look-ahead carry generator.. Assume that all Pi and Gi are available for the carry generator circuit and that the AND and OR gates can have any number of inputs. The number of AND gates and OR gates needed to implement the look-ahead carry generator for a 4-bit adder with S3, S2, S1, S0 and C4 as its outputs are respectively line 1 line (B) 2n+1 line to 1 line (D) 2n2 line to 1 line

278

## (B) 10,4 (D) 10,5

The equation for 4 bit carry look ahead adder is Cout g 3 + p 3 g 2 + p 3 p 2 g 1 + p 3 p 2 p 1 g 0 + p 3 p 2 p 1 p 0 Cin Here no. of AND gates = 10 OR gates = 4 Hence (B) is correct option. Question. 52 The control signal functions of 4-bit binary counter are given below (where X is dont care) Clear Clock Load Count Function 1 0 0 0 X X X 0 1 0 X 0 X 1 Clear to 0 No change Load input Count next

## The counter is connected as follows

279

Assume that the counter and gate delays are negligible. If the counter starts at 0, then it cycles through the following sequence (A) 0,3,4 (C) 0,1,2,3,4 SOLUTION From the truth table for the counter ckt we can see that when counter = 1. & load = 0, count next is the function. So it would count from 0 to 4 & then clear to 0 & again start if clock input is increasing. Hence (C) is correct option. YEAR 2008 Question. 53 In the IEEE floating point representation the hexadecimal value 0x00000000 corresponds to (A) the normalized value 2127 (C) the normalized value +0 SOLUTION This 0X00000000 hexadecimal value can be converted into 32 bit binary. 0000 0000 0000 0000 0000 0000 0000 0000 0 # 2c This is representation in IEEE floating point format. Case for special +0. Hence (D) is correct option. Question. 54 In the karnaugh map shown below, X denoted a dont care term. What is the nominal form of the function represented by the karnaugh map (B) the normalized value 2126 (D) the special value +0 (B) 0,3,4,5 (D) 0,1,2,3,4,5

280

## (B) a. b + b . d + a.b . d (D) a. b + b . d + a. d

quad 1 " a b quad 2 " b d pair 1 " a c d So a b + b d + a d (c + c) a b + b d + a d Hence (D) is correct option. Question. 55 Let a denote number system radix. The only value(s) of r that satisfy the equation 121 + 11, is/are (A) decimal 10 (C) decimal 10 and 11 SOLUTION (121)r = (11)r If r = 10 it is true it cant be 2 = 11 It is true for 3 to 10. So it is true for r > 2 Hence (D) is correct option. Question. 56 Give f1, f3 and f in canonical sum of products form (in decimal) for the circuit
281

(B) decimal 11 (D) any value> 2 since bit value cant be 2 then. It is not true for r

f1 = /m(4,5,6,7,8) f3 = /m(1,6,15) f = /m(1,6,8,15) Then f2 is (A) /m(4,6) (C) /m(6,8) SOLUTION (B) /m(4,8) (D) /m(4,6,8)

Given f = m(1,6,8,15) f3 = m(1,6,15) So output 1,6,8,15 here 1,6,15 can come form f3. Since the final gate is OR gate so from f1 AND f2 no minterm except 1,6,8,15 should come. f1 = m(4,5,6,7,8) f2 can be m(6,8) So Since 4,5, & 7 should no 7 come here. Hence (C) is correct option. Question. 57 If P , Q, R are Boolean variables, (P + Q) (P.Q + P. R) (P. R + Q) simplifies to (B) P. R (A) P. Q

282

(C) P. Q + R SOLUTION

(D) P. R + Q

S (P + Q ) : (P Q + PR) : (P R + Q) S (PPQ + PPR + PQ Q + PQR)(P R + Q) S (P Q + PR + PQ + PQR)(P R + Q) S (PQ + PR + PQR)(P R + Q) S [ PQ (1 + R ) + PR](P R + Q) S P (Q + R)(P R + Q) S (P P R + PQ )(Q + R) S PQ : (Q + R) S PQ + PQR S PQ (1 + R) S PQ Hence (A) is correct option. YEAR 2009 Question. 58 (1217)8 is equivalent to (A) (1217)16 (C) (2297)10 SOLUTION (vii) (1217)8 (viii) 001010001111SSS (ix) (028F)1 6 Hence (B) is correct option. Question. 59 What is the minimum number of gates required to implement the Boolean function (AB + C) if we have to use only 2-input NOR gates ? (A) 2 (C) 4 (B) 3 (D) 5
283

## (B) (028F)16 (D) (0B17)16

SOLUTION AB+C implementation through NOR gate (X + Y ) We require one AND gate & 1 OR gate

AND gate & OR gate can be implemented by NOR gate. 2 A+C+B+C 2 A+C:B+C 2 (A + C ) : (B + C) 2 C + AB So we require & NOR gates. Hence (B) is correct option. YEAR 2010 Question. 60 The minterm expansion of f (P, Q, R) = PQ + QR + PR is (A) m 2 + m 4 + m 6 + m1 (C) m 0 + m 1 + m 6 + m1 SOLUTION Given expression is f (P, Q, R) = PQ + QR + PR For min term expansion we add the remaining variables in the expression. 2. PQ (R + R ) + (P + P ) QR + P (Q + Q ) R 3. PQR + PQR + PQR + PQR + PQR + PQR 4. PQR + PQR + PQR + PQ R 5. m 7 + m 6 + m 2 + m4 6. 111 + 110 + 010 + 100 So = m 2 + m 4 + m 6 + m7
284

(B) m 0 + m 1 + m 3 + m5 (D) m 2 + m 3 + m 4 + m5

Hence (A) is correct option. Question. 61 P is a 16-bit signed integer. The 2s complement representation of P is (F 87B)16. The 2s complement representation of 8)P is (A) (C 3D8)16 (C) (F878)16 SOLUTIO N Ps 2s complement. = (F87B)16 Is complement= F 87B 1 = (F87A)16 In base 16 complement is done by subtracting from 15 i.e F. = = (0785)16 (0000 01111000 0101)2 1 # 2c + 1 # 2 2 + 1 # 2 7 + 1 # 2 8 + 1 # 2 9 + 1 # 210 = = 1925 8 # P = 8 # 1925 = 15400 Its binary 0011110000101000SSSS For hexadecimal make pairs of 4 i.e. (3C28)16 2s complement P = 1100 0011 1101 1000 C 3 D 8 2s complement of P = (C 3D8)16 Hence (A) is correct option. Question. 62 The Boolean expression for the output f of the multiplexer shown below is (B) (187B)16 (D) (987B)16

(A) P 5 Q 5 R

(B) P 5 Q 5 R
285

(C) P + Q + R SOLUTION

(D) P + Q + R

S1 & so are the select bits which are used to select any 1 of the 4 inputs. Selection table S 1 (P) S 0 (Q) Input 0 0 1 1 0 1 0 1 0R 1R 2R 3R

## The expression has 3 variables So K-map

This is K-map for P 5 Q 5 R i.e PQ R + P Q R + PQR + P QR Hence (B) is correct option. Question. 64 In the sequential circuit shown below, if the initial value of the output Q 1 Q0 is 00, what are the next four values of Q 1 Q0 ?

286

## (B) 10, 11, 01, 00 (D) 11, 10, 00, 01

There are 2 T-toggle flip flops in the ckt. Truth table for TFF. CP 0 1 1 T X 0 1 Qn+1 Qn Qn Qn Qn previous state CP clock pulse Qn+1 next state T toggle input Since initially Q, Q0 = 00, so during 1st clock cycle both T & clock signals in ckt are 1. After Q0 = 1 this fed to 2nd TFF which invert previous state Q1 = 1 so Q 1 Q0 = 11 11 when fed to next cycle clock = 1 so Q0 = 0 Q1 = 1 since no inversion Q, Q0 = 10 In next cycle clock = 1 Q0 = 1 inverse, Q1 = 0 in the end Q 1 Q0 = 00 So order 11, 10, 01, 00 Hence (A) is correct option. Which one of the following circuits is NOT equivalent to a 2-input XNOR (exclusive NOR) gate? (A) (B)
287

(D)

Exp: - All options except option D gives EX-NOR gates 67. The minimum number of D flip-flops needed to design a mod-258 counter is (A) 9 (B) 8 (C) 512 (D) 258 Answer: - (A) Exp: - 2n 258 Common Data Questions: 50 & 51 Consider the following circuit involving three D-type flip-flops used in a certain type of counter configuration.

## P D Clock Q Q D Clock Q R D Clock Q Q Q Q

288

68. If all the flip-flops were reset to 0 at power on, what is the total number of distinct outputs (states) represented by PQR generated by the counter? (A) 3 (B) 4 (C) 5 (D) 6 Answer: - (B) Exp: CLOCK D2 D1 1 2 3 4 0 0 1 0 1 1 0 0 D3 0 1 0 0 R P 0 0 1 0 Q 1 1 0 0 R 0 1 0 0 Inputs Outputs

## So Total number of distinct outputs is 4

69.

If at some instance prior to the occurrence of the clock edge, P. Q and R have a value 0, 1 and 0 respectively, what shall be the value of PQR after the clock edge? (A) 000 (B) 001 (C) 010 (D) 011 Answer: - (D) Exp: -From the Table Shown in the explanation of question 50, if first state is 010 next State is 011

289

YEAR 2013 73. Which one of the following expressions does NOT represent exclusive NOR of x and y? (B) x y' Ans: Exp: y (D) (C) x' y (D) x' y'

74. In the following truth table, V = 1 if and only if the input is valid. Inputs D0 0 1 0 1 X D1 0 0 1 X X D2 0 0 0 1 X D3 0 0 0 0 1 1 Outputs X0 X 0 X1 X 0 1 0 1 V 0 1 1 1 1

What function does the truth table represent? (A) Priority encoder (B) Decoder (C) Multiplexer (D) Demultiplexer Ans: (A) Exp: 4 to 2 priority encoder. 75. The smallest integer than can be represented byan 8-bit number in 2s complement form is (A) -256 (B) -128 (C) -127 (D) 0 Ans: (B) Exp: 28 1 128. Range is -2(n-1) to +2(n-1)-1 ts each 8 . The number of
290

## decoders (A) 4 (B)

with (B) 5

enable

line (C) 6

needed

to (D) 7

construct

Ans: Exp.

16 Number of chips required = having 2 chips horizontally] So to select one chip out of 16 vertical chips, we need 4 x 16 decoder. Available decoder is 2 x 4 decoder To be constructed is 4 x 16 decoder 2 [16 chips vertically with each

291