Let P=a,b.Give a CFG generating the language of strings with twice as manya'sasb's . Prove that your grammar is correct.

Short Answer

Expert verified

P=a,b,generating the language of strings with twice as manya'sasb's.

Thecontext free grammar is,

SOS1aab|aS1ab|aabS1|S1aba|aS1ba|abaS1|S1baa|bS1aa|baS1a|baaS1S1S0|ε

The generated language is proved correct using induction.

Step by step solution

01

Define Context free grammar

The context free language is generated by context free grammar.

These languages are accepted by Pushdown Automata. These are the superset of regular languages.

Consider context-free languages L1described asG1=(V1,S,R1,S1).

Consider context-free language L2described asG2=(V2,S,R2,S2).

02

Determine the grammar generating language with twice as many a’s as b’s

P=a,b,generating the language of strings with twice as manya'sasb's .

Thecontext free grammar is,

SOS1aab|aS1ab|aabS1|S1aba|aS1ba|abaS1|S1baa|bS1aa|baS1a|baaS1S1S0|ε

03

Prove that the language generated is correct

Smallest strings possible are: x0{aab,aba,baa}

all of which haveNAxo=2NBxo,NAxo=2NBxo,

where NA(x)gives the number of a’s in string xand NBxgives the number of b’s in string x. Assume NAxn=2NBxn,holds. Show ifn is true n+1is also true, where xn+1is string xnwith substringsε,aab,aba,baa inserted. Subsequent insertions of S1 into strings produced, either add zero a’s and zero b’s or two a’s and one b .

P=a,b,generating the language of strings with twice as manya'sasb's.

Thecontext free grammar is,

SOS1aab|aS1ab|aabS1|S1aba|aS1ba|abaS1|S1baa|bS1aa|baS1a|baaS1S1S0|ε

The generated language is proved correct using induction.

Case when zero a’s and zero b’s are inserted.

NAxn+1=NAxn+0NBxn+1=NBxn+0NAxn+1=2NBxn+1

Case when two a’s and one b are inserted.

1NAxn+1=NAxn+2NBxn+1=NBxn+1NAxn+2=2NBxn+1NAxn=2NBxn

Therefore, all strings generated using the grammar contain twice as many a’s as b’s.

Unlock Step-by-Step Solutions & Ace Your Exams!

  • Full Textbook Solutions

    Get detailed explanations and key concepts

  • Unlimited Al creation

    Al flashcards, explanations, exams and more...

  • Ads-free access

    To over 500 millions flashcards

  • Money-back guarantee

    We refund you if you fail your exam.

Over 30 million students worldwide already upgrade their learning with Vaia!

One App. One Place for Learning.

All the tools & learning materials you need for study success - in one app.

Get started for free

Most popular questions from this chapter

Let =0,1. Let B be the collection of strings that contain at least one 1 in their second half. In other words,

a. Give a PDA that recognizes B

b. Give a CFG that generates B .

Use the results of Exercise 2.16to give another proof that every regular language is context- free, by showing how to convert a regular expression directly to an equivalent context-free grammar.

This problem is inspired by the single-player game Minesweeper, generalized to an arbitrary graph. Let Gbe an undirected graph, where each node either contains a single, hidden mine or is empty. The player chooses nodes, one by one. If the player chooses a node containing a mine, the player loses. If the player chooses an empty node, the player learns the number of neighboring nodes containing mines. (A neighboring node is one connected to the chosen node by an edge.) The player wins if and when all empty nodes have been so chosen.

In the mine consistency problem, you are given a graphG along with numbers labeling some of G’s nodes. You must determine whether a placement of mines on the remaining nodes is possible, so that any node v that is labeled m has exactly m neighboring nodes containing mines. Formulate this problem as a language and show that it isNPcomplete.

In both parts, provide an analysis of the time complexity of your algorithm.

a. Show thatEQDFAP.

b. Say that a languageAisstar-closedifA=A*. Give a polynomial time algorithm

to test whether a DFArecognizes a star-closed language. (Note that EQNFAis not

known to be in P.)

Question: Answer all parts for the following DFA and give reasons for your answers.

a.Is<M,0100>ADFA?b. Is<M,011>ADFA?c. Is<M>ADFA?d. Is<M,0100>AREX?e. Is<M>EDFA?f. Is<M,M>EQDFA?

See all solutions

Recommended explanations on Computer Science Textbooks

View all explanations

What do you think about this solution?

We value your feedback to improve our textbook solutions.

Study anywhere. Anytime. Across all devices.

Sign-up for free