Found 345 Articles for Data Structure Algorithms

Construct a pair of languages by using CFG

Bhanu Priya
Updated on 12-Jun-2021 11:41:32

183 Views

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

Explain the relationship between grammar and language in TOC

Bhanu Priya
Updated on 12-Jun-2021 11:40:08

1K+ Views

In order to understand the relationship between the grammar and language in the theory of computation (TOC), let us understand what is language generated by grammar in TOC.Language generated by grammarThe grammar is S-> aSb| E.In this grammar, by using S-> E, we can generate E.Therefore, E is part of L(G).Similarly, by using S=>aSb=>ab, ab is generated.Similarly, aabb can also be generated.Therefore, the result is as follows −L(G) = {anbn, n>0}In language L(G) which is discussed above, the condition n =0 is taken to accept the epsilon.Consider the grammar given belowS -> aSa | bSb | a |bNow, let us ... Read More

What are the closure properties of Regular languages?

Bhanu Priya
Updated on 01-Nov-2023 20:20:00

40K+ Views

In an automata theory, there are different closure properties for regular languages. They are as follows −UnionIntersectionconcatenationKleene closureComplementLet see one by one with an exampleUnionIf L1 and If L2 are two regular languages, their union L1 U L2 will also be regular.ExampleL1 = {an | n > O} and L2 = {bn | n > O}L3 = L1 U L2 = {an U bn | n > O} is also regular.IntersectionIf L1 and If L2 are two regular languages, their intersection L1 ∩ L2 will also be regular.ExampleL1= {am bn | n > 0 and m > O} andL2= {am ... Read More

Construct a Finite Automata for the regular expression ((a+b)(a+b))*.

Bhanu Priya
Updated on 12-Jun-2021 11:02:54

3K+ Views

The language for the given regular expression (RE) is as follows −L={ ε,aa,ab,ba,aaaa,………}ExampleLet the regular expression be ((a+b)(a+b))*(a+b).Construct the Finite automata for the given regular expression.First, generate the language for the given Regular Expression −L={a,d,aaa,bbb,abb,bab,bba,………..}This is the language of odd length stringsThe Finite Automata is as follows −

Convert RE 1(0+1)*0 into equivalent DFA.

Bhanu Priya
Updated on 12-Jun-2021 11:01:35

4K+ Views

To convert the regular expression to Finite Automata (FA) we can use the Subset method.Subset method is used to obtain FA from the given regular expression (RE).Step 1 − Construct a Transition diagram for a given RE using Non-deterministic finite automata (NFA) with ε moves.Step 2 − Convert NFA with ε to NFA without ε.Step 3 − Convert the NFA to equivalent DFA.We will divide the given expression into three parts as follows −“1” ,”(0+1)*, and “0”NFA with Epsilon transition is as follows −Now, we will remove the epsilon transition.After removing, the transition diagram is given below −

Construct NFA with Epsilon moves for regular expression a+ba*.

Bhanu Priya
Updated on 12-Jun-2021 10:40:32

7K+ Views

The regular expression R= a+ba* divided into r1 and r2r1= a and r2= ba*Let us draw Non-deterministic finite automata (NFA) for r1 as given below −Now, we will go for r2 = ba *Divide r2 into r3 and r4, where, r3=b and r4=a*The NFA for r3 is as follows −The NFA for r4 is as follows −q5 on epsilon movies goes to q6 and q8, q6 on ‘a’ goes to q7 whereas, q7 on epsilon moves goes to q6 as well as q7.r2= r3.r4Now, concatenate r3 and r4 as shown below −q3 on input ‘b’ goes to q4, q4 on ... Read More

What is Inductive Hypothesis in TOC?

Bhanu Priya
Updated on 12-Jun-2021 10:24:52

1K+ Views

Induction is a powerful tool in mathematics. It is a way of proving propositions that hold for all natural numbers.Hypothesis − The formal proof can be using deductive proof and inductive proof. The deductive proof consists of sequence of statements given with logical reasoning in order to prove the first or initial statement. The initial statement is called Hypothesis.Suppose there exists a k > 0 such that for any regular expression r where 0 < OP(r) < k, there exists an NFA- s such that L(M) = L(r). Furthermore, suppose that M has exactly one final state.Inductive StepLet r be ... Read More

How to convert Regular expression to Finite Automata?

Bhanu Priya
Updated on 12-Jun-2021 10:22:41

17K+ Views

To convert the regular expression (RE) to Finite Automata (FA), we can use the Subset method.Subset method is used to obtain FA from the given RE.Step 1 − Construct a Transition diagram for a given RE by using Non-deterministic finite automata (NFA) with ε moves.Step 2 − Convert NFA with ε to NFA without ε.Step 3 − Convert the NFA to the equivalent Deterministic Finite Automata (DFA).Some basic RE are as follows −Case 1 − For a regular expression ‘a’, we can construct FA as shown below −Case 2 − For a regular expression ‘ab’ we can construct FA, as ... Read More

Explain the relationship between Finite Automata and Regular Expression.

Bhanu Priya
Updated on 12-Jun-2021 10:20:36

10K+ Views

In order to understand the relationship between finite automata (FA) and regular expression (RE), we need to understand these terminologies. Let us begin by understanding what is a regular expression.Regular ExpressionRegular expression is the language which is used to describe the language and is accepted by finite automata. Regular expressions are the most effective way to represent any language. Let Σ be an alphabet which denotes the input set.The regular expression over Σ can be defined as follows −Φ is a regular expression which denotes the empty set.ε is a regular expression and denotes the set { ε} and it ... Read More

Explain the problems for equivalence of two regular expressions.

Bhanu Priya
Updated on 12-Jun-2021 10:18:52

4K+ Views

Problem 1Prove that (1+00*1)+(1+00*1)(0+10*1)*(0+10*)=0*1(0+10*1)*SolutionHere, we need to prove LHS=RHS (Left hand side = Right hand side)Let us solve first LHS(1+00*1)+(1+00*1)(0+10*1)*(0+10*)Take (1+00*1) as a common factor(1+00*1)( ε+(0+10*1)*(0+10*1)Where,(0+10*1)*(0+10*1). It is in the form of R*R where R=0+10*1As we know, (ε+R*R)=( ε+RR*)=R*Therefore,(1+00*1)((0+10*1)*)Taking 1 as common factor(ε+00*)1(0+10*1)*Apply ε+00*=0*0*1(0+10*1)*=RHSHence, the two regular expressions are equal.Problem 2Show that (0*1*)*=(0+1)*SolutionConsider LHS(0*1*)*= { ε,0,00,1,11,111,01,10,……}= {any combinations of 0’s, any combinations of 1’s, any combinations of 0 and 1, ε}Similarly,RHS=(0+1)*= { ε,0,00,1,11,111,01,10,…..}= { ε, any combinations of 0’s, any combinations of 1’s, any combinations of 0 and 1}Hence, it is proved thatLHS=RHS

Advertisements