Found 282 Articles for Data Structure Algorithms

What are the restrictions of regular grammar?

Bhanu Priya
Updated on 15-Jun-2021 13:11:38

1K+ Views

A regular grammar is the one where each production takes one of the following restricted forms −B → ∧, B → w, B → A, B → wA.(Where A, B are non-terminals and w is a non-empty string of terminals.)Restrictions of regular grammarOnly one nonterminal can appear on the right-hand side of a production.Nonterminal must appear on the right end of the right-hand side.Therefore, the productions are as follows −A → aBc and S → TUThese are not part of a regular grammar, but the production A → abcA is.Things like A → aB|cC are allowed because they are actually ... Read More

Design a DFA that accepts at most 3 a"s

Bhanu Priya
Updated on 15-Jun-2021 12:51:13

16K+ Views

Construct deterministic finite automata that accepts at most 3 a’s over an alphabet ∑={a,b}.At most 3 a’s means,The string contains 0 to max 3 a’s and any number of b’s.L= {Є,a,aa,aaa,ab,abb,bab,bbabaa, bbabaabbb,…..}Construct DFALet’s construct DFA step by step −Step 1Valid inputs − aaa, a, aa,ε .Step 2Valid inputs − b, ba, baa, baaa, bb, bba, bbba,…Step 3Valid input − bab, abba, abbbaa, babba,…Step 4Valid inputs − babab, aabb, aaba, bbbaaba, …Step 5Valid inputs − aaabbb, aaabab, baaaba, …Step 6InValid inputs − aaaa, aaabab, baaaba,

Explain about CYK Algorithm for Context Free Grammar

Bhanu Priya
Updated on 15-Jun-2021 12:48:06

9K+ Views

CKY means Cocke-Kasami-Younger. It is one of the earliest recognition and parsing algorithms. The standard version of CKY can only recognize languages defined by context-free grammars in Chomsky Normal Form (CNF).It is also possible to extend the CKY algorithm to handle some grammars which are not in CNF (Hard to understand).Based on a “dynamic programming” approach −Build solutions compositionally from sub-solutionsIt uses the grammar directly.AlgorithmBegin    for ( i = 1 to n do )    Vi1 { A | A → a is a production where i th symbol of x is a }    for ( j = ... Read More

Design a DFA accepting stringw so that the second symbol is zero and fourth is 1

Bhanu Priya
Updated on 15-Jun-2021 12:45:14

3K+ Views

ProblemConstruct DFA which accepts a string that contains second symbol is zero and fourth symbol is 1 over an alphabet ∑={0,1}.SolutionInput − 00110Output is accepted; because in the given string the second symbol is ‘0’ and the fourth symbol is ‘1’.Input − 11001Output − string is not accepted, because the second symbol is not ‘0’.Design DFA step by step as given below −Step 1 -Valid inputs − 0001Step 2 -Valid input − 1001Step 3 -Valid inputs − 0011, 1011Step 4 -Valid inputs − 00010, 10010, 00110, 00011, 10011, 00111, …Step 5 -Invalid inputs − 0101, 0100, 0010, 1100, 0000, 1000, …Step 6 -Valid inputs − 01010, 01000, 11111, 0100000, …

Explain the intersection process of two DFA’s

Bhanu Priya
Updated on 15-Jun-2021 12:41:39

4K+ Views

According to the theorem, If L and M are two regular languages, then L ∩ M is also regular language.ExampleConstruct A∩B where A and B is given as follows −The language A ={10, 100, 00, 001, 1010, …..}The language B ={01, 1010, 10, 101, …..}AA = (QA, Σ, δA, qa, FA) AB = (QB, Σ, δB, qB, FB) A∩B=(QA x QB ,Σ, δ(qA x qB ,FA x F B )Where, δ(( p, q), a) =δL (p, a), δM (q, a))Here, QA x QB = {p, q} x {r, s}    ={(p, r), (p, s), (q, r), (q, s)} Z = ... Read More

Design a DFA accepting a language L having number of zeros in multiples of 3

Bhanu Priya
Updated on 15-Jun-2021 12:39:28

3K+ Views

ProblemConstruct a deterministic finite automata (DFA) that accepts a language L which has the number of zero’s is of multiple of 3 over an alphabet ∑=”{0,1}.SolutionIf input is: 000 Output is: string is acceptedBecause here the number of zero’s is multiple of 3.Designing DFAIn order to construct the DFA, follow the below mentioned steps −Step 1 -Valid inputs: 000, 000000, 09 , 012 , …Step 2 -Valid inputs: 1, 1000, 100000, …Step 3 -Valid inputs: 10100, 11000, 101100, …Step 4 -101010, 1101010, 1101110110, …Invalid inputs − 0,00,10000,01011, …

Construct DFA beginning with ‘a’ but does not have substring ‘aab’

Bhanu Priya
Updated on 15-Jun-2021 12:37:02

1K+ Views

ProblemGiven language to construct the deterministic finite automata (DFA) is, the strings start with ‘a’ but not contain substring ‘aab’ over alphabet ∑={a,b}.SolutionIf the input is: “baabba”The output is: string is not acceptedBecause the string does not start with ‘a’, and generating a substring ‘abb’,DFA transition diagramThe DFA transition diagram for the string beginning with ‘a’ but not having the substring as ‘aab’ is as follows −Transition tableThe transition table is as follows −STATEINPUT (a)INPUT (b)→ 01*4 (dead state)1*2*3*2*2*4 (dead state)3*1*3*4 (dead state)4 (dead state)4 (dead State)

Prove that the polynomial time reduction is from the Clique problem to the Vertex Cover problem

Bhanu Priya
Updated on 15-Jun-2021 12:30:04

2K+ Views

Vertex cover is a subset of vertices that covers all the edges in a graph. It is used to determine whether a given graph has a 3SAT to vertex cover.Clique is called a subset of vertices that are all directly connected. It determines whether a clique of size k exists in a graph.To prove − Vertex cover can be reduced to clique.ProofGiven a graph G=(V, E) and integer k.Get its complement graph G'=(V, E').Solve CLIQUE(G', |V|-k).If there is a solution, return yes. Otherwise, it returns as no.To prove this reduction, we need to show the following −If there is a ... Read More

Construct a DFA recognizing the language {x | the number of 1's is divisible by 2, and 0'sby 3} over an alphabet ∑={0,1}

Bhanu Priya
Updated on 15-Jun-2021 12:20:23

5K+ Views

ProblemThe given language L={ x | the number of 1's is divisible by 2, and 0's by 3} over an alphabet ∑={0, 1}.SolutionThe language is divided into two parts, first we need to find the number of 1’s divisible by 2 and second find out the number of 0’s divisible by 3, finally combine the two parts to generate a result.Step 1 − DFA for the first part, number of 1’s divisible by 2.Here, q0 on 0 goes to q0 which is a final state, and generates a string 0, accepted by the given language.q0 on 1 goes to q1, ... Read More

Differentiate between Ambiguous and Unambiguous Grammar

Bhanu Priya
Updated on 15-Jun-2021 12:14:50

7K+ Views

Before understanding the differences between ambiguous grammar and unambiguous grammar, let us learn about these concepts.Ambiguous GrammarA grammar is said to be ambiguous if there exists more than one left most derivation or more than one right most derivation or more than one parse tree for a given input string.If the grammar is not ambiguous then we call unambiguous grammarIf the grammar has ambiguity then it is good for compiler constructionNo method can automatically detect and remove the ambiguity, but we can remove the ambiguity by re-writing the whole grammar without ambiguity.ExampleLet us consider a grammar with production rules −E=I ... Read More

Previous 1 ... 4 5 6 7 8 ... 29 Next
Advertisements