GATE 2021 (Session 1)
65 questions
MCQ 34 · MSQ 13 · NAT 181-mark 30 · 2-mark 35
Questions 11–15 of 65
Suppose that is a regular language and is a context-free language. Which one of the following languages is NOT necessarily context-free?
Answer: (C)
Let be regular and be a CFL.
- The languages , and are always CFL, by closure properties.
- The language uses the complement of a CFL, and that need not be a CFL. For example, if , the result is only .
Answer:
- The languages , and are always CFL, by closure properties.
- The language uses the complement of a CFL, and that need not be a CFL. For example, if , the result is only .
Answer:
Let P be an array containing n integers. Let t be the lowest upper bound on the number of comparisons of the array elements, required to find the minimum and maximum values in an arbitrary array of n elements. Which one of the following choices is correct?
Answer: (C)
Take the elements two at a time. Compare the two with each other (1 comparison). Then compare the smaller one with the current minimum and the larger one with the current maximum (2 comparisons). That is 3 comparisons for every 2 elements. With the setup for the first pair, the total is comparisons. This is known to be the best possible, by an adversary argument. So .
Check against the options, for :
- Upper limit: , so .
- Lower limit: for even , when . For odd , when . So .
- (A) and (B) are wrong because is less than and less than . (D) is wrong because is more than .
Answer: (C)
Check against the options, for :
- Upper limit: , so .
- Lower limit: for even , when . For odd , when . So .
- (A) and (B) are wrong because is less than and less than . (D) is wrong because is more than .
Answer: (C)
Consider the following three functions.
Which one of the following options arranges the functions in the increasing order of asymptotic growth rate?
Which one of the following options arranges the functions in the increasing order of asymptotic growth rate?
Answer: (D)
Express each function with base 2:
-
-
-
Now look at the exponents. For large n:
Answer:
-
-
-
Now look at the exponents. For large n:
Answer:
Consider the following statements.
S1: The sequence of procedure calls corresponds to a preorder traversal of the activation tree.
S2: The sequence of procedure returns corresponds to a postorder traversal of the activation tree.
Which one of the following options is correct?
S1: The sequence of procedure calls corresponds to a preorder traversal of the activation tree.
S2: The sequence of procedure returns corresponds to a postorder traversal of the activation tree.
Which one of the following options is correct?
Answer: (C)
In an activation tree, a procedure is called (visited) before its children are. So the calls follow preorder. A procedure returns only after all of its children have returned. So the returns follow postorder.
Answer: S1 is true and S2 is true
Answer: S1 is true and S2 is true
Consider the following statements.
S1: Every SLR(1) grammar is unambiguous but there are certain unambiguous grammars that are not SLR(1).
S2: For any context-free grammar, there is a parser that takes at most time to parse a string of length n.
Which one of the following options is correct?
S1: Every SLR(1) grammar is unambiguous but there are certain unambiguous grammars that are not SLR(1).
S2: For any context-free grammar, there is a parser that takes at most time to parse a string of length n.
Which one of the following options is correct?
Answer: (C)
Let us check each statement.
- S1: An SLR(1) parsing table has no conflicts, so every SLR(1) grammar is unambiguous. Some unambiguous grammars are not SLR(1) (for example, many LALR/LR(1) grammars) TRUE.
- S2: The CYK algorithm can parse any CFG (written in CNF) in time TRUE.
Answer: S1 is true and S2 is true
- S1: An SLR(1) parsing table has no conflicts, so every SLR(1) grammar is unambiguous. Some unambiguous grammars are not SLR(1) (for example, many LALR/LR(1) grammars) TRUE.
- S2: The CYK algorithm can parse any CFG (written in CNF) in time TRUE.
Answer: S1 is true and S2 is true