Gate Book- Cse
March 18, 2017 | Author: adityabaid4 | Category: N/A
Short Description
cse...
Description
SREENIVASA INSTITUTE OF TECHNOLOGY AND MANAGEMENT STUDIES (AUTONOMOUS)
Department of Computer Science and Engineering
GATE BITS SUBJECT-WISE
1
Table of Contents 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
2
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.
4
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)
(B) O(log n)
(C) O(n)
(D) O(n log n)
(GATE 2013)
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)
(B) O(n)
(C) O(n log n)
(D) O(n2)
(GATE 2013)
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)
(B) ϴ(n+k)
(C) ϴ(nk)
(D) ϴ(n2)
(GATE 2013)
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
(B) 15,10,25,23,20,42,35,39,30
(C) 15,20,10,23,25,42,35,39,30
(D) 15,10,23,25,20,35,42,39,30 5
Answer: (D)
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)
6
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;inext!=NULL) { q=p; p=p->next; } ---------------------------------------return head; } Choose the correct alternative to replace the blank line. 1) q=NULL; p->next=head; head=p; 2) q->next=NULL; head=p; p->next=head; 3) head=p; p->next=q; q->next=NULL; 4) q->next=NULL; p->next=head; head=p; Answer: (D) Solution: Here the program wants to make the last node of the list, the first node. Here q is the second last node and p is the last node The second last node’s next should be now NULL so q->next=NULL. 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 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
42
3
23
4
34
5
52
6
46
7
33
8 9
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 )
B)θ(nlogn) D)θ(n2logn)
Answer: (C)
24. Consider the program below: #include int fun(int n, int *f_p){ intt,f; if (ny)?((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.
(GATE 2006)
void xyz (int a[],int b[],int c[]){ inti, j, k; i=j=k=0; while((i=5 i.e. n returned then Step
Call
n
i
(1) 1
1
1
condition false n < 5
(2)
1+1=2
2
(3) 2
2
2
(4)
2+2=4
3
(5) 3
4
3
(6)
4+3=7
4
(7) 4
7
4
false n < 5
false n < 5
true return n = 7
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......dm−i and rev = dmdm−1......dm−i+1 (B) n = dm−i+1.....dm−1dm or rev = dm−i .....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.....dm−i & rev have dmdm−1..........dm−i+1 i
n
rev
1
d1d2....dm−1 dm
2
d1d2......dm−2 dmdm−1
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;i3. 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)
B. O (n)
C. O (log2 n)
D .O (n log2 n)
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))
C. Min (f(n),g(n))
D. 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)
C. O(log N)
D. None of these
Answer B 6.The upper bound of computing time of m coloring decision problem is A. O(nm)
B .O(nm)
C. O(nmn)
D. O(nmmn)
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
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
B. column major
C. matix major D. none of these
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)
D. O (n2)
Answer A 12.Which of the following case does not exist in complexity theory A. Best case
B. Worst case C. Average case
D. Null 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
B. 4 & 2
C. 3 & 3
D. 8 & 3
Answer C 58
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)
B. T(n2n)
C. T(n) D. T(logn)
Answer C 16.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
Answer C 17.The quick sort algorithm exploit _________ design technique A. Greedy
B. Dynamic programming
C. Divide and Conquer D. Backtracking
Answer C 18.The number of distinct simple graphs with up to three nodes are A. 15
B. 10
C. 7
D. 9
Answer C 19.The number of unused pointers in a complete binary tree of depth 5 is A. 4
B. 8
C. 16
D. 32
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
B .Even degree C .Odd degree D. Different 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
Answer D 22.One can convert a binary tree into its mirror image by traversing it in A. Inorder
B. Preorder
C. Postorder
D. Any order
Answer C 23.Graphs are represented using A. Adjacency tree
B. Adjacency linked list C. Adjacency graph
D. Adjacency queue
Answer B 24.The data structure required for breadth first traversal on a graph is A. Queue
B. Stack
C. Array
D. Tree
Answer A 25.Number of edges of a complete binary tree with 16 leaf nodes are A. 14
B. 30
C. 32
D. 28
Answer B
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
B. 3
C. 4
D. 5
Answer D 29.Leaves of which of the following trees are at the same level ? 60
A. Binary tree B. B-tree
C. AVL-tree
D. Expression tree
Answer B 30.The Inorder traversal of the tree will yield a sorted listing of elements of tree in A. Binary tree B. Binary search tree
C. Heaps
D. None of the above
Answer B 31.One can make an exact replica of a Binary Search Tree by traversing it in A. Inorder
B. Preorder
C. Postorder
D. Any order
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)
B. 0(lgn)
C. 0(n)
D. 0(nlgn)
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
B. IEFCJGKHDB
C. IEFCGKJHDB
D. IEFCGJKDBH
Answer A 36. The running time of the following sorting algorithm depends on whether the partitioning is balanced or unbalanced 61
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)
C. O (log n)
D. O (n2/4)
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
C. Selection sort
D. None of these
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
B. NP C. Both A and B
D. None of these
Answer B 43. Both P and NP are closed under the operation of A. Union
B. Intersection C. Concatenation
D. Kleene
Answer D 44. If every node u in G is adjacent to every other node v in G, A graph is said to be
A.
Isolated 62
B. C. D.
Complete Finite Strongly Connected
Answer:B
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
46. Randomized quicksort is an extension chosen randomly. What is the worst numbers using randomized quicksort?
(a) O(n)
(b) O(n log n)
of quicksort where the pivot is case complexity of sorting n (c) O(n2)
(d) O(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.
Three nodes Two nodes One node Any number of nodes
60.
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.
T(n) = 2T(n - 2) + 2 T(n) = 2T(n - 1) + n T(n) = 2T(n/2) + 1 T(n) = 2T(n - 1) + 1
67.
A. A B. B C. C D. D 68. The goal of hashing is to produce a search that takes
A. B. C. D.
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. 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)
Answer : A 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) Can’t 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 can’t 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 can’t 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
(B) 9 5 + 2 +
(C) 9 5 2 ++
(D) ++ 9 5 2
SOLUTION S " TR R "+ T {pr int(' + ');}R ε T " num{print(num.val);} Given string 9 + 5 + 2 S " TR
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 t1’s 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
(D) 115, 105
SOLUTION In static scoping the variables are initialized at compile time only 73
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
(D) 2 2 2
SOLUTION 1.
Px = newQ();
2.
Qy = newQ();
3.
Pz = newQ();
4.
x : f(1); print 2 # i = 2
5.
((P) y) : f(1);
6.
z : f(1) print 2 # i = 2
but line 5. will print 2 because typecast to parent class can’t 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 doesn’t 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
(ii) P " Q s R
(iii) P " ε
(iv) P " Q t R r
(A) (i) only
(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
(D) Load-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
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
(D) 40
SOLUTION The parse tree would be.
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
(B) Left-recursive
(C) right-recurisve
(D) an operator-grammar
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
n
B) n , E + n and E + E # n (D) n , E + n and E # 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
(B) n1 = n3 < n2
(C) n1 = n2 = n3
(D) n1 $ n3 $ n2
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
Hence (B) is correct option. 22. Consider line number 3 of the following C-program.
Identify the compiler’s 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
Eval E .val
number val E .VAL
E .val
E .val
E .VAL
E .val
; 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
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)
S " S * .E
(ii)
E"F.+E
(iii)
E " F + .E
Given the items above, which two of them will appear in the same set in the canonical sets-ofitems for the grammar? 81
(A) (i) and (ii)
(B) (ii) and (iii)
(C) (i) and (iii)
(D) None of these
SOLUTION 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}
(B) {S " FR} and {} (D) {F " id} and {R " ε}
SOLUTION The predictive parser table is given as. Non Terminal
)
id
S
S " FR
F
F " id
R So at
R ") S R "! M [ S, id] = S {
M [ R,$] = {R Hence (A) is correct option.
$
R "! " FR} "!}
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 | ε
(B) S " aS | Sb | a | b
(C)
S " ACCB
(D)
S " AC | CB 83
C " aCb |! A " aA |! B " Bb |!
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
(D) max (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
(D) An LALR(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
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
(D) It is not context-free
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
(B) P is true and Q is false
(C) P is false and Q is true
(D) Both P and Q are false
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.
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
(B) 3
(C) 5
(D) 6
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
35.Which of the following strings is generated by the grammar? (A) aaaabb
(B) aabbbb
(C) aabbab
(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
(B) 2
(C) 3
(D) 4
SOLUTION For the derivation two trees are possible
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
(B) (i), (iii) and (iv) only
(C) (i), (ii) and (v)
(D) (ii), (iii) and (v) only
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
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
(B) I and IV
(C) III 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
(D) Parse table
SOLUTION Symbol table is used for storing the information about variables and their attributes by 89
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 program’s 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 doesn’t translate program’s 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
(B) Disk (D) On-chip cache
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
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 Belady’s 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
(B) 8 MB (D) 24 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
= 58/8 = 8 Bytes. So total memory = 8*1 MB= 8 MB Hence (B) is correct option. Question. 6 Consider Peterson’s algorithm for mutual exclusion between two concurrent processes i and j. The program executed by process is shown below. repeat flag[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
(A) A (C) A and C
(B) A and B (D) A, B and C
SOLUTION 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
(B) 2 ns (D) 4 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.80≈4 ns (Nearest .5) Hence (D) is correct option.
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
(B) 12KB
(C) 16 KB
(D) 20KB
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.
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 10”1 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
(B) (ii) and (iii) only (D) (i) and (ii) only
SOLUTION (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 don’t 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%
(B) 40% (D) 0%
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
(B) 5.75 (D) 6.25
SOLUTION Then around time = (Submit time −finish time) Gantt chart for the scheduler.
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
(B) 1050 nanoseconds (D) 1230 nanoseconds
SOLUTION Memory access time =0.90*150 +0.10*(150 +150) =135 +30 =165 ns The error rate = 1/10000 = 10−4 CPU burst time = 100 ns Total execution time =[100 +2[165] +10−4*8*106] =100 +330 +800 =100 +1130 =1230 ns Hence (D) is correct option.
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)
(B) P(Sx),P(Sy);P(Sy),P(Sx) (D) P(Sx),P(Sy);P(Sx),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
(B) 232 bytes
(C) 234 bytes
(D) 248 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
Question. 25 Suppose n processes, P1……Pn 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. 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 v≠y (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
(B) 2
(C) 3
(D) 4
SOLUTION When CPU burst are given to another process, called context switching. The Gantt chart for shortest remaining time first is.
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 doesn’t work properly and can’t 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
(B) 13bits
(C) 15bits
(D) 20bits
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
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
SOLUTION Process id
0
1
2
CPU Burst
2
4
8
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%
(B) 10.6%
(C) 30.0%
(D) 89.4%
SOLUTION Process 2 3
First I/O 2 4 6
Computation 7 14 21
Second I/O 1 2 3
Total 10 20 30
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 1≤i≤n. 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) < maxk≠p,q yk (B) xp+xq ≤ maxk≠p,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 function’s 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
(B) P-1 Q-2 R-3
Group-2 1.Guaranteed Scheduling 2. Real-time scheduling 3.Thread Scheduling
(C) P-2 Q-3 R-1
(D) P-1 Q-3 R-2
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
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 doesn’t 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
(B) 15
(C) 40
(D) 55
SOLUTION Gantt chart for the processes.
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 Belady’s 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
request XYZ 103 012 120
(A)P0
(B)P1
(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
(B)8
(C) 9
(D)10
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.
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
(B)1
(C) 2
(D)3
SOLUTION Instead of optimal policy if we use LRU then we don’t 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
*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
(B)bind
(C) listen
(D)connect
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
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 4 and x < 6, where x is an integer (c) x ≠ 5 not (x = 5) (d) None of the above 150
Answer: (B) 50) Consider the join of a relation R with a relation S. If R has m tuples and S has n tuples then the maximum and minimum sizes of the join respectively are (GATE:1999) (a) m + n and 0 (b) mn and 0 (c) m + n and |m – n| (d) mn and m + n
151
52) Consider the schema R = (S T U V) and the dependencies S € T, T € U. U € V and V € S. Let R = (R1 and R2) be a decomposition such that R1 ∩ R2 = ∅ . The decomposition is (GATE:1999) (a) not in 2NF
(b) in 2NF but not 3NF (c) in 3NF
but not in 2NF
(d) in both 2NF and 3NF
53) The minimum number of record movements required to merge five files A (with 10 records), B (with 20 records), C (with 15 records), D (with 5 records) and E (with 25 records) is: (GATE:1999) (a) 165 (b) 90 (c) 75 (d) 65 54) Which of the following is/are correct?
(GATE:1999)
(a) An SQL query automatically eliminates duplicates (b) An SQL query will not work if there are no indexes on the relations (c) SQL permits attribute names to be repeated in the same relation (d) None of the above Answer: (d)
55) Consider the set of relations EMP (Employee-no. Dept-no, Employee-name, Salary) DEPT (Dept-no. Dept-name, Location) Write an SQL query to: (a) Find all employee names who work in departments located at ‘Calcutta’ and whose salary is greater than Rs.50,000. (b) Calculate, for each department number, the number of employees with a salary greater than Rs.1,00,000. (GATE:1999)
56) Which normal form is considered adequate for normal relational database Design? (GATE:1998) (a) 2 NF
(b) 5 NF
(c) 4 NF
(d) 3 NF
Ans: solution (d) Explanation: 152
A relational database table is often described as "normalized" if it is in the Third Normal Form because most of the 3NF tables are free of insertion, update, and deletion anomalies. 57) There are five records in a database. Name
Age
Occupatio Categor n CO y A
Rama
27
Abdul
22
N
A
Jeniffe
28
EN
B
r
32
G
D
Maya
24
DO
C
There is an index file Devassociated with thisC and it contains the values 1,3,2,5 and 4.Which one of the fields is the index built from? (GATE:1998) SER (a) Age Answer: (C)
(b) Name MUS
(c) Occupation
(d) Category
58) Suppose we have a database consisting of the following three relations. FREQUENTS (student, parlor) giving the parlors each student visits. SERVES (parlor, ice-cream) indicating what kind of ice-creams each parlor serves. LIKES (student, ice-cream) indicating what ice-creams each student likes. (Assume that each student likes at least one ice-cream and frequents at least one parlor) Express the following in SQL: Print the students that frequent at least one parlor that serves some ice- cream that they like. (GATE:1998) 59) AB+ -tree index is to be built on the Name attribute of the relation STUDENT . Assume that all student names are of length 8 bytes, disk blocks are of size 512 bytes, and index pointers are of size 4 bytes. Given this scenario, what would be the best choice of the degree (i.e. the number of pointers per node) of the B+ -tree ? (A) 16 (B) 42 (C) 43 (D) 44 SOLUTION
Size of 1 record of index = 8 + 4 = 12 bytes. Let no. of pointers required = P No. of index values per block = P – 1 So
(P − 1) 8 + 4P= 512 12P= 520 153
P , 44 60) Let r and s be two relations over the relation schemes R and S respectively, and let A be an attribute in R . Then the relational algebra expression σA = a ]r A s g is always equal to : (A) σA = a ]r g (B) r (C) σA = a ]r A s g (D) None of the above SOLUTION
Given query performs natural join between r & s , & then project attribute A where A = a . This same result is produced by the query σA = a (r) A s . This query selects attribute A = a from r & then performs join operation results are same. Hence (C) is correct option.
INFORMATIONS SYSTEMS SOFTWARE ENGINEERING
1.The coupling between different modules of a software is categorized as follows: I. Content coupling V. Data coupling
II. Common coupling
III. Control coupling
IV. Stamp coupling
Coupling between modules can be ranked in the order of strongest(least desirable) to weakest (most desirable) as follows: 1) I-II-III-IV-V 2) V-IV-III-II-I 3) I-III-V-II-IV 4) IV-II-V-III-I
Solution:1
2.
154
Solution: B
gate-2010
3.
Solution: A
gate-2010
4.
Solution: D
gate-2010
5. In the system concepts, the term integration ? a. implies structure and order 155
b. refers to the manner in which each component functions with other components of the system c. means that parts of computer system depends on one another d. refers to the holism of systems Solution: D
gate-2009
6.What is software? a. Set of computer programs, procedures and possibly associated document concerned with the operation of data processing. b. A set of compiler instructions. c. A mathematical formulae d. All of the above e. None of the above Solution:A
gate-2009
7. Which is the last step in classic life cycle paradigm? a. System engineering b. Analysis c. Design d. Coding e. Maintenance. Solution:E
gate-2010
8. Which of the following is closer to machine Code a. Assembly language b. Machine language c. High level language d. All of the above e. None of the above Solution:A
gate-2010
9. The following are properties of Modularity except 156
a. It implement a single independent function b. It performs a single logical task. c. It has a single entry and exit point. d. It is entirely constructed of modules. e. None of the above. Solution:E
gate-2011
10. The following are characteristics of software expects a. It is developed or engineered. b. Software does not wear out c. Software are custom made d. Software have don’t have spare parts instead it has backup e. Software consists of physical devices. Solution:E
gate-2011
11. Software genetic development process contains three genetic phrases namely a. Definition, development, maintenance. b. Coding, design, Software engineering c. Software engineering, Definition, Coding d. Design, Coding, Development e. Development, Definition, Testing Solution:A
gate-2011
12. Which of the following translators convert high-level language on statement-by-statement basis? a. Compiler b. Machine level language converter c. Interpreter. d. Assembler e. None of the above 157
Solution:C
gate-2012
13. Which of the following is not an example of Prototype in engineering paradigm? a. Paper prototype. b. Existing prototype. c. Working prototype. d. Software prototype. e. Engineering prototype. Solution:A
gate-2012
14. Which of the following Construct in formal model in software engineering execute each statement in succession. a. Selection Construct. b. Sequence Construct. (Correct) c. Iteration Construct. d. Business Construct. e. Statement Construct. Solution:B
gate-2012
15.What is software engineering? a. Set of computer programs, procedures and possibly associated document concerned with the operation of data processing. b. Software engineering is Design, Coding, Development c. Software engineering implement a single independent function d. Software engineering is the establishment and use of sound engineering practice in order to produce economical and reliable software that will perform efficiently on real machine (Correct) e.Software engineering is a step that encompasses the method, tools, procedure used in software Solution:D
gate-2012
16. The most important feature of spiral model is (A) requirement analysis. (B) risk management. (C) quality management. (D) configuration management. 158
Ans: B 17. The worst type of coupling is (A) Data coupling. (B) control coupling. (C) stamp coupling. (D) content coupling. Ans: D 18. IEEE 830-1993 is a IEEE recommended standard for (A) Software requirement specification. (B) Software design. (C)Testing. (D) Both (A) and (B) Ans: A 19. One of the fault base testing techniques is (A) unit testing. (B) beta testing. (C) Stress testing. (D) mutation testing. Ans: D 20. Changes made to an information system to add the desired but not necessarily the required features is called (A) Preventative maintenance. (B) Adaptive maintenance. (C) Corrective maintenance. (D) Perfective maintenance. Ans: D 21. All the modules of the system are integrated and tested as complete system in the case of (A) Bottom up testing (B) Top-down testing (C) Sandwich testing (D) Big-Bang testing Ans: D 22. SRS is also known as specification of Ans: D (A) White box testing (B) Stress testing (C) Integrated testing (D) Black box testing 23. The model in which the requirements are implemented by category is (A) Evolutionary Development Model (B) Waterfall Model 159
(C) Prototyping (D) Iterative Enhancement Model Ans: A 24. SRD stands for (A) Software requirements definition (B) Structured requirements definition (C) Software requirements diagram (D) Structured requirements diagram Ans: B
public key cryptography, X adds a digital signature σ to message M, encrypts , and sends it to Y, where it is decrypted. Which one of the following sequences of keys is used for the operations? 25. Using
(A) Encryption: X’s private key followed by Y’s private key; Decryption: X’s public key followed by Y’s public key (B) Encryption: X’s private key followed by Y’s public key; Decryption: X’s public key followed by Y’s private key (C) Encryption: X’s public key followed by Y’s private key; Decryption: Y’s public key followed by X’s private key (D) Encryption: X’s private key followed by Y’s public key; Decryption: Y’s private key followed by X’s public key Ans:D
2013
COMPUTER NETWORKS 1. The transport layer protocols used for real time multimedia, file transfer, DNS and email, respectively are GATE 2013 (A) TCP, UDP, UDP and TCP (B) UDP, TCP, TCP and UDP (C) UDP, TCP, UDP and TCP (D) TCP, UDP, TCP and UDP ANS: C SOL: Multimedia can be unreliable but has to be fast so UDP, File transfer has to be secure & reliable so uses TCP, DNS can be both TCP and UDP, E mail uses TCP for reliability. 2. Using public key cryptography, X adds a digital signature σ to message M, encrypts , and sends it to Y, where it is decrypted. Which one of the following sequences of keys is used for the operations? GATE 2013 160
(A) Encryption: X’s private key followed by Y’s private key; Decryption: X’s public key followed by Y’s public key (B) Encryption: X’s private key followed by Y’s public key; Decryption: X’s public key followed by Y’s private key (C) Encryption: X’s public key followed by Y’s private key; Decryption: Y’s public key followed by X’s private key (D) Encryption: X’s private key followed by Y’s public key; Decryption: Y’s private key followed by X’s public key ANS: D 3. Assume that source S and destination D are connected through two intermediate routers labeled R. Determine how many times each packet has to visit the network layer and the data link layer during a transmission from S to D. GATE 2013
(A) Network layer – 4 times and Data link layer – 4 times (B) Network layer – 4 times and Data link layer – 3 times (C) Network layer – 4 times and Data link layer – 6 times (D) Network layer – 2 times and Data link layer – 6 times ANS: C SOL: Therefore, Network layer – 4 times Data link layer – 6 times
4. Determine the maximum length of the cable (in km) for transmitting data at a rate of 500 Mbps in an Ethernet LAN with frames of size 10,000 bits. Assume the signal speed in the cable to be 2,00,000 km/s. GATE 2013 (A) 1 (B) 2 (C) 2.5 (D) 5 ANS: B SOL: Propagation time = Transmission time + Collision signal time 𝐹𝑎𝑟𝑚𝑒 𝑠𝑖𝑧𝑒 𝐿𝑒𝑛𝑔𝑡ℎ 𝐿𝑒𝑛𝑔𝑡ℎ = + 𝑃𝑟𝑜𝑝𝑎𝑔𝑎𝑡𝑖𝑜𝑛 𝑡𝑖𝑚𝑒 𝑆𝑖𝑔𝑛𝑎𝑙 𝑠𝑝𝑒𝑒𝑑 𝑆𝑖𝑔𝑛𝑎𝑙 𝑠𝑝𝑒𝑒𝑑 10000 𝑏𝑖𝑡 2 ∗ 𝑙𝑒𝑛𝑔𝑡ℎ = 500 ∗ 106 𝑏𝑖𝑡𝑠/ 𝑠𝑒𝑐 2 ∗ 105 𝑘𝑚/𝑠𝑒𝑐 161
Length = 2 km 5. In an IPv4 datagram, the M bit is 0, the value of HLEN is 10, the value of total length is 400 and the fragment offset value is 300. The position of the datagram, the sequence numbers of the first and the last bytes of the payload, respectively are GATE 2013 (A) Last fragment, 2400 and 2789 (B) First fragment, 2400 and 2759 (C) Last fragment, 2400 and 2759 (D) Middle fragment, 300 and 689 ANS: C SOL: Since M bit is 0, so there is no fragment after this fragment. Hence this fragment is the last fragment. Now, HLEN defines the length of header in datagram. Since Hlen is 10 so, size of header is 10 * 4 = 40 B Length of data = Total length – Header length = 400 – 40 = 360 B Now, fragment offset of data in original datagram is measured in units of 8 B. so to find first Byte of this fragment, First byte/8 = fragment offset First byte = 300 * 8 = 2400 B and since length of data is 360 B. So, last byte on this datagram will be 2759 6. In the IPv4 addressing format, the number of networks allowed under Class C addresses is GATE 2012 (A) 214 (B) 27 (C) 221 (D) 224 ANS: C SOL: For class C address, size of network field is 24 bits. But first 3 bits are fixed as 110; hence total number of networks possible is 221. 7. Which of the following transport layer protocols is used to support electronic mail? GATE 2012 (A) SMTP (B) IP (C) TCP (D) UDP ANS:C SOL: E-mail uses SMTP in application layer to transfer mail. And SMTP uses TCP to transfer data in transport layer. 8. The protocol data unit (PDU) for the application layer in the Internet stack is GATE 2012 (A) Segment (B) Datagram (C) Message (D) Frame ANS: C SOL: Protocol Data Unit (PDU) Application layer – Message Transport layer – Segment Network layer – Datagram Data Link layer – Frame Ans = Message 162
9. Consider an instance of TCP’s Additive Increase Multiplicative Decrease (AIMD) algorithm where the window size at the start of the slow start phase is 2 MSS and the threshold at the start of the first transmission is 8 MSS. Assume that a timeout occurs during the fifth transmission. Find the congestion window size at the end of the tenth transmission. GATE 2012 (A) 8 MSS (B) 14 MSS (C) 7 MSS (D) 12 MSS ANS: C SOL: Given threshold = 8 Time = 1, during first transmission, window size = 2 (slow start phase) Time = 2, congestion window size = 4 (double the no. of acknowledgments) Time = 3, congestion window size is = 8 Time = 4, congestion window size = 9, after threshold (increase by one addictive increase) Time = 5, transmits 10 MSS, but time out occurs congestion windw size = 10 Hence threshold = (congestion window size)/2=10/2 = 5 Time = 6, transmits 2 Time = 7, transmits 4 Time = 8, transmits 5(threshold is 5) Time = 9, transmits 6 Time = 10, transmits 7 During 10th transmission, it transmits 7 segments hence at the end of the 10th transmission the size of congestion window is 7 MSS. 10. Consider a source computer (S) transmitting a file of size 106 bits to a destination computer (D) over a network of two routers (R1 and R2) and three links (L1, L2, and L3). L1 connects S to R1; L2 connects R1 to R2; and L3 connects R2 to D. Let each link be of length 100km. Assume signals travel over each line at a speed of 108 meters per second. Assume that the link bandwidth on each link is 1Mbps. Let the file be broken down i n t o 1000 p a c k e t s each of size 1000 bits. Find the total sum o f transmission and p r o p a g a t i o n delays i n transmitting the file from S to D? GATE 2012 (A) 1005ms ANS: A SOL:
(B) 1010ms L1
S
(C) 3000ms L2
R1
R2
(D) 3003ms L3 D
Transmission delay for 1st packet from each of S, R1 and R2 will take 1 ms Propagation delay on each link l1,l2 and l3 for one packet is 1ms Therefore the sum of transmission delay and propagation delay on each link for one packet is 2ms. The first packet reaches the destination at 6th ms The second packet reaches the destination at 7th ms So, inductively we can say that 1000th packet reaches the destination at 1005th ms.
163
11. Consider the directed graph shown in the figure below. There are multiple shortest paths between vertices S and T. Which one will be reported by Dijkstra’s shortest path algorithm? Assume that, in any iteration, the shortest path to a vertex v is updated only when a strictly shortest path to v is discovered.
GATE 2012 (A) SDT (B) SBDT (C) SACDT (D) SACET ANS: D SOL: Let d[v] represent the shortest path distance computed from ‘S’ Initially d[S] = 0, d[A] = ∞, d[B] = ∞, - - - - -, d[T] = ∞ and let P[v] represent the predecessor of v in the shortest path from ‘S’ to ‘v’ and let P[v] = 1 denote that currently predecessor of ‘v’ has not been computed → Let Q be the set of vertices for which shortest path distance has not been computed → Let W be the set of vertices for which shortest path distance has not been computed → So initially, Q = {S, A, B, C, D, E, F, G, T}, W = ϕ We will use the following procedure Repeat until Q is empty{ 1. u = choose a vertex from Q with minimum d[u] value 2. Q = Q – u 3. update all the adjacent vertices of u 4. W = W U{u} } d[S] = 0, d[A] = ∞, d[B] = ∞, . . . . , d[T] = ∞ Iteration 1: Step 1: u = S Step 2: Q = {A, B, C, D, E, F, G, T} Step 3: final values after adjustment d[S] = 0, d[A] = 4, d[B] = 3, d[C] = ∞, d[D] = 7, d[E] = ∞ - - -, d[T] = ∞ P[A] = S, P[B] = S, P[C] = 1, P[D] = S, P[E] = 1 - - - , P[T] = 1 Step 4: W = {S} Iteration 2: Step 1: u = S Step 2: Q = {A, C, D, E, F, G, T} Step 3: final values after adjustment d[S] = 0, d[A] = 4, d[B] = 3, d[C] = ∞, d[D] = 7, d[E] = ∞ - - -, d[T] = ∞ P[A] = S, P[B] = S, P[C] = 1, P[D] = S, P[E] = 1 - - - , P[T] = 1 164
Step 4: W = {S, B} Iteration 3: Step 1: u = A Step 2: Q = {C, D, E, F, G, T} Step 3: final values after adjustment d[S] = 0, d[A] = 4, d[B] = 3, d[C] = 5, d[D] = 7, d[E] = ∞ - - -, d[T] = ∞ P[A] = S, P[B] = S, P[C] = A, P[D] = S, P[E] = 1 - - - , P[T] = 1 Step 4: W = {S, B, A} Iteration 4: Step 1: u = C Step 2: Q = {D, E, F, G, T} Step 3: final values after adjustment d[S] = 0, d[A] = 4, d[B] = 3, d[C] = 5, d[D] = 7, d[E] = 6, - - -, d[T] = ∞ P[A] = S, P[B] = S, P[C] = A, P[D] = S, P[E] = C, - - - , P[T] = 1 Step 4: W = {S, B, A, C} Iteration 5: Step 1: u = E Step 2: Q = {D, F, G, T} Step 3: final values after adjustment d[S] = 0, d[A] = 4, d[B] = 3, d[C] = 5, d[D] = 7, d[E] = 6, d[F] = ∞, d[G] = 8, d[T] = 10 P[A] = S, P[B] = S, P[C] = A, P[D] = S, P[E] = C, P[F] = 1, P[G] = E, P[T] = E Step 4: W = {S, B, A, C, E} After iteration 5, we can observe that P[T] = E, P[E] = C, P[C] = A, P[A] = S, So the shortest path from S to T is SACET 12. An Internet Service Provider (ISP) has the following chunk of CIDR-based IP addresses available with it: 245.248.128.0/20. The ISP wants to give half of this chunk of addresses to Organization. A, and a quarter to Organization B, while retaining the remaining with itself. Which of the following is a valid allocation of addresses to A and B? GATE 2012 (A) 245.248.136.0/21 and 245.248.128.0/22 (B) 245.248.128.0/21 and 245.248.128.0/22 (C) 245.248.132.0/22 and 245.248.132.0/21 (D) 245.248.136.0/24 and 245.248.132.0/21 ANS: A SOL:
th
Since half of 4096 host addresses must be given to organization A, we can set 12 bit to 1 and include that bit into network part of organization A, so the valid allocation of addresses to A is 245.248.136.0/21
165
th
th
Now for organization B, 12 bit is set to ‘0’ but since we need only half of 2048 addresses, 13 bit can be set to ‘0’ and include that bit into network part of organization B so the valid allocation of addresses to B is 245.248.128.0/22 13. Consider different activities related to email. m1: Send an email from a mail client to a mail server m2: Download an email from mailbox server to a mail client m3: Checking email in a web browser Which is the application level protocol used in each activity? (A) m1: HTTP m2: SMTP m3: POP
GATE 2011
(B) m1: SMTP m2: FTP m3: HTTP
(C) m1: SMTP m2: POP m3: HTTP (D) m1: POP m2: SMTP m3: IMAP ANS: C SOL: Mail client uses SMTP (Simple Mail Transfer Protocol) to send mail. (The client need not be web based. So, HTTP may not be involved here). POP (Post Office Protocol) is used to retrieve mail from mail server. HTTP (Hypertext transfer protocol) is used to transfer a HTML page containing the mail message that can be viewed on a web browser.
14. A layer-4 firewall (a device that can look at all protocol headers up to the transport layer) CANNOT GATE 2011 (A) Block entire HTTP traffic during 9:00PM and 5:00AM (B) Block all ICMP traffic (C) Stop incoming traffic from a specific IP address but allow outgoing traffic to the same IP address (D) Block TCP traffic from a specific user on a multi-user system during 9:00PM and 5:00Am ANS: A Statement for Linked Questions 15 and 16 Consider a network with five nodes, N1 to N5, as shown below.
166
The network uses a Distance Vector Routing protocol. Once the routes have stabilized, the distance vectors at different nodes are as following. N1: (0, 1, 7, 8, 4) N2: (1, 0, 6, 7, 3) N3: (7, 6, 0, 2, 6) N4: (8, 7, 2, 0, 4) N5: (4, 3, 6, 4, 0) Each distance vector is the distance of the best known path at the instance to nodes, N1 to N5, where the distance to itself is 0. Also, all links are symmetric and the cost is identical in both directions. In each round, all nodes exchange their distance vectors with their respective neighbors. Then all nodes update their distance vectors. In between two rounds, any change in cost of a link will cause the two incident nodes to change only that entry in their distance vectors. 15. The cost of link N2-N3 reduces to 2(in both directions). After the next round of updates, what will be the new distance vector at node, N3? GATE 2011 (A) (3, 2, 0, 2, 5) ANS: A
(B) (3, 2, 0, 2, 6)
(C) (7, 2, 0, 2, 5)
(D) (7, 2, 0, 2, 6)
16. After the update in the previous question, the link N1-N2 goes down. N2 will reflect this change immediately in its distance vector as cost, ∞. After the NEXT ROUND of update, what will be the cost to N1 in the distance vector of N3? GATE 2011 (A) 3 ANS: C
(B) 9
(C) 10
(D) ∞
17. One of the header fields in an IP datagram is the Time to Live (TTL) field. Which of the following statements best explains the need for this field? GATE 2010 (A) It can be used to prioritize packets (B) It can be used to reduce delays (C) It can be used to optimize throughput (D) It can be used to prevent packet looping ANS: D SOL: Whenever Time to live field reaches ‘0’ we discard the packet, so that we can prevent it from looping. 18. Which one of the following is not a client server application? (A) Internet chat ANS: D
(B) Web browsing
(C) E-mail
GATE 2010 (D) Ping
167
Statement for Linked Answer Questions: 19 & 20 Consider a network with 6 routers R1 to R6 connected with links having weights as shown in the following diagram
19. All the routers use the distance vector based routing algorithm to update their routing tables. Each router starts with its routing table initialized to contain an entry for each neighbor with the weight of the respective connecting link. After all the routing tables stabilize, how many links in the network will never be used for carrying any data? GATE 2010 (A) 4 (B) 3 (C) 2 (D) 1 ANS: D SOL: In Distance vector, the Router will update its routing tables by exchanging the information from all its neighbors. After all the routing tables stabilize the routing Table for ‘R1’ will not have any entry to Router R6., so that link will not be used. So one link. 20. Suppose the weights of all unused links in the previous question are changed to 2 and the distance vector algorithm is used again until all routing tables stabilize. How many links will now remain unused? GATE 2010 (A) 0 ANS: A
(B) 1
(C) 2
(D) 3
21. Which of the following statement(s) is / are correct regarding Bellman-Ford shortest path algorithm? P. Always finds a negative weighted cycle, if one exists. Q. Finds whether any negative weighted cycle is reachable from the source. GATE 2009 (A) P only (B) Q only (C) both P and Q (D) Neither P nor Q ANS: B SOL: The algorithm identifies a negative weight cycle iff it is reachable from Source.
168
22. Consider the following graph:
Which one of the following is NOT the sequence of edges added to the minimum spanning tree using Kruskal’s algorithm? GATE 2009 (A) (b,e) (e,f) (a,c) (b,c) (f,g) (c,d) (B) (b,e) (e,f) (a,c) (f,g) (b,c) (c,d) (C) (b,e) (a,c) (e,f) (b,c) (f,g) (c,d) (D) (b,e) (e,f) (b,c) (a,c) (f,g) (c,d) ANS: D SOL: Weight of edge (a,c) is less than (b,c) . So it cannot come after (b,c) 23. In the RSA public key cryptosystem, the private and public keys are (e, n) and (d, n) respectively, where n=p*q and p and q are large primes. Besides, n is public and p and q are private. Let M be an integer such that 0
View more...
Comments