Computer Science Articles - Page 41 of 62

Explain if the CFG is recognized by Non-deterministic push down automata

Bhanu Priya
Updated on 16-Jun-2021 12:43:59

644 Views

Context Free Grammars (CFG) are definitely recognized by Non-deterministic push down automata (NPDA), but Programming languages are translated to binary (Machine Code) via Deterministic PDA.This is because it has the following below mentioned impacts −If Programming languages were supposed to be translated via NPDA then for one given program instance we will have multiple versions of binary(Machine code) generated for the same program, which ideally shouldn't be the scenario.For a given program only 1 version of binary code should be generated and that should remain consistent across all OS Platforms.Outputs will vary significantly: If we have multiple object files, then ... Read More

Design an unambiguous CFG in CNF that generates E?

Bhanu Priya
Updated on 16-Jun-2021 12:47:00

316 Views

ProblemDefine the language, E={aibj|i not equal to j and i not equal to 2j} and design an unambiguous context free grammar (CFG) in Chomsky normal form (CNF) that generates E.SolutionThe unambiguous CFG for the given language is as follows −S->AC|CBA->aA|aB->Bb|bC->aCb|aaCb|epsilonNow, convert this CFG into CNF. You can follow the below mentioned steps for the successful conversion.Step 1First add a new start symbol S0   S0->S   S->AC|CB   A->aA|a   B->Bb|b   C->aCb|aaCb|epsilonStep 2Next eliminate the epsilon symbol in the production other than the start symbol.   C->epsilon is a null productionAfter eliminating null production, the new productions are as follows −   S0->S   S->AC|CB   A->aA|a   B->Bb|b  ... Read More

Construct a TM for adding 1 to a binary natural number?

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

1K+ Views

A Turing machine (TM) can be formally described as seven tuples −(Q, X, ∑, δ, q0, B, F)Where, Q is a finite set of states.X is the tape alphabet.∑ is the input alphabet.δ is a transition function: δ:QxX->QxXx{left shift, right shift}.q0 is the initial state.B is the blank symbol.F is the final state.Binary numbers1 = 12 = 103 = 114 = 1005 = 1016 = 110. . .AlgorithmStep 1 − Move to the right end of the string.Step 2 − Repeat:If the current cell contains 1, write 0 and move left until the current cell contains 0 or blank.Step 3 ... Read More

Construct a Turing machine for adding 2 to the binary natural number?

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

1K+ Views

A Turing machine (TM) can be formally described as seven tuples −(Q, X, ∑, δ, q0, B, F)Where, Q is a finite set of states.X is the tape alphabet.∑ is the input alphabet.δ is a transition function:δ:QxX->QxXx{left shift, right shift}.q0 is the initial state.B is the blank symbol.F is the final state.Input − n a natural numberOutput − n + 2Let’s represent natural numbers in unary form (e.g. 3 = 111, 5 = 11111) and 0 will be represented by the empty symbol.AlgorithmMove the tape head to the left of the first 1 (if it exists).Change that empty cell to ... Read More

Draw a Turing machine to find 2’s complement of a binary number

Bhanu Priya
Updated on 15-Jun-2021 15:33:34

9K+ Views

2’s complement of binary numbers can be done by using two approaches.Adding 1’s complement+1Traverse bits from left to right, find the 1st 1 bit then reverse all the bits after the 1 bit.ExampleLet the input be 1110010Thus, after performing 2’s complement, the output will be as follows −Output − 0001110Coming to the Turing machine to find 2’s complement, If input is as follows −B010000100The output is as follows −B101111100ExplanationStep 1 − Here, we need to start from the rightmost ends.Step 2 − We will move the R/W head all the way to the right, skipping all the 0s and 1s.Step ... Read More

Draw a Turing machine to find 1’s complement of a binary number

Bhanu Priya
Updated on 15-Jun-2021 15:24:58

5K+ Views

1’s complement means transforming the 0 bit to 1 and the 1 bit to 0.Let the input be −B00101110BThe output is as follows −B11010001BConceptThe concept is explained below −Step 1 − Start scanning the input from left to right.Step 2 − If the R/W is at 1, then make it 0 and move right.Step 3 − If the R/W is at 0, then make it 1 and move right.Step 4 − Repeat the steps given above and we will reach B (blank).Step 5 − Then move the R/W head all the way to the left without changing anything until it ... Read More

Construct a TM for the language L= {ww : w ∈ {0,1}}

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

2K+ Views

ProblemThe language L = {ww | w ε {0, 1}} having the string of 0’s and 1’s which is followed by itselfL={00, 11, 1100, 0011, …..}SolutionThe logic for solving the problem is as follows −Find the midpoint of the string.Then match the symbols.ExplanationStep 1 − First, we need to find the midpoint of the string.Step 2 − We will make the first 0 to X or 1 to Y and then move R/W head to the right until the last character is found.Step 3 − Then make this 0 to X or 1 to Y.Step 4 − Now, we will ... Read More

Construct PDA for accepting L = {anb(2n) | n>=1} U {anbn | n>=1}

Bhanu Priya
Updated on 15-Jun-2021 15:07:47

2K+ Views

A push down automata (PDA) can be formally described as seven tuples(Q, Σ, S, δ, q0, I, F)Where, Q is finite number of statesΣ is input alphabetS is stack symbolΔ is the transition function: QX(Σ∪{e})XSXQq0 is the initial state (q0 belongs to Q)I is the initial state top symbolF is a set of accepting statesProblemConstruct PDA for L = {anb(2n) | n>=1} ∪ {anbn | n>=1}SolutionLetL = {anb(2n) | n>=1}{anbn | n>=1}Construct PDA for L= L1 U L2So, the strings which are generated by the given language L1 are as follows−L1={abb, aabbbb, aaabbbbbb, ….} andL2= {ab, aabb, aaabbb, ….}L= L1 ... Read More

Construct a DPDA for anb2n n ≥ 1 in TOC

Bhanu Priya
Updated on 15-Jun-2021 15:05:23

26K+ Views

A deterministic finite automata (DFA) can remember a finite amount of information but A push down automata (PDA) can remember an infinite amount of information.Basically a PDA is as follows −“Finite state machine+ a stack”PDA has three components, which is as follows −An Input tapeA control unitA Stack with infinite sizeA PDA can be formally described as seven tuples (Q, Σ, S, δ, q0, I, F)Q is finite number of statesΣ is input alphabetS is stack symbolΔ is the transition function: QX(Σ∪{e})XSXQq0 is the initial state (q0 belongs to Q)I is the initial state top symbolF is a set of ... Read More

Construct PDA for L = {0n1m2(n+m) | m,n >=1}

Bhanu Priya
Updated on 15-Jun-2021 15:03:33

4K+ Views

A push down automata (PDA) can be formally described as seven tuples(Q, Σ, S, δ, q0, I, F)Where, Q is finite number of statesΣ is input alphabetS is stack symbolΔ is the transition function: QX(Σ∪{e})XSXQq0 is the initial state (q0 belongs to Q)I is the initial state top symbolF is a set of accepting states(F belongs to Q)ProblemConstruct PDA for 0n1m2(n+m) where n, m>=1.SolutionSo, the strings which are generated by the given language are as follows −L={0122, 001222, 000112222, ….}That is to add the number of 0's and 1's, and that will equal the number of 2's.So for every 0's ... Read More

Advertisements