Worst Case Number of States in DFA and NFA for a Language

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

584 Views

A Deterministic Finite automata (DFA) is a five tuplesM=(Q, ∑, δ, q0, F)Where, Q − Finite set called states.∑ − Finite set called alphabets.δ − Q × ∑ → Q is the transition function.q0 ∈ Q is the start or initial state.F − Final or accept state.Let’s see the worst case number of states in DFA for the language A∩B and A*Let A and B be the two states, |A| = number of states = nA|B| = number of states = nBDFA = |A∩B|   =nA.nB|A ∪ B| =nA.nB|A*|=3/4 2nA|AB| = nA (2nB-2nB-1)NFAThe non-deterministic finite automata (NFA) also have five states ... Read More

Design an Unambiguous CFG in CNF that Generates e

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

306 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

CFG Recognition by Non-Deterministic Push Down Automata

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

626 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

Instantaneous Description and Turnstile Notation

Bhanu Priya
Updated on 16-Jun-2021 12:42:06

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

Elimination of Epsilon Productions in CFG

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

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

Change Default Font Color for All Text in Matplotlib

Rishikesh Kumar Rishi
Updated on 16-Jun-2021 12:23:21

4K+ Views

To change the default font color for all text in Matplotlib, we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Using rcParams['text.color'], we can get the default text color.We can update the text color and label color after updating the rcParams dictSet the title and label of the plot.To display the figure, use show() method.Exampleimport matplotlib.pyplot as plt plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True print("Default text color is: ", plt.rcParams['text.color']) plt.rcParams.update({'text.color': "red",                      'axes.labelcolor': "green"}) plt.title("Title") plt.xlabel("X-axis") plt.show()OutputRead More

Add Legend to a Matplotlib Pie Chart

Rishikesh Kumar Rishi
Updated on 16-Jun-2021 12:22:53

8K+ Views

To add a legend to a Matplotlib pie chart, we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Make a list of labels, colors, and sizes.Use pie() method to get patches and texts with colors and sizes.Place a legend on the plot with patches and labels.Set equal scaling (i.e., make circles circular) by changing the axis limits.To display the figure, use show() method.Exampleimport matplotlib.pyplot as plt plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True labels = ['Walk', 'Talk', 'Sleep', 'Work'] sizes = [23, 45, 12, 20] colors = ['red', 'blue', ... Read More

Make More Than 10 Subplots in a Figure Using Matplotlib

Rishikesh Kumar Rishi
Updated on 16-Jun-2021 12:21:16

1K+ Views

To make more than 10 subplots in a figure, we can use subplots() method with some rows and columns.StepsSet the figure size and adjust the padding between and around the subplots.Initialize rows count and columns count.Create a figure and a set of subplots with rows☓cols subplots.To display the figure, use show() method.Examplefrom matplotlib import pyplot as plt plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True rows = 4 cols = 3 fig, axes = plt.subplots(nrows=rows, ncols=cols) plt.show()Output

Plot Jointplot with Hue Parameter in Seaborn

Rishikesh Kumar Rishi
Updated on 16-Jun-2021 12:20:58

397 Views

To plot a jointplot with hue parameter in Seaborn, we can take the following steps −StepsSet the figure size and adjust the padding between and around the subplots.Create x data points using numpy.Make a dictionary with some curve data.Make a dataframe for tabular data.Make a jointplot using jointplot() method.To display the figure, use show() method.Examplefrom matplotlib import pyplot as plt import pandas as pd import seaborn as sns import numpy as np plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True x = np.linspace(0, 1, 5) d = {       'y=sin(x)': np.sin(x),       'y=cos(x)': np.cos(x), ... Read More

Annotate the End of Lines Using Python and Matplotlib

Rishikesh Kumar Rishi
Updated on 16-Jun-2021 12:20:16

1K+ Views

To annotate the end of lines using Python and Matplotlib, we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Initalize a variable, rows, to get the number of rows data.Get a Pandas dataframe in a rectangular tabular data.Calculate the cumsum (cumulative sum) of the dataframe.Plot the dataframe using plot() method.Iterate line and name to annotate the end of lines.Use annotate() method with column's name, xy co-ordinates, color of the lines, sizes, etc.Place a legend on the figure.To display the figure, use show() method.Exampleimport pandas as pd import numpy as np import ... Read More

Advertisements