Option 3 : All odd length palindromes

__Concept:__

S → aSa | bSb | a | b generates strings like {a, b, aaa, bbb, aba, bab, abbba, ababa, ….) which is the set of all odd length palindromes.

__Example of odd length pallindrom. __

String: ababa

__Option 1:__ Incorrect

String: “aa” (Not accepted)

Begins and ends with same symbol but not accepted by given grammar

__Option 2 and 4:__ Incorrect

String: “aa” (Not accepted)

Even length palindrome is not accepted by given grammarConsider the following grammar:

stmt → **if** expr **then** expr **else** expr; stmt | ȯ

expr → term **relop** term | term

term → id | number

id → **a** | **b** | **c**

number → [**0 – 9**]

where **relop** is a relational operator (e.g ., < , >, …), ȯ refers to the empty statement, and if, **then**, **else** are terminals.

Consider a program P following the above grammar containing ten **if** terminals. The number of control flow paths in P is _______. For example. The program.

**if** e_{1 }**then** e_{2} **else** e_{3}

**Concept:**

A control flow path / control flow graph is a graphical representation of all paths that might be traversed through a program during its execution.

**Explanation: **

Now, each if statement has 2 outcomes – either true and false. As per the grammar, each if statement is independent of the other.

Statement of type **if** e_{1 }**then** e_{2} **else** e_{3 }has 2 control flow paths, e_{1 }**→** e_{2} and e_{1} **→** e_{3}

**Calculation:**

To get control paths for 10 if terminals i.e.

**if** expr **then** expr **else** expr; stmt

**if** expr **then** expr **else** expr; stmt

………. (10 times)

As one if statement has 2 control paths so for 10 we have,

2 × 2 × 2 × 2 × 2 × 2 × 2 × 2 × 2 × 2 = 1024Consider the following problems. L(𝐺) denotes the language generated by a grammar 𝐺. L(𝑀) denotes the language accepted by a machine 𝑀.

(I) For an unrestricted grammar 𝐺 and a string 𝑤, whether 𝑤 ∈ (𝐺)

(II) Given a Turing machine M, whether L(M) is regular

(III) Given two grammars 𝐺_{1} and 𝐺_{2}, whether (𝐺_{1}) = (𝐺_{2})

(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 statements is correct?

Option 4 : Only I, II and III are undecidable

Membership algorithm does not exist for unrestricted grammars.

Regularity problem for TM is undecidable.

Equivalence of Two grammar is undecidable.

Every NFA is a PDA with a finite memory.

Consider grammar G with productions A → a | Aa | bAA | AAb | AbA

Choose a false statement :

Option 2 : abb is in L(G)

**Concept:**

A grammar G is formally defined as a tuple (N, ∑, P, S ). Such formal grammar is often called a rewriting system.

N → Nonterminal symbol

∑ → terminal symbol

P → Production rules

S →start symbol

**Explanation:**

Productions of G: A → a | Aa | bAA | AAb | AbA

N → {A}

P → { A → a | Aa | bAA | AAb | AbA}

∑ → {a, b}

S → {A}

__Option 1:__ TRUE

A → AAb → AAAbb → aaabb

aaabb is in L(G)

__ Option 2:__ FALSE

A → AAb → A**a**b →**a**ab

Therefore abb is not in L(G)

but **abb** is in L(G)

__Option3:__ TRUE

A is start symbol of G

__Option3:__ TRUE

A → AAb → A**AAb**b → AA**Aa**bb → AA**a**abb

→ Aaaabb → aaaabb

Therefore aaaabb is in L(G)

What is the highest type number that can be assigned to this following grammar:

*S*→*A**a*,* A*→*B**a*,* B*→*a**b**c*

Option 4 : Type 3

Above grammar generates string abcaa.

Type-3 or a regular grammar is a formal grammar that is right-regular or left-regular, given grammar is left-linear regular grammar hence it's a type-3 grammar.

Option 3 : All odd length palindromes

__Concept:__

S → aSa | bSb | a | b generates strings like {a, b, aaa, bbb, aba, bab, abbba, ababa, ….) which is the set of all odd length palindromes.

__Example of odd length pallindrom. __

String: ababa

__Option 1:__ Incorrect

String: “aa” (Not accepted)

Begins and ends with same symbol but not accepted by given grammar

__Option 2 and 4:__ Incorrect

String: “aa” (Not accepted)

Even length palindrome is not accepted by given grammarConsider the following grammar:

stmt → **if** expr **then** expr **else** expr; stmt | ȯ

expr → term **relop** term | term

term → id | number

id → **a** | **b** | **c**

number → [**0 – 9**]

where **relop** is a relational operator (e.g ., < , >, …), ȯ refers to the empty statement, and if, **then**, **else** are terminals.

Consider a program P following the above grammar containing ten **if** terminals. The number of control flow paths in P is _______. For example. The program.

**if** e_{1 }**then** e_{2} **else** e_{3}

**Concept:**

A control flow path / control flow graph is a graphical representation of all paths that might be traversed through a program during its execution.

**Explanation: **

Now, each if statement has 2 outcomes – either true and false. As per the grammar, each if statement is independent of the other.

Statement of type **if** e_{1 }**then** e_{2} **else** e_{3 }has 2 control flow paths, e_{1 }**→** e_{2} and e_{1} **→** e_{3}

**Calculation:**

To get control paths for 10 if terminals i.e.

**if** expr **then** expr **else** expr; stmt

**if** expr **then** expr **else** expr; stmt

………. (10 times)

As one if statement has 2 control paths so for 10 we have,

2 × 2 × 2 × 2 × 2 × 2 × 2 × 2 × 2 × 2 = 1024Consider the following problems. L(𝐺) denotes the language generated by a grammar 𝐺. L(𝑀) denotes the language accepted by a machine 𝑀.

(I) For an unrestricted grammar 𝐺 and a string 𝑤, whether 𝑤 ∈ (𝐺)

(II) Given a Turing machine M, whether L(M) is regular

(III) Given two grammars 𝐺_{1} and 𝐺_{2}, whether (𝐺_{1}) = (𝐺_{2})

(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 statements is correct?

Option 4 : Only I, II and III are undecidable

Membership algorithm does not exist for unrestricted grammars.

Regularity problem for TM is undecidable.

Equivalence of Two grammar is undecidable.

Every NFA is a PDA with a finite memory.

Consider grammar G with productions A → a | Aa | bAA | AAb | AbA

Choose a false statement :

Option 2 : abb is in L(G)

**Concept:**

A grammar G is formally defined as a tuple (N, ∑, P, S ). Such formal grammar is often called a rewriting system.

N → Nonterminal symbol

∑ → terminal symbol

P → Production rules

S →start symbol

**Explanation:**

Productions of G: A → a | Aa | bAA | AAb | AbA

N → {A}

P → { A → a | Aa | bAA | AAb | AbA}

∑ → {a, b}

S → {A}

__Option 1:__ TRUE

A → AAb → AAAbb → aaabb

aaabb is in L(G)

__ Option 2:__ FALSE

A → AAb → A**a**b →**a**ab

Therefore abb is not in L(G)

but **abb** is in L(G)

__Option3:__ TRUE

A is start symbol of G

__Option3:__ TRUE

A → AAb → A**AAb**b → AA**Aa**bb → AA**a**abb

→ Aaaabb → aaaabb

Therefore aaaabb is in L(G)

What of the following languages does the following grammar represent?

S → AAB

A → a/b

B → aB/bB/ε

Option 2 : The given grammar represents the strings of length atleast 2.

The given grammar generates the following strings: aa, ab, bb, aab, aba.......

Hence, the given grammar represents the strings of length atleast 2.

Therefore, the regular expression for the given grammar is (a+b)(a+b)(a+b)*.