0% found this document useful (0 votes)
39 views

Expected Questions in GATE 2022 Part I With Anno

gate
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
0% found this document useful (0 votes)
39 views

Expected Questions in GATE 2022 Part I With Anno

gate
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 84
y ho Expected Questions in GATE 2022 - Part I Course on Most Expected Questions in GATE 2022 Crt eee ener ys) Which one of the following is a top-down parser? (A) Recursive descent parser. (ClAM LRU) parser, (D) An LALR(k) parser — (E) Non-Recursive Descent Parser(/ L w) F) Operator Precedence Pa Consider a CFG with the following Productions. a 5 | S is the start symbol, A and B are inet mindinanana and 0 and 1are the terminals. The language generated by this grammar is Amo] a “i *a Fm, ‘tha (D) The set of all strings over {0, : containing at least t sis = , Ao O Iho gid oS |e 49 AF 0 Suppose that L1 is a regular language and L2 is a context- free language. Which one of the following languages is NOT necessarily context-free? ins (A) Lanka =) 2bacel = cel 7 (Boe (B)L1-L2 => R cr = : com TU ats "= Roe = La = L0&aa, = C)Li-L2 == (D) L1UL2 Srtucel =] cel Vv { \ yn \ TEI lyk, => Ly as => 1s — - (_cen@y" => cone ee WA) ee ee i) a) coy) = p Q ep Cake a (es ne a & (ar) UV an 2 — eee wa ae e ae i eee oy eae, Ge —_ fi (Deel O carne eam aaa eel — Let L1 be a regular language and L2 be a context-free language. Which of the ee languages ar 99) Aceh cst cl 3 1. bat? a) — eS eackl (Ly UL, )” y's pe noes 4. (L,nL,) vu (L,- n L2) we», Se) is Cia Av hae ye u (eeaon fecao ad amare) (Ave) The following program computes ines of a mathematical function f(x). Determine the form of f(x). main () 4 { at int m, n; ¢! SS i float x, y, t; Jo00° . scanf ("%f%d", &%, &n); t=1;y=0;m=1; do eit 8 poses at aa ae 7 ‘ yt=t _ _ +e? } while (mi < ; = + +20 31 ql Si printf ("The value of y is %f", y); } Tar mn G73 rr Consider the following two statements:— DrFYj .~ |. If all states of an NFAvare accepting states then the language accepted by the NFA is 2+. I There exists aégular language A such that for all languages B, AN B is regular. Which o} following is CORRECT? Gena 3) od (A) Only lis true / BEN ee (BY Only Ilis true t 1 (C) Both I and Il are true ote (D) Both I and Il are false Ald Let N be an NFA with n states. Let k be the number of - of a minimal DFA which is equivalent to N. Which one of the following is necessarily true? pom? : ; nop lp a _ a) a A ype ee Hale a Consider the following languages: L1 = {a"b™"c™: m, n >= 1} L2 = {a"b?"c": n >= 1} Which one of the following is TRUE? (A) Both L1 and L2 are context-free. (B) L1 is context-free while L2 is not context-free. (C) L2 is context-free while L1 is not context-free. (D) Neither L1 nor L2 is context-free Let w be any string of length n in {0,1}*. Let L be the set of all substrings of w. What is the minimum number of states in non- deterministic finite automation that accepts L? 1.n-1 2.n 3. n+1 4. 2n-1 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 S->aB S->bA B->b A->a B->bS A->aS B->aBB A-> bAA Which of the following strings is generated by the grammar? (A) aaaabb (B) aabbbb (©) aabbab (D) abbbba The maximum number of nodes in Binary Search Tree of height ‘h’ which have same inorder and preorder (Assume h = 2018 and root is at height 0) 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 set of rules: S --> iCtSS,|a S, --> eSle C-->b The grammar is NOT LL(1) because (A) it is left recursive (B) it is right recursive (C) it is ambiguous (D) It is not context-free 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 The following code segment is executed on a processor which allows only register operands in its instructions. Each instruction can have at most two source operands and one destination operand. Assume that all variables are dead after this code segment. Which of the following problems are decidable? 1) Does a given program ever produce an output? 2) If Lis context-free language, then is L'(complement of L) also context-free? 3) If Lis regular language, then is L'(complement of L) also regular? 4) If Lis recursive language, then is L'(complement of L) also recursive? (A) 1,2,3,4 (B) 1,2 (C)2,3,4 (D) 3,4 Consider the following sets: S,: Set of all recursively enumerable languages over the alphabet {0, 1}. S,: Set of all syntactically valid C programs. S3: Set of all languages over the alphabet {0, 1}. S,: Set of all non-regular languages over the alphabet {0, 1}. Which of the above sets are uncountable? (A) S, and S, (B) S; and S, (C) S; and Sq (D) S, and S, Consider a sorted array of integers of size n with duplicate elements. You have been given an element k, what is the time complexity to find that the element k is appeared at least n/4 times or not? Consider the following problems. L(G) denotes the language generated by a grammar G. L(M) denotes the language accepted by a machine M. (I) For an unrestricted grammar G and a string w, whether weL(G) (II) Given a Turing machine M, whether L(M) is regular (I) Given two grammar G, and G,, whether L(G,) = L(G.) (IV) Given an NFA N, whether there is a deterministic PDA P such that N and P accept the same language Which one of the following statement is correct? (A) Only | and I are undecidable (B) Only Il is undecidable (C) Only Il and IV are undecidable (D) Only |, Il and Ill are undecidable Let L(R) be the language represented by regular expression R. Let L(G) be the language generated by a context free grammar G. Let L(M) be the language accepted by a Turing machine M. Which of the following decision problems are undecidable? I. Given a regular expression R and a string w, is w € L(R)? ll. Given a context-free grammar G, is L(G)=0 Ill. Given a context-free grammar G, is L(G)=2* for some alphabet £? IV. Given a Turing machine M and a string w, is w € L(M)? (A) | and IV only (B) I and Ill only (C) U1, tl and IV only (D) II and IV only Consider the following Syntax Directed Translation Scheme (SDTS), with non-terminals {S, A} and terminals {a, b} S — aA { print! } S — a {print2} A — Sb {print3} Using the above SDTS, the output printed by a bottom-up parser, for the input aab is (A) 132 (B) 223 (c)231 (D) Syntax Error Conkicduy te Following SDT coco gl = soul} 65 561 { sevad = Sval +f C584 ved =o} Wheat YP cAlo0nrZ. SDT whet &/P 1) 1 COiIL prredace wil) take? Consider a stack S given below with elements 1,2,3 along with the usual operations push(), pop() and top() as shown. SDT: 1 A>BxC {S.push)} 3 Boc/D {Spop()} CoA (Stop()} 2 BCD idnum —{Stop()} Stack 'S' Input string: 1/2 x 3x4 The number of elements that will remain in the stack after the parsing of the input string and stack according to the above SDT rules is se SDT Corkidn Ite Fothoway Aet = Bi Aa abcD Oe ' Bs=acs ' — ate buted @) L- ateibted (&) & ne. ©, bok atte A) A Corkidiy te frtlowing Flow araph | Ty Which ore dy ie Ft owding- 58 Corvect ? @ = 4b, cm vt @) x= 4 bic Xe v} 0, = 4 bict = 4 wcr% Vf © a> dart @ Ar facern rt 0, =f xuvb O= 4x4 Which of the following statements is FALSE ? (A) In statically typed language, each variable in a program has a fixed type (B) In un-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 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 The program below uses six temporary variables a, b, c, d, e, f. a=1 b=10 return d+f Assuming that all operations take their operands from registers, what is the minimum number of registers needed to execute the above program after optimizing code and without spilling? (A)2 (B)3. (C)4_—s (DN Tm, The following code segment is executed on a processor which allows only register operands in its instructions. Each instruction can have at most two source operands and one destination operand. Assume that all variables are dead after this code segment. Suppose the instruction set architecture of the processor has only two registers. The only allowed compiler optimization is code motion, which moves statements from one place to another while preserving correctness. What is the minimum number of spills to memory in the compiled code? (a)o (B) 1 (c)2 (D) 3 A pushdown automaton P transition of the form, Py x—3¥ @ where p,q €Q,a Ea U {e}, X,Y € FUf{e}. Consider the following pushdown automaton over the input alphabet = = {a, b} and stack alphabet [={#,A}. aesA bAse a n sat ($F (yA gy 8474 The number of strings of length 100 accepted by the above pushdown automaton is-------- (a) 50 (B) 100 (c) 55 (D) 45 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 set of rules: S --> iCtSS,|a S, --> eSle C-->b The grammar is NOT LL(1) because (A) it is left recursive (B) it is right recursive (C) it is ambiguous (D) It is not context-free Consider the following problems. L(G) denotes the language generated by a grammar G. L(M) denotes the language accepted by a machine M. (I) For an unrestricted grammar G and a string w, whether weL(G) (II) Given a Turing machine M, whether L(M) is regular (I) Given two grammar G, and G,, whether L(G,) = L(G.) (IV) Given an NFA N, whether there is a deterministic PDA P such that N and P accept the same language Which one of the following statement is correct? (A) Only | and I are undecidable (B) Only Il is undecidable (C) Only Il and IV are undecidable (D) Only |, Il and Ill are undecidable Consider the productions A> PQ andA > XY. Each of the five non-terminals A,P,Q,X, and Y has two attributes: s is a synthesized attribute, and iis an inherited attribute. Consider the following rules. i=A.i+2, Q.i=P.i+A.i, and A.s=P.s+Q.s “STAI Which one of the following is TRUE ? (A) Both Rule 1 and Rule 2 are L-attributed (B) Only Rule 1 is L-attributed (C) Only Rule 2 is L-attributed (D) Neither Rule 1 nor Rule 2 is L-attributed Lk & be a Finile non-empl5 adphaber ond 2& be Ite powersot 2% which or df it Flowing’ true @ © 2, es counreWa- © é; 2 Unoura , © 2? — Cont Ma, EF uncon @ 2 — uncounre , 2 Cosntatte. Let L(R) be the language represented by regular expression R. Let L(G) be the language generated by a context free grammar G. Let L(M) be the language accepted by a Turing machine M. Which of the following decision problems are undecidable? I. Given a regular expression R and a string w, is w € L(R)? ll. Given a context-free grammar G, is L(G)=0 Ill. Given a context-free grammar G, is L(G)=2* for some alphabet £? IV. Given a Turing machine M and a string w, is w € L(M)? (A) | and IV only (B) I and Ill only (C) U1, tl and IV only (D) II and IV only Consider the following C code segment: 4: +4; 5.g=erf; In a compiler, this code segment is represented internally as a directed acyclic graph (DAG). The number of nodes in the DAG is------- Which of the following sets can be recognized by a Deterministic Finite-state Automaton? (A) The number 1, 2, 4, 8......,24n,.......... Written in binary. (B) The number 1, 2, 4,....., 24n,.......... Written in unary. (C) The set of binary strings in which the number of zeros is the same as the number of ones. (D) The set {1, 101, 11011, 1110111........} Consider the basic block given below. a=btec c=at+d d=btc e=d-b a=etb The minimum number of nodes and edges present in the DAG representation of the above basic block respectively are 1. 6and6 2. 8and10 3. 9and 12 4. 4and4 DAK min ni-vy nodal J Sel E-A+B er eE-c G =< FeD Wea A+B Te 2-C zy =iI+h bea min nord nodf ) 22 pgs cd EQ= arb b= beta ty ~ tate Given ¥ = {a, b}, which of the following sets is not countable ? (A) Set of all strings over 5 (B) Set of all languages over > (C) Set of all regular languages over > (D) Set of all languages over 5 accepted by Turing machines For a statement S in a program, in the context of liveness analysis, the following sets are defined: *USE(S) : the set of variables used in S *IN(S) : the set of variables that are live at the entry of S *OUT(S) : the set of variables that are live at the exit of S Consider a basic block that consists of two statements, $1 followed by S2. Which one of the following statements is correct? (A) OUT(S1) = IN (S2) (B) OUT (S1) = IN (S1) U USE (51) (C) OUT (S1) = IN (S2) U OUT (S2) (D) OUT (S1) = USE (S1) U IN (S2) For aC program accessing X{i][j][k], the following intermediate code is generated by a compiler. Assume that the size of an integer is 32 bits and the size of a character is 8 bits. i+ 1024 * 32 3 + t2 5 = X[t4] Which one of the following statements about the source code for the C program is CORRECT? (A) X is declared as “int X[32][32][8]” (B) X is declared as “int x[4][1024][32]” (C) X is declared as “char X[4][32][8]” (D) X is declared as “char X[32][16][2]” Consider the following ANSI C program 1.#include 2.int foo(int x, int y, int q) 3. 1.int main( ) 4.if ((x<=0) && (y<=0)) 24 5.return q; 3.int r = foo(15, 15, 10); 6.if (x<=0) 4.printf(“%d”, r); 7.return foo(x, y-q, 4); 5.return 0; 8.if (y<=0) 6} 9.return foo(x-q, y, q); 10.return foo(x, y-q, q) + foo(x-q, y, q); 11.} The output of the program upon execution is A canonical set of items is given below S-->L.>R Q-->R. On input symbol < the set has (A) a shift-reduce conflict and a reduce-reduce conflict. (B) a shift-reduce conflict but not a reduce-reduce conflict. (C) a reduce-reduce conflict but not a shift-reduce conflict. (D) neither a shift-reduce nor a reduce-reduce conflict. The height of a tree is defined as the number of edges on the longest path in the tree. The function shown in the pseudo-code below is invoked as height (root) to compute the height of a binary tree rooted at the tree pointer root. int height (treeptr n) { if (n== NULL) return -1; if (n+ left == NULL) if (n + right =NULL) return 0; else return [BI]; // Box 1 else {h1 = height (n — left); if (n > right = NULL) return (1+h1); else {h2 = height (n — right); return [B2] ; // Box 2 e The appropriate expression for the two boxes B1 and B2 are (A) B1 : (1 + height(n->right)), B2 : (1 + max(h1,h2)) (B) B1 : (height(n->right)), B2 : (1 + max(h1,h2)) (C) B1 : height(n->right), B2 : max(h1,h2) (D) B1 : (1 + height(n->right)), B2 : max(h1,h2) A binary search tree 7 contains 7 distinct elements. What is the time complexity of picking an element in T that is smaller than the maximum element and larger than minimum element in T ? 1.0(nlogn) 2.0(n) 3.0(logn) 4.0(1) A Binary Search Tree (BST) stores values in the range 37 to 573. Consider the following sequence of keys. I. 81, 537, 102, 439, 285, 376, 305 Il. 52, 97, 121, 195, 242, 381, 472 Ill. 142, 248, 520, 386, 345, 270, 307 IV. 550, 149, 507, 395, 463, 402, 270 Suppose the BST has been unsuccessfully searched for key 273. Which all of the above sequences list nodes in the order in which we could have encountered them in the search? (A) Il and Il only (B) land Ill only (C) Ill and IV only (D) Il only % corveck Pre-ordsy souville$f J OST ° (BST conoiny 12.3459) ’) Ss3i2z478& @) 53126487 c) s3224uUl67€& pd) SZIZ2ZUF96¢E 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 void find_and_replace(char *A, char *oldc, char *newc) (4) oldc = "abc", newc = "bac” The tester now tests the program on all input strings of length five consisting of characters ‘a’, ‘b’, ‘c’, ‘d’ and ‘e’ with duplicates allowed. If the tester carries out this testing with the four test cases given above, how many test cases will be able to capture the flaw? (A) Only one (B) Only two (C) Only three (D) All four 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 What is the return value of f(p, p) if 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 (B) 6561 (c) 55440 (D)161051 Consider a sorted array of integers of size n with duplicate elements. You have been given an element k, what is the time complexity to find that the element k is appeared at least n/4 times or not? The maximum number of nodes in Binary Search Tree of height ‘h’ which have same inorder and preorder (Assume h = 2018 and root is at height 0) Consider an ambiguous grammar G and its disambiguated version D. Let the language recognized by the two grammars be denoted by L(G) and L(D) respectively. Which one of the following is true ? (A) L(D) C L(G) (B) L(D) > L(G) (C) L(D) =L (G) (D) L (D) is empty Consider the following rooted tree with the vertex labelled P as the root: P The order in which the nodes are visited during in- order traversal is (a) SQPTRWUV (8) SQPTURWV (Cc) SQPTWUVR (D) SQPeTRUWV The string 1101 does not belong to the set represented by (A) 110*(0+1) (B) 1(0+1)*101 (C) (10)*(01)*(00+11)* (D) (00+(11)*0)* Consider these two functions and two statements S1 and S2 about them int work1(int *a, int i, int j) { int x = a[i+2]; alj] = x+1; return a[i+2] - 3; } int work2(int *a, int i, int j) { int t1 = i+2; int t2 = a[t1]; afj] = t2+1; return t2 — 3; $1: The transformation form work1 to work2 is valid, i.e., for any program state and input arguments, work2 will compute the same output and have the same effect on program state as work1 $2: All the transformations applied to work1 to get work2 will always improve the performance (i.e reduce CPU time) of work2 compared to work1 (A) S1 is false and S2 is false (B) S1 is false and S2 is true (C) $1 is true and S2 is false (D) S1 is true and $2 is true Consider the regular expression (0+1)(0+1)... 26 times. The minimum state finite automaton that recognizes the language represented by this regular expression contains: (A) 26 states (B) 27 states (C) 28 states (D) None of the above Which one of the following grammars is free from left recursion? (A (B) «© (~) wh Bn Bau bot thd CbL tdd yu AB Aa < Ab Bd e Aa Bb d Aa Bd Ae Consider the following translation scheme. S>ER R > *E{print(“*”);}R | € E> F+E {print(“+”);} | F F > (S) | id {print(id.value);} Here id is a token that represents an integer and id.value represents the corresponding integer value. For an input ‘2 * 3 +4’, this translation scheme prints (A)2*3+4 (B) 2 * +34 (c)23*4+ (D) 23 4+* Consider the DFAs M and N given above. The number of states in a minimal DFA that accepts the language L(M) 2 L(N) is --------- b a a b M Ly N cee a (A) 0 (B) 1 (c)2 (D) 3 Consider the language L given by the regular expression (a + b) *b(a +b)(a+b) over the alphabet {a, b}. The smallest number of states needed in a deterministic finite-state automaton (DFA) accepting L is --------- (A) 3 (B)7 (c)5 (D) 8 Consider a hash table with chaining scheme for overflow handling: 1.For what type of instance does this hashing scheme take the worst-case time for insertion? 2.What is the worst-case timing complexity of inserting n elements into such a table? Let L= { we(0+1)* | w has even number of 1s}. i.e. Lis the set of all the bit strings with even numbers of 1s. Which one of the regular expressions below represents L? 1. (0*10*1)* 2. 0*(10*10*)* 3. 0*(10*1)*0* 4. 0*1(10*1)*10* Corbidiv tte Following Co Program. int main() { static int a[2][3] = {1, 2, 3, 4, 5, 6}; int i, J: static int *p(] = {(int*)a, (int*)a+1, (int*)a+2}; for(i=0; i<2; i++) for(j=0; 4<3; j++) printf ("%d, %d, %d, %d\n", *(*(p+i)+3), *(*(i+p) +i), *(* (itp) +5), *(* (pti) +i)); return 0; Whak will be Ie ap ® int arr[2][3][2]; print(arr[1]-arr[0],arr[1][0]-arr{0][0}) whak iS tte owkpulk Let w be any string of length n in {0,1}*. Let L be the set of all substrings of w. What is the minimum number of states in non- deterministic finite automation that accepts L? 1.n-1 2.n 3. n+1 4. 2n-1 Which of the following languages is/are regular? L1: {wxwR | w, Xx € {a, b}* and Iwl, Ix >0} wk is the reverse of string w L2: {a"b™ t #n and m, n20 L3: {aPb4c' | p, q, r 2 0} (A) Li and L3 only (B) L2 only (C) L2 and L3 only (D) L3 only Consider the following two statements about regular languages: °S1: Every infinite regular language contains an undecidable language as a subset. *S2: Every finite language is regular. Which one of the following choices is correct? A.Only S11 is true B.Only S2 is true C.Both S1 and S2 are true D.Neither S1 nor S2 is true For a string w, we define w® to be the reverse of w. For example, if w = 01101 then w® = 10110. Which of the following languages is/are context-free? (A) {wxw®x® | w,xE{0,1}*} (B) {ww®xx® | w,x€{0,1}*} (C) {wxw® | w,x€{0,1}*} (D) {wxx?w® | w,xE{0,1}*}

You might also like