Found 700 Articles for Computer Science

Construct the derivation tree for the string aabbabba.

Bhanu Priya
Updated on 12-Jun-2021 09:31:05

8K+ Views

ProblemDerive a derivation tree for the string aabbabba for the given context free grammar (CFG) −S->aB|bA A->a|aS|bAA B->b|bS|aBBSolutionDerivation is a sequence of production rules, which is used to get input strings.Derivation treeIt is a graphical representation for derivation of given production rules for a given CFG. It is also called as a parse tree.PropertiesThe derivation tree contains some properties, which are as follows −The root node is always a node indicating the start symbol.The derivation is read from left to right.The leaf node is always terminal nodes.The interior nodes are always the non-terminal nodes.The given CFG is as follows −S->aB|bA ... Read More

Design finite automata from a given regular expression.

Bhanu Priya
Updated on 12-Jun-2021 09:27:47

2K+ Views

Finite automata (FA) is an abstract computing device. It can be represented in the following −Graphical (Transition diagrams)Tabular (Transition table)Mathematical (Transition function)The formal definition of FA is that it is a five tuples.M=(Q, Σ, δ, q0, F)Where, Q: Finite set called statesΣ: Finite set called alphabetsδ: Q × Σ → Q is the transition functionq0 ∈ Q is the start or initial stateF: Final or accept stateRegular expressionThe regular expression can be used to describe a sequence of patterns that defines a string. It is used to match character combinations in strings.The language accepted by some regular expression are referred ... Read More

Derive the string “abb” for leftmost and rightmost derivation

Bhanu Priya
Updated on 12-Jun-2021 09:24:35

2K+ Views

ProblemLet’s consider a grammar to derive “abb” string using LMD and RMD   S->AB/ ε   A-> aB   B-> SbSolutionWe have to use context free grammar.Derivation is a sequence of production rules, which is used to get input strings.During parsing, we have to take two decisions, which are as follows −We have to decide which non-terminal has to be replaced.We have to decide which non-terminal has to be replaced by using which production rule.There are two options to decide which non-terminal has to be replaced with production rule −Leftmost derivationRightmost derivationLeftmost derivationThe input is scanned and replaced with production rules from left ... Read More

How to generate the language for context free grammar?

Bhanu Priya
Updated on 12-Jun-2021 09:22:44

3K+ Views

ProblemGenerate the language for the given context free grammar.S->0S, S-> λS-> A0, A->1A, A-> λS->000S, S-> λSolutionContext free grammar (CFG) is a formal grammar that is used to generate all the possible patterns of strings in a given formal language.CFG is defined by four tuplesG=(V, T, P, S)Where, T: Set of terminals (lowercase letters) symbols.V: Vertices or non-terminal symbols (Capital letters).P: Production rules.S: Start symbol.Example 1The grammar is −S->0S, S->λCase 1 − S->0S     ->0Case 2 − S->0S    ->00S    ->00Case 3 − S->0S   ->00S   ->000S   ->000Therefore, the language generated for the given grammar is −L={e, 0, 00, 000……..}Example ... Read More

Explain NFA with epsilon transition.

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

18K+ Views

We extend the class of NFAs by allowing instantaneous ε transitions −The automaton may be allowed to change its state without reading the input symbol 2.In diagrams, such transitions are depicted by labeling the appropriate arcs with ε.Note that this does not mean that E has become an input symbol. On the contrary, we assume that the symbol E does not belong to any alphabet.ε -NFAs add a convenient feature but (in a sense) they bring us nothing new. They do not extend the class of languages that can be represented.Both NFAs and E-NFAs recognize exactly the same languages.Epsilon (ε) ... Read More

Explain with an example how to convert NFA to DFA.

Bhanu Priya
Updated on 12-Jun-2021 09:17:08

2K+ Views

ProblemConvert the following Non-Deterministic Finite Automata (NFA) to Deterministic Finite Automata (DFA).SolutionThe transition diagram is as follows −The transition table of NFA is as follows −Stateab->q0q0q0, q1q1-*q2*q2--The DFA table cannot have multiple states. So, make q0q1 as a single state.Let’s convert the given NFA to DFA by considering two states as a single state.The transition table of DFA is as follows −Stateab->q0q0[q0, q1][q0q1][q0][q0q1q2]*[q0q1q2][q0][q0q1q2]In the above transition table, q2 is the final state. Wherever, q2 is present that becomes the final state.Note −After conversion the number of states in the final DFA may or may not be the same as in ... Read More

How to convert from NFA to DFA in TOC?

Bhanu Priya
Updated on 12-Jun-2021 09:14:20

2K+ Views

In Non-Deterministic Finite Automata, for any current state and input symbol, there exists more than one next output state.Any string is accepted if and only if there exists at least one transition path which is starting at initial state and ending at final state.The following steps are followed to convert a given NFA to a DFA −AlgorithmStep-01Let's take ' q’ as a new set of states of the DFA. It is declared null in the beginning.Let's take T’ be a new transition table of the DFA.Step-02Add the start state of the NFA to q’.Add transitions from the start state to ... Read More

Design a Moore machine for some binary input sequence.

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

9K+ Views

ProblemDesign a Moore machine for a binary input sequence such that if it has a substring 101, the machine outputs A, if the input has substring 110, it outputs B otherwise it outputs C.SolutionFor designing such a machine, we will check two conditions, and those are 101 and 110. If we get 101, the output will be A, and if we recognize 110, the output will be B. For other strings, the output will be C.Moore machine has 6 tuples(Q, q0, Σ, O, δ, λ)Where, Q: Finite set of statesq0: Initial state of machineΣ: Finite set of input symbolsO: Output ... Read More

Design a Moore machine to generate 1's complement of a binary number.

Bhanu Priya
Updated on 12-Jun-2021 09:08:25

5K+ Views

Moore machine has 6 tuples, which are as follows −(Q, q0, Σ, O, δ, λ)Where, Q: Finite set of statesq0: Initial state of machineΣ: Finite set of input symbolsO: Output alphabetδ: Transition function where Q × Σ → Qλ: Output function where Q → OThe transition diagram is as follows −ExplanationStep 1 − q0 is the start state on input ‘0’ goes to q1 state and on ‘1’ goes to state q2 generating output 0.Step 2 − q1 on input ‘0’ goes to q1 itself and on ‘1’ goes to q2 generating output ‘1’.Step 3 − q2 on input ‘0’ ... Read More

Draw DFA which accepts the string starting with ‘ab’.

Bhanu Priya
Updated on 11-Jun-2021 14:39:49

18K+ Views

ProblemDraw the state transition diagram over an alphabet Σ={a, b} that accepts the string starting with ‘ab’.SolutionThe formal definition of Deterministic Finite Automata (DFA) is as follows −A DFA is a collection of 5-tuples as shown below −M=(Q, Σ, δ, q0, F)Where, Q: Finite set called states.Σ: Finite set called alphabets.δ: Q × Σ → Q is the transition function.q0 ∈ Q is the initial state.The language is generated as given below −L={ab, aba, abab, …….}The transition diagram is as follows −Here, D is a dead state.D is a transition state, which it can never escape. Such a state is ... Read More

Advertisements