
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

8K+ Views
Problem 1Write the regular expression for the language accepting all the strings containing any number of a's and b's.SolutionThe regular expression will be −r.e. = (a + b)*This will give the set as L = {E, a, aa, b, bb, ab, ba, aba, bab, .....}, any combination of a and b.The (a + b)* shows any combination with a and b even a null string.Problem 2Write the regular expression for the language starting with a but not having consecutive b's.SolutionThe regular expression has to be built for the language: L = {a, aba, aab, aba, aaa, abab, .....}The regular expression ... Read More

7K+ Views
ProblemConstruct a minimum state DFA for the following automata −SolutionWe first construct a transition table for the given finite automata −States\inputs01q0q1q5q1q6q2*q2q0q2q3q2q6q4q7q5q5q2q6q6q6q4q7q6q2Q={q0, q1, q2, q3, q4, q5, q6, q7}Q01={q2} and Q02={q0, q1, q2, q3, q4, q5, q6, q7}S0={{q2} {q0, q1, q2, q3, q4, q5, q6, q7}}Consider the set {q0, q1, q2, q3, q4, q5, q6, q7}{q2} {q0, q1, q3, q5, q6, q7}{q2} {q0, q4, q6} {q1, q3, q5, q7}{q2} {q0, q4} {q6} {q1, q3, q5, q7}{q2}{q0, q4}{q6}{q1, q7}{q3, q5}The minimized state is as follows −M1=(Q1, Σ, δ1, q01, F1)Q1= {[q2], [q0, q4], [q6], [q1, q7], [q3, q5]}qo1= {[q0, q4]}F1= {[q2]}Transition TableNow ... Read More

3K+ Views
A finite state machine (FSM) which has a set of states and two functions called the next-state and output function.The set of states correspond to all the possible combinations of the internal storage.If there are n bits of storage, there are 2n possible states.The next state function is a combinational logic function that given the inputs and the current state, determines the next state of the systemA Finite State Machine consists of the following −K states: S = {s1, s2, ... ,sk}, s1 is initial stateN inputs: I = {h, i2, ... ,in}M outputs: O = {o1, o2, . ,om}Next-state ... Read More

41K+ Views
In this method, we try to remove all the ε-transitions from the given Non-deterministic finite automata (NFA) −The method is mentioned below stepwise −Step 1 − Find out all the ε-transitions from each state from Q. That will be called as ε-closure(qi) where, qi ∈Q.Step 2 − Then, 𝛿1 transitions can be obtained. The 𝛿1 transitions means an ε-closure on 𝛿 moves.Step 3 − Step 2 is repeated for each input symbol and for each state of given NFA.Step 4 − By using the resultant status, the transition table for equivalent NFA without ε can be built.NFA with ε to ... Read More

23K+ Views
The ε closure(P) is a set of states which are reachable from state P on ε-transitions.The epsilon closure is as mentioned below −ε-closure (P) = P, where P ∈ QIf there exists ε-closure (P) = {q} and 𝛿(q, ε) =r then, ε-closure (P) = {q, r}ExampleFind ε-closure for the following Non-deterministic finite automata (NFA) with epsilon.Solutionε-closure (q0)= {q0, q1, q2}self state+ ε-reachable states.ε-closure (q1)= { q1, q2}q1 is self-state and q2 is a state obtained from q1 with epsilon input.ε-closure (q2)= {q2}Lets us consider an example to understand more clear about epsilon closure −Problem − find the number of epsilon ... Read More

7K+ Views
The language L accepted by Non-deterministic finite automata (NFA) with ε, denoted by M= (Q, Σ, 𝛿, q0, F) and can be defined as follows −Let M= (Q, Σ, 𝛿, q0, F) be a NFA with εWhere, Q is a set of statesΣ is input setδ is a transition function from Q x { Σ U ε } to 2Qq0 is start stateF is a final stateThe string w in L accepted by NFA can be represented as follows −L(M)={w| w ∈ Σ* and 𝛿 transition for w from q0 reaches to F}ExampleConstruct NFA with epsilon which accepts a language ... Read More

11K+ Views
ProblemConvert the given finite automata (FA) into regular expression (RE).SolutionThere are two popular methods for converting a DFA to its regular expression −Arden’s MethodState elimination methodLet’s consider the state elimination method to convert FA to RE.RulesThe rules for state elimination method are as follows −Rule 1The initial state of DFA must not have any incoming edge.If there is any incoming edge to the initial edge, then create a new initial state having no incoming edge to it.Rule 2There must exist only one final state in DFA.If there exist multiple final states, then convert all the final states into non-final states ... Read More

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

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

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