Computer Science Engineering (CSE) Exam  >  Computer Science Engineering (CSE) Tests  >  Question Bank for GATE Computer Science Engineering  >  Test: Context-Free Language - Computer Science Engineering (CSE) MCQ

Test: Context-Free Language - Computer Science Engineering (CSE) MCQ


Test Description

10 Questions MCQ Test Question Bank for GATE Computer Science Engineering - Test: Context-Free Language

Test: Context-Free Language for Computer Science Engineering (CSE) 2024 is part of Question Bank for GATE Computer Science Engineering preparation. The Test: Context-Free Language questions and answers have been prepared according to the Computer Science Engineering (CSE) exam syllabus.The Test: Context-Free Language MCQs are made for Computer Science Engineering (CSE) 2024 Exam. Find important definitions, questions, notes, meanings, examples, exercises, MCQs and online tests for Test: Context-Free Language below.
Solutions of Test: Context-Free Language questions in English are available as part of our Question Bank for GATE Computer Science Engineering for Computer Science Engineering (CSE) & Test: Context-Free Language solutions in Hindi for Question Bank for GATE Computer Science Engineering course. Download more important topics, notes, lectures and mock test series for Computer Science Engineering (CSE) Exam by signing up for free. Attempt Test: Context-Free Language | 10 questions in 30 minutes | Mock test for Computer Science Engineering (CSE) preparation | Free important questions MCQ to study Question Bank for GATE Computer Science Engineering for Computer Science Engineering (CSE) Exam | Download free PDF with solutions
Test: Context-Free Language - Question 1

Consider the languages L1 = {0i1j | i ≠ j}. L2 = {0i1j | i = j}. L3 = {0i1j | i = 2j + 1}. L4 = {0i1j | i ≠ 2j} Which one of the following statements is true?

Detailed Solution for Test: Context-Free Language - Question 1

L1 = {0i1j | i ≠ j} → Context free
A regular expression for this is (0*1*)
A language that generates a regular expression is called regular language that is accepted by deterministic finite automata(DFA) can also be accepted by PDA
So, this language is also a context-free language
L2 = {0i1j | i = j} → Context free
First, push 0 into a stack then pop 0 for each 1 from the stack. The given language is accepted by
Deterministic Pushdown Automaton. Therefore, L2  is deterministic context-free.
L3 = {0i1j | i = 2j + 1} → Context free
If first 0 came then do nothing and for others 0's, for each zero push two 0's on the stack, and when 1 comes then pop two 0's for each 1 from the stack.
here pushing two 0's sounds non-deterministic but we push one symbol on the stack so it is deterministic
So, the given language is accepted by
Deterministic Pushdown Automaton. Therefore, L2  is deterministic context-free.
L4 = {0i1j | i ≠ 2j} → Context-free
let's take i = 2j +1
so it becomes as language L3
So, the given language is accepted by
Deterministic Pushdown Automaton. Therefore, L2  is deterministic context-free.
So, all the language are context-free

Test: Context-Free Language - Question 2

Which of the following languages are context free ?
L1 = {aibj ck | i< j < k}
L2 = {am bn | m≠n and m ≠2n}

Detailed Solution for Test: Context-Free Language - Question 2

L1 = {aibj ck | i < j < k} is not context free
We can prove this using the pumping lemma also let pumping constant = n
String S = an bn+1 cn+2∈L
Let S = uvwxy where |vx| ≥1 and |vwx| ≤n

Cases :

  • vwx is in an : for i = 2, S1 = uviwxiy has more or equal a’s than b’s ⇒ S1∉L
  • vwx is in bn : for i = 0, S1 = uviwxiy has more or equal a’s than b’s ⇒ S1∉ L
  • vwx is in cn : for i = 0, S1 = uviwxiy has more or equal b’s than c’s ⇒ S1∉ L
  • vwx contains both a and b i.e. an bn+1 :
  • Since x has atleast one b, for i = 2, S1 = uviwxiy has more b’s than c’s ⇒ S1∉ L
  • vwx contains both b and c i.e. bn+1 cn+2 since v has atleast one b, for i = 0,

S1 = uviwxi y has more or equal a’s than b’s ⇒ S1∉ L                              
So we can say that by pumping lemma, given language is not CFL.
L2 = {am bn | m ≠n and m ≠2n} is CFL
L2 can be define as  L21 = {am bn | m < n}
L22 = {am bn | n < m < 2n}
L23 = {am bn | m > 2n}
So, L2 = L21∪L22∪L23
As there exists CFGs for L21, L22 and L23 and since union of CFL’s is a CFL. Thus L2 is CFL.

1 Crore+ students have signed up on EduRev. Have you? Download the App
Test: Context-Free Language - Question 3

Suppose that L1 is a regular and L2 is a context-free language, Which one of the following languages is NOT necessarily context-free?

Detailed Solution for Test: Context-Free Language - Question 3

Concepts:
Operation under which context-free language is not closed: Intersection, complementation, set difference
Operation under which context-free language is closed: Union, Kleene Closure, and Concatenation.
Context-free language is closed under Intersection with regular language.

L1 is a regular and L2 is a context-free language.
Every regular language is context-free language.

Option 1: context-free language
L1.L2 it is the context-free language because it is closed under Concatenation.

Option 2: context-free language
L1 ∪ L2 it is the context-free language because it is closed under Union.

Option 3: context-free language
L1∩L2 it is the context-free language because context-free language is closed under Intersection with regular language.

Option 4: may not be context-free language
L1 - L2  it may not be context-free language because it is not closed under complementation.

Test: Context-Free Language - Question 4

Consider the following languages:
L1 = {anbmcn + m: m, n ≥ 1}
L2 = {anbnc2n: n ≥ 1}
Which one of the following is TRUE?

Detailed Solution for Test: Context-Free Language - Question 4

Statement I: L1 = {an bm cn + m: m, n ≥ 1}
L1 can be accepted easily by single stack. First, push a’s into stack, then push b’s into stack then read c’s and pop b’s, when no b’s left on stack, then keep reading c’s and pop a’s. When no c’s left in input and stack is empty then accepted by only one stack. Hence L1 is a context free language.
Statement II: L2 = {anbnc2n: n ≥ 1}
This language can’t be accepted by a single stack. When we push a’s into stack and pop them with b’s then it satisfies number of a’s = number of b’s but we left with empty stack and c’s in input. We can’t ensure that number of c’s are double than a and b’s. A push down automata can’t remember number of a’s for third set of characters, that is. c.
Hence L2 is a context sensitive language but not context free language.

Test: Context-Free Language - Question 5

Which one of the following languages over Σ = {a, b} is NOT context-free?

Detailed Solution for Test: Context-Free Language - Question 5
  • {wanbnwR |w ∈ {a, b}*, n ≥ 0} is accepted by a non-deterministic pushdown automaton and hence it is a context-free language
  • {wwR |w ϵ {a, b}*} is accepted by a non-deterministic pushdown automaton and hence it is context-free language.
  • {wanwRbn|w ∈ {a, b}*, n ≥ 0} is not accepted by a pushdown automaton and hence it is not a context-free language.
  • i = n, 2n, 3n, 4n, etc. forms and arithmetic series. anbn, anb2n and anb3n is accepted by a deterministic pushdown automaton and context-free language are closed under union and hence anbn ∪ anb2n ∪ anb3n is a context-free language. Hence {anbi |i ∈ {n, 3n, 5n}, n ≥ 0} is a context-free language.
Test: Context-Free Language - Question 6

Context free grammar is not closed under:

Detailed Solution for Test: Context-Free Language - Question 6

Concept:
Context free languages are closed under Union, Concatenation and Kleene Closure (star)
CFLs are NOT closed under intersection and not closed under complementation
Example:
L1 = pn qn rm | m, n > 0 → CFL
L2 = pm qn rn  | m, n > 0 → CFL
L = pn qn rm ∩ pm qn rn  | m, n > 0. L = pn qn rn it is not accepted by pushdown automaton and hence it is not a CFL. and hence it is not closed under intersection.

Test: Context-Free Language - Question 7

Let S be an NP-complete problem. Q and R are other two problems not known to be NP. Q is polynomial time reducible to S and S is polynomial time reducible to R. Which of the following statements is true?

Detailed Solution for Test: Context-Free Language - Question 7
  • If the NP-Hard problem is reducible to another problem in polynomial time, then that problem is also NP-hard which means every NP problem can be reduced to this problem in polynomial time.
  • If Q is reducible to S in polynomial time, Q could be NP because all NP problems can be reduced to S. Since Q could be Np therefore Q could be P also as P is a subset of NP. Also, Q could be NPC because every NPC problem can be reduced to another NPC problem in polynomial time. 
*Answer can only contain numeric values
Test: Context-Free Language - Question 8

Consider the following CFL
L1 = {an|n≥1}
L2 = {bnan|n≥1}
L3 = {0n1m |n = 2m, n,m ≥ 0}
L4 = {ap|p is odd number}
How many statements are true?
(i) Complement of L1 is also regular.
(ii) Union of L2 and L3 is also CFL
(iii) Intersect of L1 and L4 is also CFL
(iv) Concatenation of L1 and L2 is also CFL


Detailed Solution for Test: Context-Free Language - Question 8

Concept:
The given grammar is,
L1 = {an|n ≥ 1} 
It regular grammar, 


L2 = {bnan|n ≥ 1}
It is not regular but DCFL because we need to compare a number of b's with the number of a's so we need one stack for comparisons.
L3 = {0n1m |n = 2m, n,m ≥ 0}
It is not regular but DCFL because we need to compare a number of b's with the number of a's so we need one stack for comparisons.
L4 = {ap|p is odd number}
It regular grammar,

(i) Complement of L1 is also regular.
True, L1 is regular so complement is also regular and every regular is context-free so it is true.
(ii) Union of L2 and L3 is also CFL
True, the Union of two CFLs is also CFL by closure property.
(iii) Intersect of L1 and L4 is also CFL
True, L1 and L4 both are regular and the intersection of regular is also regular and every regular is CFL.
(iv) Concatenation of L1 and L2 is also CFL.
True, the Concatenation of two CFLs is always CFL.

*Multiple options can be correct
Test: Context-Free Language - Question 9

Consider the following languages:
L1 = {ww | w ∈ {a, b}*}
L2 = {anbncm | m, n ≥ 0}
L3 = {ambncn | m, n ≥ 0}
Which of the following statements is/are FALSE?

Detailed Solution for Test: Context-Free Language - Question 9

Option 1: L1 is not context-free but L2 and L3 are deterministic context-free. 
True, L1 is not context-free and L2 and L3 are clearly DCFLs since they have only one comparison and DPDA can accept both.

Option 2: Neither L1 nor L2 is context-free.
False, L2 is DCFL and every DCFL is a CFL.
L2 - Context-free.
L3 - Context-free.
L2 ∩ L3 = {anbncn or ambmcm , m, n > = 0}
This language is context sensitive language.

Option 3: L2, L3 and  L2 ∩ L3 all are context-free.
False, 
L2 - Context-free.
L3 - Context-free.
L2 ∩ L3 = {anbncn, n > = 0} We can not compare the anbncn  with one single stack. Hence it is not context-free.

Option 4: Neither L1 nor its complement is context-free.
False, L1 - Not context-free.
L1' Complement of L1 is accepted by a context-free grammar is CFL.
Hence the correct answer is option 2, option 3 and option 4.

Test: Context-Free Language - Question 10

Consider the language L = {an |n ≥ 0} ∪ {anbn| n ≥ 0} and the following statements.
I. L is deterministic context-free.
II. L is context-free but not deterministic context-free.
III. L is not LL(k) for any k.
Which of the above statements is/are TRUE?

Detailed Solution for Test: Context-Free Language - Question 10

Statement I: TRUE.
L = {an |n ≥ 0} ∪ {anbn| n ≥ 0}
{an |n ≥ 0} is a regular language and {anbn| n ≥ 0} is a DCFL and hence, there Union would be a DCFL.

Statement II: FALSE.
L is DCFL then it is CFL too.

Statement III: TRUE
L cannot be LL(k) for any number of look-ahead. LL(k) cannot conclusively distinguish that whether the string to be parsed is from an or from anbn. Both have a common prefix.

63 videos|8 docs|165 tests
Information about Test: Context-Free Language Page
In this test you can find the Exam questions for Test: Context-Free Language solved & explained in the simplest way possible. Besides giving Questions and answers for Test: Context-Free Language , EduRev gives you an ample number of Online tests for practice

Top Courses for Computer Science Engineering (CSE)

Download as PDF

Top Courses for Computer Science Engineering (CSE)