
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 282 Articles for Data Structure Algorithms

1K+ Views
ProblemGenerate the push down automata (PDA) that recognizes the language E={aibj| i is not equal to j and I is not equal to 2j}.SolutionConsider the two languages as given below −L1={aibj|i,j>=0 and i>2j}L2={aibj|i,j>=0 and iaA A->aaAb|aA|epsilonIn L2, the number of a's are less than double the number of b'sSo the CFG for L2 becomes as follows − S2->Bb|aBb B->Bb|aBb|aaBb|epsilon S->S1|S2L1: {aibj:i>2j}L2:{aibj: i

10K+ Views
All grammars are not always optimized, which means the grammar may consist of some extra symbols (non-terminals) which increase the length of grammar.So, we have to reduce the grammar by removing the useless symbols.PropertiesThe properties to reduce grammar are explained below −Each non-terminal and terminal of G appears in the derivation of some word in L.There should not be any production as X->Y where X and Y are non-terminals.If epsilon is not in language L then there need not be in the production X-> ε.The diagram given below depicts the use of reduce grammar−The productions of type S-> ε are ... Read More

1K+ Views
The instantaneous description (ID) of a push down automata (PDA) is represented by a triple (q, w, s)Where, q is the state.w is unconsumed input.s is the stack contents.ID is an informal notation of how a PDA compares an input string and makes a decision that string is accepted or rejected.Turnstile NotationIt is used for connecting pairs of ID's that represent one or more moves of a PDA.The process of transition is denoted by the turnstile symbol "⊢"⊢ it represents one move.⊢ sign describes a sequence of moves.Example(P, b, T) ⊢ (q, w, a)While taking a transition from P to ... Read More

587 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

264 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

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

933 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

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

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

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