Found 349 Articles for Data Structure Algorithms

Explain about CYK Algorithm for Context Free Grammar

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

6K+ 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

What are the properties of Regular expressions in TOC?

Bhanu Priya
Updated on 15-Jun-2021 13:00:04

6K+ Views

A regular expression is basically a shorthand way of showing how a regular language is built from the base set of regular languages.The symbols are identical which are used to construct the languages, and any given expression that has a language closely associated with it.For each regular expression E, there is a regular language L(E).There are some general equalities for the regular expressions.PropertiesAll the properties held for any regular expressions R, E, F and can be verified by using properties of languages and sets.Additive (+) propertiesThe additive properties of regular expressions are as follows −R + E = E + ... 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

2K+ 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

3K+ 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

2K+ 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

756 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

1K+ 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

3K+ 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

What is a Queue Automaton?

Bhanu Priya
Updated on 15-Jun-2021 12:17:12

392 Views

A queue automaton is like a push-down automaton (PDA) except that the stack is replaced by a queue.A queue is a tape allowing symbols to be written only on the left-hand end and read only at the right-hand end.Each write operation (we’ll call it a push) adds a symbol to the left-hand end of the queue and each read operation (we’ll call it a pull) reads and removes a symbol at the right-hand end.As with a PDA, the input is placed on a separate read-only input tape, and the head on the input tape can move only from left to ... Read More

Differentiate between Ambiguous and Unambiguous Grammar

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

5K+ 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 ... 6 7 8 9 10 ... 35 Next
Advertisements