Type 3 grammars are regular grammars that describe regular / formal languages.These grammars contain production rules consisting of the following −Only one non-terminal at the left hand side, The right hand side has a single terminal and may or may not be followed by non terminals.ExampleA → ε , A → a, A → b, A → aA etc.TypesThere are two types of regular grammars namely −Right linear / Right regular grammarLeft linear / Left regular grammarLet us learn about these two types of grammar in detail.Right linear grammarThis is a regular grammar with the production rules of the formA ... Read More
It is easy to see that for any language L the following simple properties hold −L · {∧} = {∧} · L = LL · ∅ = ∅ · L = ∅Now let’s see the commutativity and associativity of the operation of concatenation.Properties of products – commutativityThe operation of concatenation is not commutative. In other words, the order matters!Given two languages L and M, it’s usually true thatL · M ≠ M · LExampleIf L = {ab, ac} and M = {a, bc, abc}, then the productL · M is the languageL · M = {aba, abbc, ababc, aca, acbc, ... Read More
To plot arbitrary markers on a Pandas data series, we can use pyplot.plot() with markers.StepsSet the figure size and adjust the padding between and around the subplots.Make a Pandas data series with axis labels (including timeseries).Plot the series index using plot() method with linestyle="dotted".Use tick_params() method to rotate overlapping labels.To display the figure, use show() method.Exampleimport pandas as pd from matplotlib import pyplot as plt import numpy as np plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True ts = pd.Series(np.random.randn(10), index=pd.date_range('2021-04-10', periods=10)) plt.plot(ts.index, ts, '*', ls='dotted', color='red') plt.tick_params(rotation=45) plt.show()OutputRead More
There are three common ways of creating a new language from two languages −UnionIntersectionProductLanguages are sets of strings, so they can be combined by the usual set operations of union and intersection.IntersectionIf L1 and L2 are languages over ∑, then L1 ∩ L2 is the language of strings in both L1 and L2 .For example, If L = {aa, bb, ab} and M = {ab, aabb} then, The intersection is as follows −L ∩ M = {ab}AndUnionIf L1 and L2 are languages over the alphabet ∑, then the language L1 ∪ L2 is the language of all strings in at ... Read More
Basically a push down automata (PDA) is as follows −“Finite state machine+ a stack”PDA has three components, which are as follows −An Input tape.A control unit.A Stack with infinite size.A 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 a non-deterministic PDA (NPDA) for accepting the languageL = {a^m b^{2m} | m>=1}.SolutionThe strings which ... Read More
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(ΣU{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 anbmc(n+m) n, m≥1SolutionSo, the strings which are generated by the given language are as follows−L={abcc, aabccc, aaabbccccc, ….}That is to add the number of a's and b's, and that will equal the number of c's.So for every a's and ... Read More
L = {ww’ | wcw’, w={0, 1}*} where w’ is the reverse of w.This is the language of all palindromes, both odd and even over the alphabet {0, 1}.For the construction of all length palindromes, let us use the Non-deterministic push down automata (NPDA).To construct the wcw’ we need to check if the string is of odd length and if reaches the middle element ‘c’ then process it and move to the next state without making any change in stack.ExampleGiven string is 1 1 0 0 1 1 1 1 0 0 1 1Result − ACCEPTEDGiven string is: 1 0 ... Read More
DPDA is the short form for the deterministic push down automata (DPDA).ProblemConstruct DPDA for anbncm where m, n>=1SolutionSo, the strings which are generated by the given language are −L={abc, aabbc, aaabbbcc, ….}That is we have to count equal number of a’s, b’s and different number of c’sLet’s count the number of a's which is equal to the number of b's.This can be achieved by pushing a's in STACK and then we will pop a's whenever "b" comes.Then for c nothing will happen.Finally, at the end of the strings if nothing is left in the STACK then we can say that ... Read More
ProblemConstruct deterministic push down automata (DPDA) for anbn where n>=1.SolutionSo, the strings which are generated by the given language are as follows −L={ab, aabb, aaabbb, ….}That is we have to count equal number of a’s and b’sThis can be achieved by pushing a's in STACK and then we will pop a's whenever "b" comes.Finally at the end of the strings if nothing is left in the STACK then we can declare that language is accepted in the PDA.The transition diagram is as follows −Transition FunctionsThe transition functions are as follows −δ(q0, a, Z) = (q0, aZ)δ(q0, a, a) = (q0, ... Read More
Let us understand the push down automata (PDA) and the linear bounded automata (LBA) in the theory of computation (TOC).Push-Down AutomataA PDA can be formally described as seven tuples (Q, Σ, S, δ, q0, I, F)Where, Q is finite no of statesΣ is input alphabetS is stack symbolΔ is the transition function: QX(ΣU{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)A Push-Down Automaton is a finite-state machine that is equipped with a memory device that functions as a push-down store.Push-down automata are equivalent to ... Read More
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP