Found 282 Articles for Data Structure Algorithms

How to identify if a language is regular or not in TOC?

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

5K+ Views

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

Eliminate epsilon, unit and useless symbols and rewrite into CNF

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

1K+ Views

ProblemEliminate epsilon, unit and the useless symbols for the given grammar and rewrite it into CNF.S->0E0|1FF| εE->GF->S|EG->S| εSolutionIn the given grammar, we will first remove the null production. There are two null productions in the grammar, as given below −S ==> εG ==> εSo, remove null production and rewrite all the other rules containing G by epsilon there, along with old productions. We do not remove S ==> epsilon as it is the start symbol.Remove G ==> epsilon, we get the following −S ==> 0E0 | 1FF | εE ==> G | εF ==> S | EG ==> SNow remove ... Read More

Generate a CNF for a given context free grammar

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

1K+ Views

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

Convert the given Context free grammar to CNF

Bhanu Priya
Updated on 12-Jun-2021 12:10:49

23K+ Views

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

Explain how to convert CFG to CNF

Bhanu Priya
Updated on 12-Jun-2021 12:34:50

4K+ Views

CFG stands for context free grammar and CNF stands for Chomsky’s Normal Form in the theory of computation.Context Free Grammar (CFG)A context free grammar (CFG) is a forma grammar which is used to generate all possible patterns of strings in a given formal language.It is defined as four tuples −G=(V, T, P, S)Where, G is a grammar, which consists of a set of production rules. It is used to generate the strings of a language.T is the final set of terminal symbols. It is denoted by lower case letters.V is the final set of non-terminal symbols. It is denoted by ... Read More

What is the Instantaneous description of PDA?

Bhanu Priya
Updated on 12-Jun-2021 11:45:25

15K+ Views

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

What is the difference between DFA and NFA?

Bhanu Priya
Updated on 31-Oct-2023 20:57:57

66K+ Views

DFA is the short form for the deterministic finite automata and NFA is for the Non-deterministic finite automata. Now, let us understand in detail about these two finite automata.DFAA Deterministic Finite automata is a five-tuple automata. Following is the definition of DFA −M=(Q, Σ, δ, q0, F)Where, Q : Finite set called states.Σ : Finite set called alphabets.δ : Q × Σ → Q is the transition function.q0 ϵ Q is the start or initial state.F : Final or accept state.NFANFA also has five states same as DFA, but with different transition function, as shown follows −δ: Q X Σ ... Read More

What is unambiguous grammar in TOC?

Bhanu Priya
Updated on 12-Jun-2021 11:53:55

5K+ Views

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

What are the regular expressions to finite automata?

Bhanu Priya
Updated on 12-Jun-2021 12:29:13

902 Views

For each of the following languages, draw the finite automata (FA) accepting it.{a, b}*{a}The language states that the automata accept the strings containing any number of a's and b's and finally ending in a.The finite state automaton for the language is as follows −{a, b}*{b, aa}{a, b*}The language states that the automata accept the strings starting and ending with any number of a's and b's and containing any of the substrings b and aa.The finite state automaton for the language is a follows −{bbb, baa}*{a}The language states that the automata accept the strings containing any number of bbb's and baa's ... Read More

Explain Pumping lemma for context free language

Bhanu Priya
Updated on 12-Jun-2021 11:46:19

37K+ Views

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

Advertisements