ProblemGenerate a Chomsky normal form (CNF) for the following context free grammar (CFG).S->aAa|bBb|eA->C|aB->C|bC->CDE|eD->A|B|abSolutionFollow the steps mentioned below to generate a CNF for the given CFGStep 1 − Eliminate ∧ -productionsWe can delete, erase or ∧ -productions double time repeated.S --> aAa | bBb | ∧A --> a | ∧B --> b | ∧D --> A | B | abStep 2 − Eliminate unit productions in above grammarEliminate R.H.S one symbol productionsS --> aDa | bDbD --> a | b | abStep 3 − Eliminate useless symbolsE is a useless symbol from given grammar since it is not derivative in RHS.S ... Read More
ProblemConvert the given grammar into Chomsky's Normal Form (CNF)S->AAA|BA->aA|BB-> εSolutionFollow the steps given below to convert CFG to CNF −Step 1 − Eliminate epsilon productionsTo eliminate epsilon productions, the variable which is producing epsilon must be replaced on the RHS of all other productions for the epsilon production to be removed.Replacing B with ε in all other productions gives the following production set −S-> AAA | ε | BA->aA | ε | BReplacing A with \epsilon in all other productions gives the following −S ->AAA | AA | A | B | ε [replacing 1, 2, and 3 A's with ε ... Read More
The star height of Regular expression (RE) is nothing but the depth of Kleene stars in the theory of computation (TOC).For example, a+b the star height is 0(a+b)* the star height is 1(a*+b*)* the star height is 2 …….Star height is used to indicate the structural complexity of regular languages and expressions.The regular expressions may have different star height that depends on structural complexity or nesting.The star height of a regular language is a unique number and that is equal to the least star height of any regular expression which represents that language.The star height of regular expressions is a ... Read More
A grammar with at most one variable at the right side of production is called linear grammar.Following is an example of the linear grammar −S→aSb/εHere, if you observe, we can write the same production by dividing …..S→AbA→aAbA→εLeft Linear GrammarA grammar is left linear grammar where all non-terminals in the right hand sides are at the left end.For example, A→Sa/εSteps for conversionThe steps for the conversion of finite automata (FA) to the left linear grammar are as follows −Step 1 − Take reverse of the finite automataStep 2 − write right linear grammarStep 3 − Then take reverse of the right ... Read More
A grammar can be unambiguous, if the grammar does not contain ambiguity. This means if it does not contain more than one left most derivation (LMD) or more than one right most derivation (RMD) or more than one parse tree for the given input string, it is an unambiguous grammar.RulesTo convert the ambiguous grammar to the unambiguous grammar, we apply the following rules −Rule 1 − If the left associative operators (+, -, *, /) are used in the production rule, then apply left recursion in the production rule. Left recursion is nothing but left most symbol on the right side ... Read More
A grammar with at most one variable at the right side of production is called linear grammar.Example 1 S→aSb/εExample 2 S→Ab A→aAb A→εRight Linear GrammarA grammar is right linear grammar where all the non terminals in the right hand sides are at the right end.For example, S->aS/εAlgorithm for conversionThe algorithm to convert the finite automata (FA) to the right linear grammar is as follows −Step 1 − Begin the process from the start state.Step 2 − Repeat the process for each state.Step 3 − Write the production as the ... Read More
To identify whether a language is regular or not, is based on Pigeon Hole Principle. This is generally called as the Pumping Lemma.Pumping lemma for Regular languagesIt gives a method for pumping (generating) many substrings from a given string.In other words, we say it provides means to break a given long input string into several substrings.It gives the necessary condition(s) to prove a set of strings is not regular.But the pumping lemma is a contradiction test. This means if any language does not satisfy pumping lemma, then we can say that it is not regular. However, if it satisfies the ... Read More
Pumping lemma for context free language (CFL) is used to prove that a language is not a Context free languageAssume L is context free languageThen there is a pumping length n such that any string w εL of length>=n can be written as follows −|w|>=nWe can break w into 5 strings, w=uvxyz, such as the ones given below|vxy| >=n|vy| # εFor all k>=0, the string uvkxyyz∈LThe steps to prove that the language is not a context free by using pumping lemma are explained below −Assume that L is context free.The pumping length is n.All strings longer than n can be ... Read More
The Instantaneous description is called as an informal notation, and explains how a Push down automata (PDA) computes the given input string and makes a decision that the given string is accepted or rejected.The PDA involves both state and content of the stack.Stack is often one of the important parts of PDA at any time.So, we make a convenient notation for describing the successive configurations of PDA for string processing.The factors of PDA notation by triple (q, w, γ) wereq is the current state.w is the remaining input alphabet.γ is the current contents of the PDA stack.Generally, the leftmost symbol ... Read More
ProblemConsider the following context-free grammars (CFG) and find the pairs of languages which can be generated by Gl and G2 respectively.SolutionConsider the following CFG −G1 : S->aS|B , B->b l bBG2: S->aA | bB , A->aA| B | ε , B->bB | εNow, we can generate the language as follows. First consider G1 as shown belowConsider G1: S->aS|B B->b|bB Using S->B ->b b can be generated Using S->B ->bB ->bb bb can be generated Using S->aS ->aB ... Read More
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP